Clockworker
Clockworker, loosely inspired by Seastar, is a single-threaded async executor with fair scheduling across multiple queues. Clockworker is agnostic to the underlying async runtime and can sit on top of any runtime like Tokio, Monoio, or Smol.
⚠️ Early/Alpha Release: This project is in early development. APIs may change in breaking ways between versions. Use at your own risk.
What is Clockworker for?
There is a class of settings where single-threaded async runtimes are a great fit. Several such runtimes exist in the Rust ecosystem—Tokio, Monoio, Glommio, etc. But almost none of these (with the exception of Glommio) provide the ability to run multiple configurable work queues with different priorities. This becomes important for many real-world single-threaded systems, at minimum to separate foreground and background work. Clockworker aims to solve this problem.
It does so via work queues with configurable time-shares onto which tasks can be spawned. Clockworker uses an EEVDF-inspired scheduler: it chooses the queue to poll based on its fair time share (inspired by Linux CFS/EEVDF), and then executes tasks from that queue in FIFO order.
Note that Clockworker itself is just an executor loop, not a full async runtime, and is designed to sit on top of any other runtime.
Features
- EEVDF-based queue scheduling: Fair CPU time distribution between queues using virtual runtime (inspired by Linux CFS/EEVDF)
- FIFO task ordering: Tasks within each queue execute in FIFO order
- Task cancellation: Abort running tasks via
JoinHandle::abort() - Panic handling: Configurable panic behavior (propagate or catch as
JoinError::Panic) - Statistics: Built-in metrics for monitoring executor and queue performance
Quick Start
Add to your Cargo.toml:
[]
= "0.1.0"
Examples
Basic Usage
The simplest example - spawn a task and wait for it:
use ExecutorBuilder;
use LocalSet;
async
Multiple Queues with Different Weights
Allocate CPU time proportionally between queues:
use ;
use LocalSet;
use Arc;
use ;
async
Task Cancellation
Cancel tasks using JoinHandle::abort():
use ExecutorBuilder;
use LocalSet;
use ;
async
Panic Handling
By default, the executor also panics when any of the tasks panic (same behavior as Tokio's single-threaded runtime). However, this can be configured:
use ;
use LocalSet;
async
Architecture
Clockworker uses a single-level scheduling approach based on EEVDF:
- Queue-level scheduling (EEVDF): Fairly distributes CPU time between queues based on their weights using virtual runtime
- Task-level scheduling (FIFO): Within each queue, tasks execute in FIFO order
This design allows you to:
- Allocate CPU resources between different workload classes (via queue weights)
- Ensure predictable task ordering within each queue
Benchmarks
Clockworker includes several benchmarks to evaluate performance:
- overhead: Measures executor overhead
- tail_latency: Measures tail latency under various loads
- poll_profile: Profiles polling behavior
- priority: Tests priority queue behavior (Linux-specific)
Running Benchmarks on Linux (via Docker)
Some benchmarks use Linux-specific features (e.g., libc::setpriority, io_uring). To run these on macOS or any platform, use Docker:
# Build the Docker image
# Run the priority benchmark
# Run all benchmarks
# Or use docker directly
See README_DOCKER.md for detailed Docker usage instructions.
Requirements
- Rust 1.70+
- Works with any async runtime (tokio, smol, monoio, etc.) via
LocalSetor similar
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.