diff --git a/Cargo.lock b/Cargo.lock index c11bb2f..2eebe57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,7 +73,6 @@ dependencies = [ "indicatif", "mimalloc", "num-format", - "plotly", "rand", "rand_distr", "serde", @@ -935,6 +934,15 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" +[[package]] +name = "plot_pareto" +version = "0.1.0" +dependencies = [ + "plotly", + "rand", + "rand_distr", +] + [[package]] name = "plotly" version = "0.4.1" diff --git a/Cargo.toml b/Cargo.toml index d9d9e67..e890ce2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ members = [ "aquatic_udp_load_test", "aquatic_udp_protocol", "aquatic_ws", + "plot_pareto" ] [profile.release] diff --git a/TODO.md b/TODO.md index 0cb2fec..e69c180 100644 --- a/TODO.md +++ b/TODO.md @@ -11,9 +11,6 @@ use of Ipv4 ones, I have to check. * More tests? -## aquatic_udp_bench -* move plot_pareto to own crate - ## bittorrent_udp * Tests with good known byte sequences (requests and responses) diff --git a/aquatic_udp_bench/Cargo.toml b/aquatic_udp_bench/Cargo.toml index 6da3f10..9829f26 100644 --- a/aquatic_udp_bench/Cargo.toml +++ b/aquatic_udp_bench/Cargo.toml @@ -5,15 +5,9 @@ authors = ["Joakim FrostegÄrd "] edition = "2018" license = "Apache-2.0" -[lib] +[[bin]] name = "aquatic_udp_bench" -[[bin]] -name = "aquatic_udp_bench_handlers" - -[[bin]] -name = "plot_pareto" - [dependencies] anyhow = "1" aquatic_cli_helpers = { path = "../aquatic_cli_helpers" } @@ -22,7 +16,6 @@ crossbeam-channel = "0.4" indicatif = "0.14" mimalloc = { version = "0.1", default-features = false } num-format = "0.4" -plotly = "0.4" rand = { version = "0.7", features = ["small_rng"] } rand_distr = "0.2" serde = { version = "1", features = ["derive"] } diff --git a/aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/announce.rs b/aquatic_udp_bench/src/announce.rs similarity index 98% rename from aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/announce.rs rename to aquatic_udp_bench/src/announce.rs index efba852..b1e9793 100644 --- a/aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/announce.rs +++ b/aquatic_udp_bench/src/announce.rs @@ -9,8 +9,6 @@ use rand_distr::Pareto; use aquatic_udp::common::*; use aquatic_udp::config::Config; -use aquatic_udp_bench::pareto_usize; - use crate::common::*; use crate::config::BenchConfig; diff --git a/aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/common.rs b/aquatic_udp_bench/src/common.rs similarity index 60% rename from aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/common.rs rename to aquatic_udp_bench/src/common.rs index 615e969..cc34b0b 100644 --- a/aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/common.rs +++ b/aquatic_udp_bench/src/common.rs @@ -1,5 +1,6 @@ - use indicatif::{ProgressBar, ProgressStyle}; +use rand::Rng; +use rand_distr::Pareto; pub const PARETO_SHAPE: f64 = 0.1; @@ -12,3 +13,15 @@ pub fn create_progress_bar(name: &str, iterations: u64) -> ProgressBar { ProgressBar::new(iterations).with_style(style) } + + +pub fn pareto_usize( + rng: &mut impl Rng, + pareto: Pareto, + max: usize, +) -> usize { + let p: f64 = rng.sample(pareto); + let p = (p.min(101.0f64) - 1.0) / 100.0; + + (p * max as f64) as usize +} \ No newline at end of file diff --git a/aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/config.rs b/aquatic_udp_bench/src/config.rs similarity index 100% rename from aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/config.rs rename to aquatic_udp_bench/src/config.rs diff --git a/aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/connect.rs b/aquatic_udp_bench/src/connect.rs similarity index 100% rename from aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/connect.rs rename to aquatic_udp_bench/src/connect.rs diff --git a/aquatic_udp_bench/src/lib.rs b/aquatic_udp_bench/src/lib.rs deleted file mode 100644 index 1cc91c8..0000000 --- a/aquatic_udp_bench/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -use rand::Rng; -use rand_distr::Pareto; - - -pub fn pareto_usize( - rng: &mut impl Rng, - pareto: Pareto, - max: usize, -) -> usize { - let p: f64 = rng.sample(pareto); - let p = (p.min(101.0f64) - 1.0) / 100.0; - - (p * max as f64) as usize -} \ No newline at end of file diff --git a/aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/main.rs b/aquatic_udp_bench/src/main.rs similarity index 100% rename from aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/main.rs rename to aquatic_udp_bench/src/main.rs diff --git a/aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/scrape.rs b/aquatic_udp_bench/src/scrape.rs similarity index 98% rename from aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/scrape.rs rename to aquatic_udp_bench/src/scrape.rs index bee40b9..dffa2e3 100644 --- a/aquatic_udp_bench/src/bin/aquatic_udp_bench_handlers/scrape.rs +++ b/aquatic_udp_bench/src/scrape.rs @@ -9,8 +9,6 @@ use rand_distr::Pareto; use aquatic_udp::common::*; use aquatic_udp::config::Config; -use aquatic_udp_bench::pareto_usize; - use crate::common::*; use crate::config::BenchConfig; diff --git a/plot_pareto/Cargo.toml b/plot_pareto/Cargo.toml new file mode 100644 index 0000000..875819b --- /dev/null +++ b/plot_pareto/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "plot_pareto" +version = "0.1.0" +authors = ["Joakim FrostegÄrd "] +edition = "2018" +license = "Apache-2.0" + +[[bin]] +name = "plot_pareto" + +[dependencies] +plotly = "0.4" +rand = { version = "0.7", features = ["small_rng"] } +rand_distr = "0.2" \ No newline at end of file diff --git a/aquatic_udp_bench/src/bin/plot_pareto.rs b/plot_pareto/src/main.rs similarity index 79% rename from aquatic_udp_bench/src/bin/plot_pareto.rs rename to plot_pareto/src/main.rs index f5ab294..4d6cf5c 100644 --- a/aquatic_udp_bench/src/bin/plot_pareto.rs +++ b/plot_pareto/src/main.rs @@ -1,11 +1,9 @@ use plotly::{Plot, Scatter, Layout}; use plotly::common::Title; use plotly::layout::Axis; -use rand::{thread_rng, rngs::SmallRng, SeedableRng}; +use rand::{thread_rng, rngs::SmallRng, SeedableRng, Rng}; use rand_distr::Pareto; -use aquatic_udp_bench::pareto_usize; - fn main(){ let mut plot = Plot::new(); @@ -42,3 +40,15 @@ fn main(){ plot.show(); } + + +pub fn pareto_usize( + rng: &mut impl Rng, + pareto: Pareto, + max: usize, +) -> usize { + let p: f64 = rng.sample(pareto); + let p = (p.min(101.0f64) - 1.0) / 100.0; + + (p * max as f64) as usize +} \ No newline at end of file diff --git a/scripts/bench-udp-handlers.sh b/scripts/bench-udp-handlers.sh index e09f1d6..565268c 100755 --- a/scripts/bench-udp-handlers.sh +++ b/scripts/bench-udp-handlers.sh @@ -2,4 +2,4 @@ export RUSTFLAGS="-C target-cpu=native" -cargo run --release --bin aquatic_udp_bench_handlers -- $@ \ No newline at end of file +cargo run --release --bin aquatic_udp_bench -- $@ \ No newline at end of file