diff --git a/internal/protocol/http/fetcher.go b/internal/protocol/http/fetcher.go index a2b850c0..0e5836ad 100644 --- a/internal/protocol/http/fetcher.go +++ b/internal/protocol/http/fetcher.go @@ -39,6 +39,11 @@ const ( stealMinChunkSize = 512 * 1024 // Min steal size: 512KB (avoid tiny chunks) ) +// connReadBufferSize is the read buffer each connection allocates once and +// reuses for its lifetime. 64 KiB keeps per-read overhead low on fast links; +// at 256 connections it is 16 MiB per task. +const connReadBufferSize = 64 * 1024 + var ( errRangeRequestIgnored = errors.New("server ignored HTTP range request") errInvalidRangeResponse = errors.New("invalid HTTP range response") @@ -1136,7 +1141,7 @@ func (f *Fetcher) runConnection(conn *connection) { // Use fast-fail client for quick retry during download phase client := f.buildFastFailClient() - buf := make([]byte, 8192) + buf := make([]byte, connReadBufferSize) retries := 0 f.connMu.Lock() @@ -1798,7 +1803,7 @@ func (f *Fetcher) runConnectionWithResolveResp(conn *connection) { conn.State = connConnecting f.connMu.Unlock() - buf := make([]byte, 8192) + buf := make([]byte, connReadBufferSize) // Get the resolve response f.resolveRespLock.Lock() @@ -1892,7 +1897,7 @@ func (f *Fetcher) runConnectionWithResolveResp(conn *connection) { func (f *Fetcher) runConnectionFallback(conn *connection) { // Use fast-fail client for quick retry during download phase client := f.buildFastFailClient() - buf := make([]byte, 8192) + buf := make([]byte, connReadBufferSize) retries := 0 countedRetries := 0