| Crates.io | turbo-mpmc |
| lib.rs | turbo-mpmc |
| version | 0.1.0 |
| created_at | 2025-11-24 16:47:15.157254+00 |
| updated_at | 2025-11-24 16:47:15.157254+00 |
| description | A blazingly fast lock-free MPMC queue that beats crossbeam-channel on SPSC workloads. |
| homepage | |
| repository | https://github.com/Sumit99589/turbo_mpmc |
| max_upload_size | |
| id | 1948133 |
| size | 115,226 |
A blazingly fast lock-free Multi-Producer Multi-Consumer (MPMC) queue implementation in Rust that outperforms crossbeam-channel. Built using a ticket-based Vyukov-style bounded queue design with cache-line optimization.
Add this to your Cargo.toml:
[dependencies]
turbo-mpmc = "0.1.0"
use turbo_mpmc::Queue;
use std::sync::Arc;
use std::thread;
fn main() {
// Create a queue with 16 slots (must be power of 2)
let queue = Arc::new(Queue::<String, 16>::new());
let producer_queue = queue.clone();
let consumer_queue = queue.clone();
// Producer thread
let producer = thread::spawn(move || {
for i in 0..10 {
let message = format!("Message {}", i);
producer_queue.send(message);
}
});
// Consumer thread
let consumer = thread::spawn(move || {
for _ in 0..10 {
if let Ok(message) = consumer_queue.recv() {
println!("Received: {}", message);
}
}
});
producer.join().unwrap();
consumer.join().unwrap();
}
send(value: T) - Blocks until the value is successfully sent (spins when queue is full)recv() -> Result<T, RecvError> - Blocks until a value is received (spins when queue is empty)try_send(value: T) -> Result<(), SendError<T>> - Returns immediately with error if queue is fulltry_recv() -> Result<T, RecvError> - Returns immediately with error if queue is empty// CAP must be > 0 and a power of 2
let queue = Queue::<MessageType, 1024>::new();
Benchmarks comparing against popular Rust MPMC implementations:
cargo bench
Benchmark results are saved to target/criterion/report/index.html
The repository includes several examples demonstrating different use cases:
cargo run --example simple
cargo run --example work_queue
cargo run --example quick_perf --release
fetch_add for lock-free ticket distributionโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CachePadded<AtomicUsize> tail โ Producer ticket counter
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ CachePadded<AtomicUsize> head โ Consumer ticket counter
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Slot<T> [0] (64-byte aligned) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Slot<T> [1] (64-byte aligned) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ... โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Slot<T> [CAP-1] (64-byte aligned) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Standard tests
cargo test
# Loom-based concurrency tests (slow but thorough)
RUSTFLAGS="--cfg loom" cargo test --test loom_tests --release
The project includes comprehensive integration tests covering:
# Debug build
cargo build
# Release build (optimized)
cargo build --release
# Linux/macOS
./verify.sh
# Windows
./verify.ps1
| Feature | turbo-mpmc | crossbeam-channel | flume | std::mpsc |
|---|---|---|---|---|
| MPMC Support | โ | โ | โ | โ (MPSC only) |
| Lock-Free | โ | โ | โ | โ |
| Bounded | โ | โ | โ | โ |
| Unbounded | โ | โ | โ | โ |
| Performance | ๐ Fastest | Fast | Fast | Moderate |
| Select Support | โ | โ | โ | โ |
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is dual-licensed under either:
at your option.
Made with โค๏ธ and Rust