Skip to content

Commit fcda74a

Browse files
committed
perf(downloader): 连接池空闲上限提升到 64 匹配多核分段数
旧值 16 按 4 核机器设定,在 16+ 逻辑核主机上下载大文件时(分段数达 64)会饿死空闲连接池,导致第 16 段之后的每个分段都要重新 TCP+TLS 握手。HLS 并发仍独立保持 16 以约束 CDN 单 IP 连接压力。
1 parent 148ea44 commit fcda74a

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

native/engine/src/downloader.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,13 +650,17 @@ pub fn build_client(
650650
.connect_timeout(Duration::from_secs(15))
651651
// No global timeout — downloads can be very long
652652
// Connection pool — keep enough idle connections to cover all
653-
// segments of a typical multi-segment download. 16 matches
654-
// MAX_SEGMENTS on a 4-core machine (cpu_cores * 4) and avoids
655-
// expensive TCP+TLS re-handshakes when workers finish one segment
656-
// and immediately start the next. 90 s idle timeout tolerates
657-
// brief pauses / UI interaction without discarding warm connections.
653+
// segments of a multi-segment download so workers reuse warm
654+
// keep-alive connections instead of paying TCP+TLS re-handshake
655+
// costs when finishing one segment and starting the next.
656+
// 64 == MAX_SEGMENTS (segment_advisor caps io_cap at cpu_cores*4,
657+
// which reaches 64 on 16+ logical-core machines downloading large
658+
// files). The previous value of 16 (sized for a 4-core machine)
659+
// starved the idle pool on many-core hosts, forcing re-handshakes
660+
// for every segment beyond the 16th. 90 s idle timeout reclaims
661+
// the extra connections shortly after the download finishes.
658662
.pool_idle_timeout(Duration::from_secs(90))
659-
.pool_max_idle_per_host(16)
663+
.pool_max_idle_per_host(64)
660664
// Cookies — needed for session-based downloads (Google Drive, etc.).
661665
// reqwest follows RFC 6265: cookies are scoped to their domain.
662666
.cookie_store(true)

native/engine/src/hls_downloader.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ const RETRY_BASE_DELAY: std::time::Duration = std::time::Duration::from_secs(2);
7171

7272
/// Upper bound on concurrent segment downloads.
7373
///
74-
/// Matches `build_client`'s `pool_max_idle_per_host(16)` in `downloader.rs`:
75-
/// going past the connection-pool size forces expensive TCP+TLS re-handshakes
76-
/// and risks tripping CDN per-IP connection limits. 16 is the same ceiling the
77-
/// multi-segment HTTP downloader uses.
74+
/// Capped at 16 to bound CDN per-IP connection pressure: HLS playlists often
75+
/// have hundreds of tiny segments, and opening dozens of parallel connections
76+
/// to a single streaming CDN risks tripping per-IP limits or throttling.
77+
/// This ceiling is intentionally independent of `build_client`'s idle-pool
78+
/// size (`pool_max_idle_per_host`, sized for the 64-segment HTTP path) —
79+
/// the pool is large enough to keep every HLS connection warm regardless.
7880
const MAX_HLS_CONCURRENCY: usize = 16;
7981

8082
/// Concurrency used when the user left the segment count on "auto"

0 commit comments

Comments
 (0)