Why Tokio?
Fast
Tokio’s zero-cost abstractions give you bare-metal performance
Reliable
Leverages Rust’s ownership, type system, and concurrency model to reduce bugs and ensure thread safety
Scalable
Has a minimal footprint, and handles backpressure and cancellation naturally
Core components
At a high level, Tokio provides the following major components:Task scheduler
A multithreaded, work-stealing based task scheduler for executing asynchronous tasks
Async I/O
Asynchronous TCP and UDP sockets backed by the operating system’s event queue
Timers
Utilities for tracking time, including timeouts, sleeps, and intervals
Synchronization
Channels and primitives for communicating and sharing data between tasks
Key features
Working with tasks
Asynchronous programs in Rust are based around lightweight, non-blocking units of execution called tasks. Tokio provides tools for working with tasks:- The
spawnfunction for scheduling new tasks on the runtime - Functions for running blocking operations in an asynchronous context
- Synchronization primitives like channels (
oneshot,mpsc,watch,broadcast) - Non-blocking
Mutexfor controlling access to shared data
Asynchronous I/O
Tokio provides everything you need to perform input and output asynchronously:- Networking: Non-blocking TCP, UDP, and Unix Domain Sockets
- Filesystem: Asynchronous file operations
- Process management: Spawning and managing child processes
- Signal handling: Asynchronous OS signal handling
Runtime flexibility
The Tokio runtime can be configured to match your application’s needs:- Single-threaded: Lightweight runtime for simple applications
- Multi-threaded: Work-stealing scheduler for maximum performance
- Customizable: Fine-grained control over thread pools and resource limits
The easiest way to get started is to enable the
full feature flag, which provides access to all of Tokio’s public APIs.Example: TCP echo server
Here’s a complete TCP echo server that demonstrates Tokio’s core concepts:#[tokio::main]: The macro that sets up the async runtime- Async I/O: Non-blocking TCP listener and socket operations
- Task spawning: Each connection is handled concurrently with
tokio::spawn - Error handling: Robust error propagation with
Result
Get started
Installation
Add Tokio to your Rust project
Quickstart
Build your first async application
Supported platforms
Tokio guarantees support for the following platforms:- Linux
- Windows
- Android (API level 21)
- macOS
- iOS
- FreeBSD
Related projects
The Tokio ecosystem includes several complementary libraries:- axum: Web application framework focused on ergonomics and modularity
- hyper: Fast HTTP/1.1 and HTTP/2 implementation
- tonic: gRPC over HTTP/2 implementation
- tower: Modular components for building networking clients and servers
- tracing: Application-level tracing and async-aware diagnostics