| Crates.io | nexus-logbuf |
| lib.rs | nexus-logbuf |
| version | 1.0.1 |
| created_at | 2026-01-25 20:46:17.476393+00 |
| updated_at | 2026-01-25 23:25:15.227701+00 |
| description | Lock-free SPSC and MPSC byte ring buffers for logging and archival |
| homepage | |
| repository | https://github.com/Abso1ut3Zer0/nexus |
| max_upload_size | |
| id | 2069501 |
| size | 147,146 |
High-performance lock-free ring buffers for variable-length messages.
A bytes-in, bytes-out ring buffer primitive for archival and logging. Producer writes raw bytes into a pre-allocated buffer; consumer reads them out on a background thread. No policy decisions—you define the framing, serialization, and I/O strategy on top.
Target use cases:
WriteClaim/ReadClaim with RAII semanticsqueue — Low-level primitivesMaximum control, no blocking, no backpressure handling.
use nexus_logbuf::queue::spsc;
let (mut producer, mut consumer) = spsc::new(4096);
// Producer (hot path)
let payload = b"hello world";
if let Ok(mut claim) = producer.try_claim(payload.len()) {
claim.copy_from_slice(payload);
claim.commit();
}
// Consumer (background thread)
if let Some(record) = consumer.try_claim() {
assert_eq!(&*record, b"hello world");
// record dropped -> zeros region, advances head
}
channel — Ergonomic blocking APIWraps queues with backoff and parking for receivers.
use nexus_logbuf::channel::spsc;
use std::thread;
let (mut tx, mut rx) = spsc::channel(4096);
thread::spawn(move || {
let payload = b"hello";
let mut claim = tx.send(payload.len()).unwrap();
claim.copy_from_slice(payload);
claim.commit();
tx.notify();
});
let record = rx.recv(None).unwrap();
assert_eq!(&*record, b"hello");
| Variant | Producer | Consumer | Use Case |
|---|---|---|---|
spsc |
Single | Single | Lowest latency, dedicated archiver thread |
mpsc |
Multiple | Single | Multiple hot threads → single archiver |
Senders are never slowed down. They use immediate try_send() or brief
backoff, never syscalls. If the buffer is full, they return an error.
Receivers can block. They use park_timeout to wait without burning CPU.
See BENCHMARKS.md for detailed numbers.
Summary (64-byte payload):
| Metric | SPSC | MPSC (1P) | MPSC (4P) |
|---|---|---|---|
| Producer p50 | 40 cycles | 42 cycles | 340 cycles |
| Consumer p50 | 26 cycles | 28 cycles | 28 cycles |
| Throughput | 20.7 GB/s | 38M msg/s | 13M msg/s |
MIT OR Apache-2.0