diff --git a/Cargo.lock b/Cargo.lock index 4908160..b33b4ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,7 @@ version = "0.1.0" dependencies = [ "bittorrent_udp", "dashmap", + "histogram", "indexmap", "mimalloc", "mio", @@ -244,6 +245,12 @@ dependencies = [ "libc", ] +[[package]] +name = "histogram" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cb882ccb290b8646e554b157ab0b71e64e8d5bef775cd66b6531e52d302669" + [[package]] name = "humansize" version = "1.1.0" diff --git a/TODO.md b/TODO.md index 1fb8907..5ec79c6 100644 --- a/TODO.md +++ b/TODO.md @@ -15,12 +15,6 @@ * Performance * cpu-target=native good? * mialloc good? - * use DashMap readable view when accessing torrent stats and possibly - also after modification of announcing peer and during collection - of response peers -* Statistics - * Print stats for number of peers per torrent (median, 95th, 99th - percentile.) Use histogram crate? * bittorrent_udp * ParseError enum maybe, with `Option` * Avoid allocating in conversion to bytes, send in a mutable buffer diff --git a/aquatic/Cargo.toml b/aquatic/Cargo.toml index 7bde6ed..4767d61 100644 --- a/aquatic/Cargo.toml +++ b/aquatic/Cargo.toml @@ -14,6 +14,7 @@ name = "aquatic" [dependencies] bittorrent_udp = { path = "../bittorrent_udp" } dashmap = "3" +histogram = "0.6" indexmap = "1" mimalloc = { version = "0.1", default-features = false } mio = { version = "0.7", features = ["udp", "os-poll", "os-util"] } diff --git a/aquatic/src/lib/lib.rs b/aquatic/src/lib/lib.rs index 1508caa..2857a7c 100644 --- a/aquatic/src/lib/lib.rs +++ b/aquatic/src/lib/lib.rs @@ -1,6 +1,8 @@ use std::sync::atomic::Ordering; use std::time::Duration; +use histogram::Histogram; + pub mod common; pub mod config; pub mod handlers; @@ -55,6 +57,34 @@ pub fn run(){ responses_per_second, requests_per_readable_event ); + + let mut peers_per_torrent = Histogram::new(); + + for torrent in state.torrents.iter(){ + let num_seeders = torrent.num_seeders.load(Ordering::SeqCst); + let num_leechers = torrent.num_leechers.load(Ordering::SeqCst); + + let num_peers = (num_seeders + num_leechers) as u64; + + if let Err(err) = peers_per_torrent.increment(num_peers){ + eprintln!("error incrementing peers_per_torrent histogram: {}", err) + } + } + + if peers_per_torrent.entries() != 0 { + println!( + "peers per torrent: min: {}, p50: {}, p75: {}, p90: {}, p99: {}, p999: {}, max: {}", + peers_per_torrent.minimum().unwrap(), + peers_per_torrent.percentile(50.0).unwrap(), + peers_per_torrent.percentile(75.0).unwrap(), + peers_per_torrent.percentile(90.0).unwrap(), + peers_per_torrent.percentile(99.0).unwrap(), + peers_per_torrent.percentile(99.9).unwrap(), + peers_per_torrent.maximum().unwrap(), + ); + + println!(); + } } }); }