Expand description
Thread-per-core HTTP server bootstrap for the Tako framework.
Spawns N OS threads (one per CPU by default), each running its own
tokio current_thread runtime + tokio::task::LocalSet. Connections
are distributed across workers at the kernel level via SO_REUSEPORT.
Tasks never migrate between threads, eliminating tokio’s work-stealing
coordination on the hot path and improving cache locality (especially with
the affinity feature which pins each worker to a specific core).
Two entry points:
serve_per_thread— uses the existing thread-safetako_rs_core::router::Routerfromtako-core. Drop-in alternative totako::serve; no API changes.serve_per_thread_compio(under thecompiofeature) — sameSO_REUSEPORTbootstrap but each worker runs acompioruntime (io_uringon Linux, IOCP on Windows, kqueue on macOS).
Structs§
- PerThread
Config - Configuration for
serve_per_thread(and thecompiovariant when enabled). - PerThread
Shutdown - Shutdown coordinator shared by every worker spawned via
spawn_per_thread(and friends). Workersselect!againstSelf::notifiedin their accept loop, so triggeringPerThreadShutdown::triggercleanly exits each worker’sloop { accept }instead of leaking the OS thread on shutdown.
Functions§
- serve_
per_ thread - Starts a thread-per-core HTTP server with the given router.
- serve_
per_ thread_ compio compio - Starts a thread-per-core HTTP server with the compio runtime.
- spawn_
per_ thread - Spawn the worker threads and return both the join handles and a
PerThreadShutdownthat the caller can use to signal a clean stop.