Skip to content

Rust async — Tokio en 2026 #273

Description

@khalilbenaz

lede: Tokio reste runtime async dominant Rust. Async/await stable, structured concurrency, performance. State of art 2026.
lede_en: Tokio remains dominant Rust async runtime. Stable async/await, structured concurrency, performance. 2026 state of art.
title_en: Rust async — Tokio in 2026

Tokio en 2026

Tokio (créé 2016) est le runtime async dominant Rust :

  • Async/await : syntaxe standard depuis Rust 2018 edition.
  • Performance : top tier (proche C).
  • Écosystème : axum, sqlx, tonic, tracing tous Tokio-native.

Quasi-monopole : 95 % des projets async Rust utilisent Tokio.

Patterns standards

Spawn task :

tokio::spawn(async {
    println!("Hello from task");
});

Async I/O :

use tokio::fs::File;
use tokio::io::AsyncReadExt;

let mut file = File::open("data.txt").await?;
let mut contents = String::new();
file.read_to_string(&mut contents).await?;

Concurrent operations :

let (a, b, c) = tokio::join!(
    fetch_user(1),
    fetch_user(2),
    fetch_user(3)
);

Structured concurrency

Tokio 1.40+ pousse vers structured concurrency :

use tokio::task::JoinSet;

let mut set = JoinSet::new();
for id in 1..=10 {
    set.spawn(async move { fetch_user(id).await });
}

while let Some(result) = set.join_next().await {
    let user = result?;
    println!("{:?}", user);
}

JoinSet garantit que toutes les tasks sont awaited. Pas de tasks orphelines.

Frameworks Tokio-native

  • Axum (Tokio team) : web framework moderne.
  • SQLx : SQL async type-safe.
  • Tonic : gRPC.
  • Reqwest : HTTP client.
  • Tracing : observability.

Tous interopèrent naturellement.

Vs alternatives async

  • async-std : alternative, en déclin. Beaucoup ont migré vers Tokio.
  • smol : minimaliste, sweet spot embedded.
  • glommio : thread-per-core, niche high-perf.

Tokio est défaut. Pas de raison de chercher ailleurs pour 95 % des cas.

Performance tuning

// Multi-thread (défaut, scaling)
#[tokio::main]
async fn main() { ... }

// Current-thread (single-threaded, sweet spot embedded)
#[tokio::main(flavor = "current_thread")]
async fn main() { ... }

// Custom : N worker threads
#[tokio::main(worker_threads = 4)]
async fn main() { ... }

Anti-patterns

  • Blocking dans async : std::thread::sleep dans async task = freeze runtime. Use tokio::time::sleep.
  • Sync I/O dans async : same. Use Tokio async equivalents.
  • Spawn sans bound : runaway tasks. Always bound concurrency.

Verdict

Pour Rust async en 2026 : Tokio sans hésitation. Mature, performant, écosystème massif.

Alternatives existent pour niches mais Tokio reste le défaut sûr.

Tokio in 2026

Tokio (created 2016) is the dominant Rust async runtime:

  • Async/await: standard syntax since Rust 2018 edition.
  • Performance: top tier (close to C).
  • Ecosystem: axum, sqlx, tonic, tracing all Tokio-native.

Near-monopoly: 95% of async Rust projects use Tokio.

Standard patterns

Spawn task:

tokio::spawn(async {
    println!("Hello from task");
});

Async I/O:

use tokio::fs::File;
use tokio::io::AsyncReadExt;

let mut file = File::open("data.txt").await?;
let mut contents = String::new();
file.read_to_string(&mut contents).await?;

Concurrent operations:

let (a, b, c) = tokio::join!(
    fetch_user(1),
    fetch_user(2),
    fetch_user(3)
);

Structured concurrency

Tokio 1.40+ pushes toward structured concurrency:

use tokio::task::JoinSet;

let mut set = JoinSet::new();
for id in 1..=10 {
    set.spawn(async move { fetch_user(id).await });
}

while let Some(result) = set.join_next().await {
    let user = result?;
    println!("{:?}", user);
}

JoinSet guarantees all tasks are awaited. No orphan tasks.

Tokio-native frameworks

  • Axum (Tokio team): modern web framework.
  • SQLx: type-safe async SQL.
  • Tonic: gRPC.
  • Reqwest: HTTP client.
  • Tracing: observability.

All interoperate naturally.

vs async alternatives

  • async-std: alternative, declining. Many migrated to Tokio.
  • smol: minimalist, embedded sweet spot.
  • glommio: thread-per-core, high-perf niche.

Tokio is default. No reason to look elsewhere for 95% of cases.

Performance tuning

// Multi-thread (default, scaling)
#[tokio::main]
async fn main() { ... }

// Current-thread (single-threaded, embedded sweet spot)
#[tokio::main(flavor = "current_thread")]
async fn main() { ... }

// Custom: N worker threads
#[tokio::main(worker_threads = 4)]
async fn main() { ... }

Anti-patterns

  • Blocking in async: std::thread::sleep in async task = freeze runtime. Use tokio::time::sleep.
  • Sync I/O in async: same. Use Tokio async equivalents.
  • Spawn without bound: runaway tasks. Always bound concurrency.

Verdict

For Rust async in 2026: Tokio without hesitation. Mature, performant, massive ecosystem.

Alternatives exist for niches but Tokio remains safe default.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blogArticle publié sur le blogrust

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions