class

AptLarder::ConnectionPool

Inherits Reference / Object

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

IDLE_PER_HOST = 4

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.

IDLE_TTL = 50.seconds

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

checkin(uri : URI, client : HTTP::Client, now : Time::Instant = Time.instant) : Nil

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.

Source
checkout(uri : URI, now : Time::Instant = Time.instant) : HTTP::Client

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.

Source
discard(client : HTTP::Client) : Nil

Closes client and discards it. Silently ignores errors (e.g. already closed). Use this when the connection is known to be dirty or broken.

Source