diff --git a/aquatic_udp_load_test/src/config.rs b/aquatic_udp_load_test/src/config.rs index b2566df..963c80f 100644 --- a/aquatic_udp_load_test/src/config.rs +++ b/aquatic_udp_load_test/src/config.rs @@ -101,10 +101,10 @@ pub struct RequestConfig { /// Probability that a generated request is a scrape request, as part /// of sum of the various weight arguments. pub weight_scrape: usize, - /// Pareto shape - /// - /// Fake peers choose torrents according to Pareto distribution. - pub torrent_selection_pareto_shape: f64, + /// Peers choose torrents according to this Gamma distribution shape + pub torrent_gamma_shape: f64, + /// Peers choose torrents according to this Gamma distribution scale + pub torrent_gamma_scale: f64, /// Probability that a generated peer is a seeder pub peer_seeder_probability: f64, /// Probability that an additional connect request will be sent for each @@ -116,12 +116,13 @@ impl Default for RequestConfig { fn default() -> Self { Self { number_of_torrents: 10_000, - peer_seeder_probability: 0.25, scrape_max_torrents: 50, weight_connect: 0, - weight_announce: 5, + weight_announce: 100, weight_scrape: 1, - torrent_selection_pareto_shape: 2.0, + torrent_gamma_shape: 0.2, + torrent_gamma_scale: 100.0, + peer_seeder_probability: 0.25, additional_request_probability: 0.5, } } diff --git a/aquatic_udp_load_test/src/main.rs b/aquatic_udp_load_test/src/main.rs index 7066b5f..30d70d5 100644 --- a/aquatic_udp_load_test/src/main.rs +++ b/aquatic_udp_load_test/src/main.rs @@ -6,7 +6,7 @@ use std::time::{Duration, Instant}; #[cfg(feature = "cpu-pinning")] use aquatic_common::cpu_pinning::{pin_current_if_configured_to, WorkerIndex}; -use rand_distr::Pareto; +use rand_distr::Gamma; mod common; mod config; @@ -58,7 +58,11 @@ fn run(config: Config) -> ::anyhow::Result<()> { statistics: Arc::new(Statistics::default()), }; - let pareto = Pareto::new(1.0, config.requests.torrent_selection_pareto_shape).unwrap(); + let pareto = Gamma::new( + config.requests.torrent_gamma_shape, + config.requests.torrent_gamma_scale, + ) + .unwrap(); // Start workers diff --git a/aquatic_udp_load_test/src/utils.rs b/aquatic_udp_load_test/src/utils.rs index bae1391..d436233 100644 --- a/aquatic_udp_load_test/src/utils.rs +++ b/aquatic_udp_load_test/src/utils.rs @@ -1,9 +1,9 @@ use rand::prelude::*; -use rand_distr::Pareto; +use rand_distr::Gamma; use aquatic_udp_protocol::*; -pub fn pareto_usize(rng: &mut impl Rng, pareto: Pareto, max: usize) -> usize { +pub fn pareto_usize(rng: &mut impl Rng, pareto: Gamma, max: usize) -> usize { let p: f64 = rng.sample(pareto); let p = (p.min(101.0f64) - 1.0) / 100.0; diff --git a/aquatic_udp_load_test/src/worker/mod.rs b/aquatic_udp_load_test/src/worker/mod.rs index 40b0a62..63c2fd4 100644 --- a/aquatic_udp_load_test/src/worker/mod.rs +++ b/aquatic_udp_load_test/src/worker/mod.rs @@ -8,7 +8,7 @@ use std::time::Duration; use mio::{net::UdpSocket, Events, Interest, Poll, Token}; use rand::Rng; use rand::{prelude::SmallRng, thread_rng, SeedableRng}; -use rand_distr::Pareto; +use rand_distr::Gamma; use socket2::{Domain, Protocol, Socket, Type}; use aquatic_udp_protocol::*; @@ -21,7 +21,7 @@ const MAX_PACKET_SIZE: usize = 8192; pub fn run_worker_thread( state: LoadTestState, - pareto: Pareto, + pareto: Gamma, config: &Config, addr: SocketAddr, ) { diff --git a/aquatic_udp_load_test/src/worker/request_gen.rs b/aquatic_udp_load_test/src/worker/request_gen.rs index ce99889..665ed32 100644 --- a/aquatic_udp_load_test/src/worker/request_gen.rs +++ b/aquatic_udp_load_test/src/worker/request_gen.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use rand::distributions::WeightedIndex; use rand::prelude::*; -use rand_distr::Pareto; +use rand_distr::Gamma; use aquatic_udp_protocol::*; @@ -12,7 +12,7 @@ use crate::utils::*; pub fn process_response( rng: &mut impl Rng, - pareto: Pareto, + pareto: Gamma, info_hashes: &Arc>, config: &Config, torrent_peers: &mut TorrentPeerMap, @@ -190,7 +190,7 @@ fn create_scrape_request( fn create_torrent_peer( config: &Config, rng: &mut impl Rng, - pareto: Pareto, + pareto: Gamma, info_hashes: &Arc>, connection_id: ConnectionId, ) -> TorrentPeer { @@ -213,6 +213,6 @@ fn create_torrent_peer( } } -fn select_info_hash_index(config: &Config, rng: &mut impl Rng, pareto: Pareto) -> usize { +fn select_info_hash_index(config: &Config, rng: &mut impl Rng, pareto: Gamma) -> usize { pareto_usize(rng, pareto, config.requests.number_of_torrents - 1) }