parallel

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2025 License: Apache-2.0, Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package parallel provides an http.RoundTripper that transparently parallelizes GET requests using concurrent byte-range requests for better throughput.

───────────────────────────── How it works ─────────────────────────────

  • For non-GET requests, the transport passes them through unmodified to the underlying transport.
  • For GET requests, it first performs a HEAD request to check if the server supports byte ranges and to determine the total response size.
  • If the HEAD request indicates range support and known size, the transport generates multiple concurrent GET requests with specific byte-range headers.
  • Subranges are written to temporary files and stitched together in a custom Response.Body that's transparent to the caller.
  • Per-host and per-request concurrency limits are enforced using semaphores.

───────────────────────────── Notes & caveats ───────────────────────────

  • Only works with servers that support "Accept-Ranges: bytes" and provide Content-Length or Content-Range headers with total size information.
  • Content-Encoding (compression) is not compatible with byte ranges, so compressed responses fall back to single-threaded behavior.
  • Temporary files are created for each subrange and cleaned up automatically.
  • The transport respects per-host concurrency limits to avoid overwhelming servers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*ParallelTransport)

Option configures a ParallelTransport.

func WithMaxConcurrentPerHost

func WithMaxConcurrentPerHost(limits map[string]uint) Option

WithMaxConcurrentPerHost sets the maximum concurrent requests per hostname. Default concurrency limits are applied if not specified.

func WithMaxConcurrentPerRequest

func WithMaxConcurrentPerRequest(n uint) Option

WithMaxConcurrentPerRequest sets the maximum concurrent subrange requests for a single request. Default: 4.

func WithMinChunkSize

func WithMinChunkSize(size int64) Option

WithMinChunkSize sets the minimum size in bytes for each subrange chunk. Requests smaller than this will not be parallelized. Default: 1MB.

func WithTempDir

func WithTempDir(dir string) Option

WithTempDir sets the directory for temporary files. If empty, os.TempDir() is used.

type ParallelTransport

type ParallelTransport struct {
	// contains filtered or unexported fields
}

ParallelTransport wraps another http.RoundTripper and parallelizes GET requests using concurrent byte-range requests when possible.

func New

func New(base http.RoundTripper, opts ...Option) *ParallelTransport

New returns a ParallelTransport wrapping base. If base is nil, http.DefaultTransport is used. Options configure parallelization behavior.

func (*ParallelTransport) RoundTrip

func (pt *ParallelTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper. It parallelizes GET requests when possible, otherwise passes requests through to the underlying transport.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL