Principles for Fast Tokio Applications(dial9-rs.github.io)
241 points by carllerche 1 day ago | 62 comments
tl;dr: Writing performant Tokio applications requires balancing fairness (yielding frequently for latency) against batching (amortizing overhead for throughput), while avoiding pitfalls like contended mutexes that can stall all workers, global resource bottlenecks (blocking pool, global queue), and OS scheduling delays from noisy neighbor threads. The author recommends starting from real metrics rather than chasing red flags, constraining parallelism with semaphores, and isolating latency-sensitive work on separate runtimes pinned to dedicated cores. Advanced tactics like blocking the executor or spinning can be appropriate in specific controlled scenarios but shouldn't be defaults.
HN Discussion:
  • ~Article should have mentioned Tokio channels as alternatives to mutexes
  • Appreciates the framing of scheduler fairness as a resource to spend
  • For true high performance, skip Tokio and use lower-level tools like DPDK or busy-spinning
  • Async servers waste most CPU on meta-work; article's principles are valid but often violated
  • Agentic coding tools help add tracing for this kind of optimization work