AptLarder::ConnectionPool
Per-host pool of idle HTTP::Client connections.
Reusing connections avoids the TCP and TLS handshake overhead on every
upstream request. The pool is keyed by scheme://host:port so that
connections to different ports on the same host are kept separate.
At most IDLE_PER_HOST connections are retained per host. Connections
returned when the pool is full are closed immediately.
All methods are safe to call from concurrent fibers.
Constants
Maximum number of idle connections kept per upstream host. 4 covers the typical APT concurrency (a handful of parallel downloads) without risking file-descriptor exhaustion.
Pooled connections idle longer than this are assumed dead — the upstream may have closed its keep-alive — and are discarded on checkout instead of risking a wasted round-trip on a stale socket. Kept below the typical server keep-alive timeout (60s).
Constructors
Instance methods
Returns client to the pool for uri so it can be reused.
If the pool for this host already holds IDLE_PER_HOST connections,
client is closed immediately rather than queued. now is injectable
for tests; production callers use the default monotonic clock.
Returns a pooled connection for uri, or creates a new one if none is
available. Connections idle beyond IDLE_TTL are closed and skipped.
The host bucket is dropped once empty so the table cannot grow unbounded.
Closes client and discards it. Silently ignores errors (e.g. already closed). Use this when the connection is known to be dirty or broken.