Skip to content

Connection Pooling Guide ​

HTTPX includes an internal, thread-safe connection pool designed for high throughput, connection reuse, and minimal socket creation overhead.

Architecture ​

text
HTTP Request -> Pool.acquire(host, port)
                 |
                 +--> Reusable Keep-Alive socket found?
                 |       Yes: Send request on existing socket
                 |       No: Connect new TCP/TLS socket
                 |
HTTP Response -> Pool.release(socket)
                 |
                 +--> Return to idle pool for subsequent requests

Configuration ​

Connection pooling is configured on Client.init:

zig
var client = httpx.Client.init(allocator, io, .{
    .pool = .{
        .maxConnections = 64,
        .maxPerHost = 16,
        .idleTimeoutMs = 30_000,
    },
});
defer client.deinit();
OptionTypeDefaultDescription
maxConnectionsu32256Hard ceiling across all origins
maxPerHostu1616Ceiling per origin (host + port)
idleTimeoutMsi6430000Parked sockets older than this are dropped
maxParkedMsi64300000Max time a connection may stay parked (0 disables)

Pool Key Isolation ​

Connections are keyed by:

  1. Target Hostname / IP
  2. Target Port
  3. Transport Scheme (http vs https)
  4. Proxy Configuration (direct vs proxy endpoint)

A connection established for http://example.com will never be mistakenly reused for https://example.com or through a proxy.

Released under the MIT License.