acoustic-carpenter-78188
06/10/2026, 7:42 AMflytestdlib/storage) relies on http.DefaultTransport, which keeps only 2 idle connections per host (MaxIdleConnsPerHost default). All S3 traffic targets a single host (the bucket endpoint) over HTTP/1.1 — no multiplexing — so connection count equals request concurrency.
Under high-concurrency blob-store access (hundreds of concurrent S3 operations from one process), nearly every request dials a fresh connection, uses it once, fails to park it in the full idle pool, and the connection is closed — so the next request pays a full TLS handshake. CPU profiling under such load showed ~22% of total CPU in net/http.(persistConn).addTLS / crypto/tls.HandshakeContext, TLS handshake allocators (ML-KEM/x25519 key exchange, HKDF, new-connection bufio buffers) dominating the allocation delta at ~150 MB/s, and multi-second latency outliers on requests that landed on a cold connection.
This change:
• Clones http.DefaultTransport in createHTTPClient (preserving proxy, TLS, and HTTP/2 wiring) so the storage client gets its own tunable connection pool.
• Exposes maxIdleConns, maxIdleConnsPerHost, maxConnsPerHost, and idleConnTimeout via HTTPClientConfig (Storage.defaultHttpClient.*), regenerating the pflags.
• Defaults the idle pool to 1024 / 1024 idle connections, 90s idle timeout so connections are reused instead of re-dialed at high concurrency. Idle connections are cheap (parked goroutines + FDs); 1024 covers peak concurrency with headroom.
• Leaves maxConnsPerHost unset (0 = unlimited) by default: a per-host connection cap blocks requests once reached (indefinitely, given the client Timeout defaults to 0), which is a worse failure mode than a transient dial burst. It is available as a config-tunable safety valve.
• Each knob is applied only when > 0, since zero values are meaningful to net/http (MaxIdleConnsPerHost=0 silently means 2 again); zero-valued config falls back to the corresponding http.DefaultTransport value.
When headers are configured, the header-injecting proxyTransport now wraps the tuned transport instead of the shared http.DefaultTransport.
Test Plan
• Unit tests added/updated in `rawstores_test.go`: transport settings are applied, an empty config preserves http.DefaultTransport behavior (fresh clone, same values), and configured headers wrap the tuned transport.
• go test ./flytestdlib/storage/... and go vet pass.
• Live (2026-06-10): ran in a combined leaseworker test build (unionai/cloud test branch, flyte2 fork carrying this commit) on a dogfood dataplane through two ~10–30k-lease burst rounds (fasttask fanout + high-rate sleep fanout). No regressions: blob reads/writes healthy throughout, config knobs wired and visible, defaults applied. Caveat: that cluster is GCS-backed, so the S3/`http.DefaultTransport` path this PR patches was not meaningfully exercised — call-graph inspection shows no TLS-handshake frames at all on the GCS path (the Google SDK uses its own pooled HTTP/2 transport, structurally immune to the MaxIdleConnsPerHost=2 churn), and the bufio allocations in those profiles were later traced (on the S3 run below) to Connect RPC response decompression (compressionPool.putDecompressor → gzip.Reset), unrelated to this PR's transport.
• VALIDATED on an S3-backed dataplane (2026-06-10, dogfood, fasttask tree fanout, ~16k queued leases, 512 concurrent evaluations):
• TLS-handshake CPU: gone. Mid-burst 30s profile has zero `addTLS`/`HandshakeContext`/ML-KEM/x25519 frames (same-cluster control on the previous build, same morning: 9.2% + dialConn ~5%). The only TLS frames remaining are `Conn.Write`/`Conn.Read` record crypto on established connections (~4.5%) — i.e., connections are being reused.
• Handshake allocators: gone from the burst allocation delta (no `mlkem`/`x25519`/`hkdf` entries; control had them dominating at ~150 MB/s). Remaining bufio allocations traced via peek to Connect RPC response decompression (compressionPool.putDecompressor → gzip.Reset) and aws-sdk XML decoding — unrelated to this transport.
• Whole-process CPU at higher lease pressure dropped vs the same-cluster control (~3.2 vs ~4.75 cores), with the top profile frames now allocation/GC machinery from unrelated known work (fasttask status decode).
Rollout Plan
• Merges to `main`; consuming services pick the change up on their next dependency bump/build. No config change is required — the new defaults take effect automatically.
• The pool can be tuned per deployment via Storage.defaultHttpClient.{maxIdleConns,maxIdleConnsPerHost,maxConnsPerHost,idleConnTimeout}.
Rollback Plan
• Config-level rollback without a code change: set maxIdleConns, maxIdleConnsPerHost, and idleConnTimeout to 0 to restore the previous http.DefaultTransport pool behavior.
• Full rollback: revert this commit; the change is self-contained to flytestdlib/storage.
🤖 Generated with Claude Code
flyteorg/flyteacoustic-carpenter-78188
06/11/2026, 12:09 AM