From 45913aae5f8a0635d048cd8fa7b4fa645bff71af Mon Sep 17 00:00:00 2001 From: Rob von Behren Date: Thu, 11 Jun 2026 16:47:42 -0700 Subject: [PATCH] perf: increase undici HTTP/2 pool from 4x64 to 20x128 streams Raise the connection count from 4 to 20 and per-connection stream limit from 64 to 128 (matching typical server MAX_CONCURRENT_STREAMS). This increases max in-flight requests from 256 to 2560 before queuing. Co-Authored-By: Claude Opus 4.6 --- src/lib/undici-fetch.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib/undici-fetch.ts b/src/lib/undici-fetch.ts index 376f38b75..e010baa9f 100644 --- a/src/lib/undici-fetch.ts +++ b/src/lib/undici-fetch.ts @@ -37,10 +37,12 @@ import { MultipartBody } from '../_shims/MultipartBody'; import { type Fetch } from '../core'; const KEEP_ALIVE_TIMEOUT_MS = 10 * 60 * 1000; -// Bound the pool to a few TLS sessions per origin and multiplex many H2 streams -// over each. 4 x 64 = 256 concurrent requests in flight before undici queues the rest. -const H2_MAX_CONNECTIONS = 4; -const H2_MAX_CONCURRENT_STREAMS = 64; +// Bound the pool to several TLS sessions per origin and multiplex H2 streams over +// each. The server typically advertises MAX_CONCURRENT_STREAMS=100-128; we use 128 +// per connection to match. 20 x 128 = 2560 concurrent requests in flight before +// undici queues the rest. +const H2_MAX_CONNECTIONS = 20; +const H2_MAX_CONCURRENT_STREAMS = 128; // One module-scoped default dispatcher, reused across requests: a bounded HTTP/2 pool // with keep-alive. `allowH2` negotiates h2 over TLS via ALPN and transparently falls