Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

The Go Blog 7 min read Deep dive mediumAdept

Better HTTP/1 connection reuse

Go 1.27's net/http.Transport now asynchronously drains unread HTTP/1 response bodies, up to 50 ms or 256 KB, before closing them. Connections can then be reused instead of abandoned, which made a 100-request status-check loop about 5x faster (710 ms to 150 ms). Before this change, any unread bytes, even a trailing newline left by encoding/json.Decoder, forced a new TCP+TLS handshake costing several RTTs. The recommendation is to drop hand-rolled drain helpers, which are also unnecessary for HTTP/2, and simply close response bodies.

Assumes: HTTP/1.1 keep-aliveTCP and TLS handshakesGo net/http client

Related posts

  • Next level customer experience with HTTP/3 traffic engineering

    Zalando Engineering mediumAdept

    HTTP/3 over QUIC addresses TCP-era protocol inefficiencies: head-of-line blocking, multi-round-trip handshakes (5-6 for cold HTTP/2 vs 3 for HTTP/3), layered TLS overhead, kernel-bound congestion control and lack of connection migration. Open problems remain, including UDP datagram loss still causing blocking, higher memory and kernel-to-user copy costs, ISP and middlebox policies tuned for TCP, unsettled congestion control (NewReno, CUBIC, BBR), and the 1280-byte minimum MTU. On 5G mid-band radio networks, only BBR handles noise-, blockage- and handover-induced loss well. Zalando has adopted HTTP/3 for distributing all media content, relying on CloudFront edge locations, Apple's native iOS stack and Cronet on Android.

  • Retrospective and Technical Details on the recent Firefox Outage

    Mozilla Hacks mediumAdept

    On January 13, 2022, Firefox hung worldwide for about two hours after Google Cloud silently made HTTP/3 the default on load balancers left at "Automatic", causing Telemetry connections to switch from HTTP/2 to HTTP/3. Telemetry's Rust code sent requests through the viaduct library, which lower-cased the Content-Length header. Necko's high-level API checked headers case-insensitively, but its HTTP/3 code looked them up case-sensitively, so it treated the request as complete with the body unsent and looped forever on the single socket thread, blocking all networking. Lessons include setting load balancer options explicitly instead of relying on defaults, and running system tests across HTTP versions and intermediate networking layers in CI.

  • Learn How to Lower Heroku Dyno Latency through Persistent Connections (Keep-alive)

    Heroku Engineering mediumAdept

    HTTP keep-alive connections cut latency by reusing TCP connections, so repeat requests skip the handshake and TCP slow start and run at full bandwidth. HTTP/1.0 opened one connection per request; HTTP/1.1 decoupled requests from connections through pipelining and keep-alive. Heroku Router 2.0 now uses keep-alive to dynos by default. Ruby apps that disabled keep-alives over earlier latency spikes should upgrade to Puma 7.1.0+ and can check settings with PUMA_LOG_CONFIG and the http-disable-keepalive-to-dyno labs flag.

  • Quicker serverless Postgres connections

    Neon mediumAdept

    Neon cut the network round-trips needed to get a first query result from its WebSocket-based serverless Postgres driver from nine to four. It moved to TLS 1.3, ran Postgres unencrypted inside a secure wss: WebSocket (or pipelined SSLRequest with the TLS Client Hello), and replaced CPU-heavy SCRAM-SHA-256 with plain password auth over TLS, since Neon only issues long random passwords. It also pipelined the startup, password and query messages into a single send. Pipelining at first added up to 50ms of delay over short distances because of Nagle's algorithm, fixed by setting TCP_NODELAY in the proxy. QUIC-based WebSockets or WebTransport might cut the count further.

  • Upgrade to Puma 7 and Unlock the Power of Fair Scheduled Keep-alive

    Heroku Engineering mediumAdept

    Puma 6 and earlier let a single keep-alive connection monopolize a thread for up to 10 requests via the "fast inline" loop originally built for HTTP pipelining, so under overload about one in ten requests waited roughly 10x longer while later keep-alive requests cut the line. Puma 7 fixes this by requeuing pipelined and keep-alive requests at the back of the queue and removing the wait_until_not_full block on the accept loop. To keep load balanced across workers, it extends wait_for_less_busy_worker with a proportional sleep, so busier workers wait longer before accepting. Capacity is unchanged, but overload delay is now spread fairly; upgrading to 7.1.0+ is recommended, especially for Heroku Router 2.0 users who disabled keep-alives.

The quest for software engineering knowledge.

Look:
Layout: