#memory-mapped #queue #big #persistent #file

bigqueue

A big, fast and persistent queue based on memory mapped file

1 unstable release

0.0.2 Jun 18, 2019

#39 in #big

MIT/Apache

26KB
632 lines

A big, fast and persistent queue based on memory mapped file.


let mut q = BigQueue::new(&"/tmp/bigqueue", true).unwrap();

let total = 10000;
let data = b"1234567890abcdefghij";

for _a in 0..total {
q.push(data).unwrap();
}

let mut count = 0;
loop {
let pop_data = q.pop();
if  pop_data.is_ok() && pop_data.unwrap().len() == data.len() {
count = count + 1;
} else {
println!("count {}", count);
break;
}
}

fs::create_dir_all(PathBuf::from("/tmp/spsc")).expect("create dir error");
if let Ok((mut tx, mut rx)) = bigqueue::channel("/tmp/spsc", true){
let v = b"1234567890abcdefghij";
let total = 100000000;
let t = thread::spawn(move|| {
for _i in 0..total {
tx.enqueue(v).unwrap();
}
});

let two_sec = Duration::from_secs(2);
thread::sleep(two_sec);

let start = PreciseTime::now();
let mut count = 0;
loop{
if rx.dequeue().is_ok() {
count = count + 1;

}
if count == total {
println!("count {}", count);
break;
}

}
let end = PreciseTime::now();
println!("{} seconds for enqueue and dequeue. {} ps", start.to(end), total*1000000/start.to(end).num_microseconds().unwrap());
t.join().unwrap();
}

Dependencies

~3MB
~52K SLoC