bind_reuseport
def bind_reuseport(addr: SocketAddr, backlog: Int = Int(1024)) -> TcpListener Bind a TcpListener with SO_REUSEPORT enabled.
Multiple workers can call bind_reuseport with the same
addr and the kernel load-balances accepted connections
across them by hashing the connection 4-tuple to one of the
bound listeners.
.. note::
The 4-tuple hash distribution is uneven under bursty
connection arrival: a 256-connection storm from a wrk2-style
load generator can land 80+ conns on one listener and 30 on
another. prefers the shared-listener path
(bind_shared + Reactor.register_exclusive) for
multi-worker servers because the kernel-driven exclusive
wakeup gives a fairer accept-time distribution. bind_reuseport
remains available for the multi-process load-balancing case
across separate flare processes (where shared-fd inheritance
is impossible) and for backward compatibility with benchmarks.
- Args
addr: Local address to bind.backlog: Listen backlog (default 1024 — higher than the single-worker 128 so a burst of SYNs is less likely to overflow before any worker picks them up).
Raises AddressInUse: If a previous bind did not set
SO_REUSEPORT on the same port.
NetworkError: For any other OS error.