Documentation
¶
Overview ¶
Package connlimit holds a connection to the number of calls its upstream can take at once (#2209): a connection's max_concurrent_calls, across every replica of the deployment.
Some upstreams cannot serve parallel requests. Twelve runs of one script started together against such an endpoint all failed, and nothing on the platform could say "this upstream takes one request at a time". A limited connection's every request now takes a slot first and gives it back when its response has been read, whatever sent it: an interactive tool call, an export's page walk, a script's platform.call.
A slot is a PostgreSQL session-level advisory lock, (connection, slot n), held on the process's lock session (internal/advisorylock) for the length of the call, so the limit holds across replicas: an upstream that takes one request does not take three because the deployment runs three replicas. A call over the limit waits for a slot instead of failing, and the wait counts against the call's own deadline; a call whose deadline passes while it waits fails naming the limit and how long it waited. A deployment with no database holds the limit in this process alone.
Index ¶
Constants ¶
const Ceiling = 32
Ceiling bounds a connection's max_concurrent_calls. Each call holding a slot holds a database connection for its length, so the limit is for an upstream that takes a few calls at once, not a throughput setting.
Variables ¶
This section is empty.
Functions ¶
func Install ¶
func Install(l *Limiter)
Install makes l the limiter every limited transport takes its slots from. A transport built before Install takes them from it all the same: it reads the installed limiter on every request.
func Parse ¶
Parse reads a configured max_concurrent_calls, absent or nil being unlimited. A value that is not a whole number is refused rather than read as unlimited: a limit an operator set and the platform silently ignored is an upstream flooded by the calls the limit was set to hold back.
func Transport ¶
func Transport(base http.RoundTripper, kind, connection string, limit int) http.RoundTripper
Transport is base with every request taking one of the connection's limit slots before it is sent and giving it back once its response body is read to the end or closed, which is when the upstream is done with the call. A limit of zero or less is base unchanged: an unlimited connection, the default.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter hands out a connection's slots.
func Default ¶
func Default() *Limiter
Default is the installed limiter, or one that holds limits in this process until one is installed.
type Slot ¶
type Slot struct {
// contains filtered or unexported fields
}
Slot is one held slot. Release gives it back; it is safe to call more than once.