Tokio's Scheduler Rewrite: Up to 10x Speed Boost
A significant rewrite of Tokio's scheduler, submitted in 2019, dramatically improved performance, yielding up to a 10x speedup in some benchmarks and a 20% throughput increase for Hyper-based web frameworks through optimized work-stealing queues.
The top 3
- Old Scheduler's Flaws: Why the Rewrite?: Tokio's initial 0.1 scheduler, released in March 2018, made assumptions that led to inefficiencies, particularly struggling with flexible thread shutdown and relying on a less optimal `crossbeam-deque` implementation for its work-stealing mechanism.
- Work-Stealing: The Core of Tokio's Speed: The rewritten scheduler implements a multi-producer, multi-consumer work-stealing deque model, where each worker thread has a local queue and can 'steal' tasks from other busy workers when idle, optimizing load balancing and reducing synchronization overhead.
- 10x Boost: Specific Workload Impact: The reported 10x speed boost from the scheduler rewrite was observed in benchmarks involving high numbers of short-lived tasks and heavy I/O-bound workloads, significantly improving concurrent request handling in scenarios like Hyper and Tonic.
Sources
Open the full topic