#async-io #run-time #async #io #future

actix-rt

Tokio-based single-threaded async runtime for the Actix ecosystem

30 releases (16 stable)

2.10.0 Jun 9, 2024
2.9.0 Aug 26, 2023
2.8.0 Jan 21, 2023
2.7.0 Mar 9, 2022
0.1.0 Dec 11, 2018

#508 in Asynchronous

Download history 252620/week @ 2024-06-24 231868/week @ 2024-07-01 259403/week @ 2024-07-08 258746/week @ 2024-07-15 277651/week @ 2024-07-22 266252/week @ 2024-07-29 264899/week @ 2024-08-05 304713/week @ 2024-08-12 305686/week @ 2024-08-19 305321/week @ 2024-08-26 287068/week @ 2024-09-02 345530/week @ 2024-09-09 294675/week @ 2024-09-16 356204/week @ 2024-09-23 341329/week @ 2024-09-30 350947/week @ 2024-10-07

1,355,443 downloads per month
Used in fewer than 389 crates

MIT/Apache

37KB
569 lines

actix-rt

Tokio-based single-threaded async runtime for the Actix ecosystem.

crates.io Documentation Version MIT or Apache 2.0 licensed
dependency status Download Chat on Discord

See crate documentation for more: https://docs.rs/actix-rt.


lib.rs:

Tokio-based single-threaded async runtime for the Actix ecosystem.

In most parts of the the Actix ecosystem, it has been chosen to use !Send futures. For this reason, a single-threaded runtime is appropriate since it is guaranteed that futures will not be moved between threads. This can result in small performance improvements over cases where atomics would otherwise be needed.

To achieve similar performance to multi-threaded, work-stealing runtimes, applications using actix-rt will create multiple, mostly disconnected, single-threaded runtimes. This approach has good performance characteristics for workloads where the majority of tasks have similar runtime expense.

The disadvantage is that idle threads will not steal work from very busy, stuck or otherwise backlogged threads. Tasks that are disproportionately expensive should be offloaded to the blocking task thread-pool using task::spawn_blocking.

Examples

use std::sync::mpsc;
use actix_rt::{Arbiter, System};

let _ = System::new();

let (tx, rx) = mpsc::channel::<u32>();

let arbiter = Arbiter::new();
arbiter.spawn_fn(move || tx.send(42).unwrap());

let num = rx.recv().unwrap();
assert_eq!(num, 42);

arbiter.stop();
arbiter.join().unwrap();

io-uring Support

There is experimental support for using io-uring with this crate by enabling the io-uring feature. For now, it is semver exempt.

Note that there are currently some unimplemented parts of using actix-rt with io-uring. In particular, when running a System, only System::block_on is supported. Asynchronous signal handling (Tokio re-exports). Unix specific signals (Tokio re-exports). TCP/UDP/Unix bindings (mostly Tokio re-exports). Utilities for tracking time (Tokio re-exports). Task management (Tokio re-exports).

Dependencies

~3–12MB
~109K SLoC