Skip to main content

Module per_core

Module per_core 

Source
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: shared or per-core (the rws binary’s default).

Functions§

default_to_per_core
Make per-core the runtime unless RWS_CONFIG_RUNTIME is already set — what the rws binary does before reading its config file and flags, so runtime = "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_RUNTIME asks for per-core runtimes (always false off Unix, where there is no SO_REUSEPORT).
runtime_count
How many per-core runtimes to start: TOKIO_WORKER_THREADS when set (the same knob as the shared runtime), otherwise one per available CPU.