Module listener

Module listener 

Source
Expand description

Binding of TCP listeners with an operator-controllable accept queue.

The async runtime builds listeners through mio, which hardcodes the listen(2) backlog to 128 with no way to override it. That queue has been observed to overflow under a connection burst well before CPU saturates, dropping connections the kernel could otherwise have queued. This module binds the socket directly so the backlog can be set, defaulting to the kernel’s ceiling.

Functions§

bind_with_backlog
Binds a listening TCP socket at listen, requesting an accept queue of backlog entries, or the kernel maximum when backlog is None. The returned listener is in non-blocking mode, ready to hand to an async runtime.
kernel_max_backlog
Returns the kernel’s maximum accept-queue length, which is the largest backlog listen(2) will honor. A larger request is silently clamped down to this value. On Linux this is net.core.somaxconn. Elsewhere, and when it cannot be read, returns a conservative default that the kernel will clamp down further if needed.