bench_queue/
bench_queue.rs

1//! A sample application asynchronously printing metrics to stdout.
2
3use dipstick::{AtomicBucket, Input, InputQueueScope, InputScope, Stream};
4use std::env::args;
5use std::str::FromStr;
6use std::thread;
7use std::thread::sleep;
8use std::time::Duration;
9
10fn main() {
11    let bucket = AtomicBucket::new();
12    // NOTE: Wrapping an AtomicBucket with a Queue probably useless, as it is very fast and performs no I/O.
13    let queue = InputQueueScope::wrap(bucket.clone(), 10000);
14    let event = queue.marker("a");
15    let args = &mut args();
16    args.next();
17    let tc: u8 = u8::from_str(&args.next().unwrap()).unwrap();
18    for _ in 0..tc {
19        let event = event.clone();
20        thread::spawn(move || {
21            loop {
22                // report some metric values from our "application" loop
23                event.mark();
24            }
25        });
26    }
27    sleep(Duration::from_secs(5));
28    bucket
29        .flush_to(&Stream::write_to_stdout().metrics())
30        .unwrap();
31}