Crates.io | disk-ringbuffer |
lib.rs | disk-ringbuffer |
version | 0.7.4 |
source | src |
created_at | 2024-06-25 17:14:14.889801 |
updated_at | 2024-09-26 15:56:52.005563 |
description | lock free on disk ringbuffer to be used in the implementation of Franz |
homepage | https://github.com/MostlyMaxi/disk-ringbuffer |
repository | https://github.com/MostlyMaxi/disk-ringbuffer |
max_upload_size | |
id | 1283519 |
size | 21,875 |
This is an extremely simple implementation of an on-disk broadcast channel that sort of pretends to be a ringbuffer! It uses memory-mapped pages to have interprocess, lock-free, reads and writes. It's blazingly fast, but tends to hog disk-space for better efficiency (fewer but bigger memory-mapped pages).
Example
use disk_ringbuffer::ringbuf;
fn example() {
// takes directory to use as ringbuf storage and the total number of pages to store as input.
// note that each page takes 80Mb and setting the max_pages to zero implies an unbounded queue
let (mut tx, mut rx) = ringbuf::new("test-example", 2).unwrap();
// you can clone readers and writers to use in other threads!
let tx2 = tx.clone();
for i in 0..500_000 {
tx.push(i.to_string());
}
for i in 0..500_000 {
let m = rx.pop().unwrap().unwrap();
assert_eq!(m, i.to_string());
}
}