open-coroutine
The open-coroutine
is a simple, efficient and generic stackfull-coroutine library, you can use this as a performance
replacement for IO thread pools, see why better.
English | δΈζ
π Features
- Preemptive(
not supported in windows
): even if the coroutine enters a dead loop, it can still be seized, see example; - Hook: you are free to use most of the slow syscall in coroutine, see supported syscall on unix/windows;
- Scalable: the size of the coroutine stack supports unlimited expansion without the cost of copying stack, and immediately shrinks to the original size after use, see example;
- io_uring(
only in linux
): supports and is compatible with io_uring in terms of local file IO and network IO. If it's not supported on your system, it will fall back to non-blocking IO; - Priority: support custom task priority, note that coroutine priority is not open to users;
- Work Steal: internally using a lock free work steal queue;
- Compatibility: the implementation of open-coroutine is no async, but it is compatible with async, which means you
can use this crate in
tokio/async-std/smol/...
; - Platforms: running on Linux, macOS and Windows;
π Roadmap
- add docs;
- add performance benchmark;
- cancel coroutine/task;
- add metrics;
- add synchronization toolkit;
- support and compatibility for AF_XDP socket;
π Architecture
graph TD
subgraph ApplicationFramework
Tower
Actix-Web
Rocket
warp
axum
end
subgraph MessageQueue
RocketMQ
Pulsar
end
subgraph RemoteProcedureCall
Dubbo
Tonic
gRPC-rs
Volo
end
subgraph Database
MySQL
Oracle
end
subgraph NetworkFramework
Tokio
monoio
async-std
smol
end
subgraph open-coroutine-architecture
subgraph core
Preemptive
ScalableStack
WorkSteal
Priority
end
subgraph hook
HookSyscall
end
subgraph macros
open-coroutine::main
end
subgraph open-coroutine
end
hook -->|depends on| core
open-coroutine -->|link| hook
open-coroutine -->|depends on| macros
end
subgraph OperationSystem
Linux
macOS
Windows
end
ApplicationFramework -->|maybe depends on| RemoteProcedureCall
ApplicationFramework -->|maybe depends on| MessageQueue
ApplicationFramework -->|maybe depends on| Database
MessageQueue -->|depends on| NetworkFramework
RemoteProcedureCall -->|depends on| NetworkFramework
NetworkFramework -->|runs on| OperationSystem
NetworkFramework -->|can depends on| open-coroutine-architecture
Database -->|runs on| OperationSystem
open-coroutine-architecture -->|runs on| OperationSystem
π Quick Start
step1: add dependency to your Cargo.toml
[]
# check https://crates.io/crates/open-coroutine
= "x.y.z"
step2: add open_coroutine::main
macro
step3: create a task
πͺΆ Advanced Usage
create a task with priority
wait until the task is completed or timed out
scalable stack
β Learn More
π Credits
This crate was inspired by the following projects:
Thanks to those who have provided assistance: