compio README

The project's README from github.com/compio-rs/compio. As one markdown file: README.md.


Compio

MIT licensed crates.io docs.rs Check Test Telegram Discord

A thread-per-core Rust runtime with IOCP/io_uring/polling inspired by monoio.

Quick start

Add compio as dependency:

cargo add compio --features macros,fs

Then use the high level APIs provided to perform filesystem & network IO:

use compio::{fs::File, io::AsyncReadAtExt};

#[compio::main]
async fn main() {
    let file = File::open("Cargo.toml").await.unwrap();
    let (read, buffer) = file.read_to_end_at(Vec::with_capacity(1024), 0).await.unwrap();
    assert_eq!(read, buffer.len());
    let buffer = String::from_utf8(buffer).unwrap();
    println!("{}", buffer);
}

It's also possible to use the low-level driver (the proactor, without async executor) manually. See driver example.

Observability

The console feature makes the runtime emit the tracing spans and events that tokio-console consumes, so compio applications can be inspected with it:

cargo add compio --features console
cargo add console-subscriber
# .cargo/config.toml
#
# `console-subscriber` refuses to run unless the runtime is known to be
# instrumented; this is the escape hatch it provides for runtimes other than
# tokio.
[build]
rustflags = ["--cfg", "console_without_tokio_unstable"]
console_subscriber::init();
compio::runtime::Runtime::new().unwrap().block_on(async {
    // ...
});

Then run tokio-console to watch tasks, poll times and waker activity. The console module docs describe what is reported and what is not.

The console example runs an echo server on a dispatcher, so that the console shows the tasks of a thread-per-core application spread over its worker threads, next to tasks that are wrong in the ways it warns about. It passes the cfg on the command line instead:

RUSTFLAGS="--cfg console_without_tokio_unstable" \
    cargo run --example console --features console,time,net,dispatcher,sync

Why the name?

The name comes from "completion-based IO", and follows the non-existent convention that an async runtime should be named with a suffix "io".

Comparison with other runtimes

Tokio

Tokio is a great generic-purpose async runtime. However, it is poll-based, and even uses undocumented APIs on Windows. We would like some new high-level APIs to perform IOCP/io_uring.

compio isn't tokio-based. This is mainly because tokio doesn't expose APIs to control mio, and mio doesn't expose APIs to control IOCP.

Monoio

Monoio focuses on Linux and io-uring, and fallbacks to mio on other platforms.

Glommio

Glommio doesn't support Windows.

Others

There are also lots of other great async runtimes. But most of them are (at the moment when compio was created) either poll-based, use io-uring unsoundly, or aren't cross-platform. We hope compio can fill this gap.

Contributing

There are opportunities to contribute to Compio at any level. It doesn't matter if you are just getting started with Rust or are the most weathered expert, we can use your help. If you have any question about Compio, feel free to join our telegram group. Before contributing, please checkout our contributing guide.

compio (compio-rs/compio)

Searching Database…

1.9K ·GitHub
What is this?Compio is a thread-per-core async Rust runtime that uses completion-based IO backends (IOCP on Windows, io_uring on Linux, polling elsewhere) instead of the poll-based model most runtimes use.
Is this a library I add to my Rust project, or a standalone server?It is a Rust library (crate) you add as a dependency to get async filesystem and network IO plus a low-level driver you can use directly.
How do I get started with it?Add compio as a dependency to your Cargo.toml, then use its high-level async APIs for filesystem and network IO, or drop down to the low-level proactor driver manually if you need more control.
Do I need anything beyond Rust to use it?Just Rust and the compio crate; on Linux it relies on io_uring, on Windows on IOCP, and falls back to polling on other platforms, all handled internally.
How is it different from just using Tokio?Tokio is poll-based and on Windows relies on undocumented APIs, while compio is built around completion-based IO (IOCP/io_uring) from the ground up and is not built on top of tokio or mio.
Who is compio aimed at, and does it work cross-platform unlike some alternatives?It targets Rust developers building high-performance async network/filesystem applications who want a true cross-platform completion-based runtime; unlike Monoio (Linux/io_uring focused) or Glommio (no Windows support), compio works across Linux, Windows, and macOS.
Why is it called compio?The name comes from 'completion-based IO', following the convention that an async runtime should have an '-io' suffix.
Can I debug or inspect running compio tasks?Yes, with the console feature enabled, compio emits tracing spans and events that tokio-console can consume, letting you watch tasks, poll times, and waker activity, including in thread-per-core dispatcher setups.
Why wasn't compio built on top of tokio or mio?Tokio doesn't expose APIs to control mio, and mio doesn't expose APIs to control IOCP, so compio needed its own completion-based foundation instead of reusing those abstractions.
What are similar projects?libuv, tokio, muduo, swoole-src, hotpath-rs, conc, perry, libevent
Creator
compio-rs
Size
3.9 MB
Stars
1.9K
Age
3y
Commits · 90 Days