class

ContributorMural::HTTPPool

Inherits Reference < Object

Keep-alive HTTP connections, pooled per origin.

Every avatar and every API page used to open a connection of its own, so a mural of a few hundred faces paid for a few hundred TCP and TLS handshakes against the same one or two hosts — most of the wall clock, and most of the CPU, of a run that moves only a couple of megabytes. Reusing connections also gives the whole program one place to set timeouts, which matters more than the speed does: an unbounded read on a stalled socket used to hang the job until the runner killed it, with no output and nothing in the log.

Constants

CONNECT_TIMEOUT = 10.seconds

Long enough for a loaded runner on a slow link, short enough that a black-holed socket lands in the caller's retry loop rather than sitting there. Read is the generous one: it covers a large avatar body, not just the wait for the first byte.

MAX_IDLE_PER_ORIGIN = 16

A run can only reuse one idle connection per worker; past that the pool would be a leak rather than a cache.

READ_TIMEOUT = 30.seconds
WRITE_TIMEOUT = 10.seconds

Constructors

new(connect_timeout : Time::Span = CONNECT_TIMEOUT, read_timeout : Time::Span = READ_TIMEOUT, write_timeout : Time::Span = WRITE_TIMEOUT)
Source

Instance methods

close
Source
get(url : String, headers : HTTP::Headers | Nil = nil) : HTTP::Client::Response
Source
get(url : String, headers : HTTP::Headers | Nil = nil, & : HTTP::Client::Response -> T) : T forall T

Hands the response over with its body still on the socket, so a caller that cannot say in advance how much it is willing to accept can decide while it reads instead of after the whole thing is in memory. The response is only valid inside the block.

The block must read the body to the end or raise. Anything left unread is still queued on the connection and would be handed to whoever picks it up next as the head of their own response — so raising is the way out, and the connection it happened on is dropped rather than pooled.

Source
post(url : String, headers : HTTP::Headers | Nil = nil, body : String | Nil = nil) : HTTP::Client::Response
Source