Expand description
Per-core runtimes (RWS_CONFIG_RUNTIME=per-core, Unix only): one
single-threaded tokio runtime per core, each accepting on its own
SO_REUSEPORT socket, the way nginx runs one worker per core. A
connection stays on the thread the kernel gave it to, so there’s no work
stealing, no cross-thread wake-ups and no idle workers searching for work.
The rws binary runs per-core unless configured otherwise (since 18.0.0,
default_to_per_core); for an application built on the library the
default stays shared, tokio’s multi-threaded runtime. run_tls and
run_plain start the per-core accept loops ([spawn]) and keep the
signals: SIGINT/SIGTERM stop every loop, SIGHUP reloads the config and
hands the rebuilt TLS acceptor to every loop. HTTP/3, the redirect
listener and ACME stay on the main runtime.
Tokio I/O belongs to the runtime that created it, so pooled upstream
connections are kept per thread ([pool_key]).
Constants§
- RWS_
CONFIG_ RUNTIME RWS_CONFIG_RUNTIME:sharedorper-core(therwsbinary’s default).
Functions§
- default_
to_ per_ core - Make
per-corethe runtime unlessRWS_CONFIG_RUNTIMEis already set — what therwsbinary does before reading its config file and flags, soruntime = "shared"there (or in the environment) still wins. Library applications don’t call it: their handlers may keep tokio I/O in process-wide structures, which per-core runtimes don’t share. - enabled
- Whether
RWS_CONFIG_RUNTIMEasks for per-core runtimes (alwaysfalseoff Unix, where there is noSO_REUSEPORT). - runtime_
count - How many per-core runtimes to start:
TOKIO_WORKER_THREADSwhen set (the same knob as the shared runtime), otherwise one per available CPU.