What Tokio Does
- Multi-threaded scheduler — work-stealing for parallel async tasks
- Async I/O — TCP, UDP, Unix sockets, named pipes
- Timers — sleep, interval, timeout
- Channels — mpsc, oneshot, broadcast, watch
- Sync primitives — Mutex, RwLock, Semaphore, Notify (async-aware)
- Task spawning — lightweight green threads
- Runtime — configurable (multi-thread or current-thread)
- Tracing — integrated with tokio-console for debugging
Architecture
Work-stealing scheduler: multiple OS threads each maintain a local task queue. When idle, a thread steals tasks from others. Each task is a Future that the runtime polls. I/O is backed by epoll (Linux), kqueue (macOS), or IOCP (Windows) via the mio crate.
Comparison
| Runtime | Multi-thread | I/O |
|---|---|---|
| Tokio | Work-stealing | mio |
| async-std | Work-stealing | async-io |
| smol | Work-stealing | async-io |
| monoio | Thread-per-core | io_uring |
常见问题 FAQ
Q: 什么时候用 Tokio? A: 任何需要异步 I/O 的 Rust 项目——web server、gRPC、数据库客户端、CLI 工具的并发请求。
Q: 和 async-std 比? A: Tokio 生态最大、维护最活跃、性能最佳。async-std 更接近 std API 但社区较小。
来源与致谢 Sources
- Docs: https://tokio.rs
- GitHub: https://github.com/tokio-rs/tokio
- License: MIT