Use gamma distribution for all load testers

This commit is contained in:
Joakim Frostegård 2022-10-26 19:49:30 +02:00
parent 2b9db63984
commit db561a1101
12 changed files with 65 additions and 55 deletions

View file

@ -58,7 +58,7 @@ fn run(config: Config) -> ::anyhow::Result<()> {
statistics: Arc::new(Statistics::default()),
};
let pareto = Gamma::new(
let gamma = Gamma::new(
config.requests.torrent_gamma_shape,
config.requests.torrent_gamma_scale,
)
@ -92,7 +92,7 @@ fn run(config: Config) -> ::anyhow::Result<()> {
WorkerIndex::SocketWorker(i as usize),
);
run_worker_thread(state, pareto, &config, addr)
run_worker_thread(state, gamma, &config, addr)
})?;
}

View file

@ -3,8 +3,8 @@ use rand_distr::Gamma;
use aquatic_udp_protocol::*;
pub fn pareto_usize(rng: &mut impl Rng, pareto: Gamma<f64>, max: usize) -> usize {
let p: f64 = rng.sample(pareto);
pub fn gamma_usize(rng: &mut impl Rng, gamma: Gamma<f64>, max: usize) -> usize {
let p: f64 = rng.sample(gamma);
let p = (p.min(101.0f64) - 1.0) / 100.0;
(p * max as f64) as usize

View file

@ -21,7 +21,7 @@ const MAX_PACKET_SIZE: usize = 8192;
pub fn run_worker_thread(
state: LoadTestState,
pareto: Gamma<f64>,
gamma: Gamma<f64>,
config: &Config,
addr: SocketAddr,
) {
@ -80,7 +80,7 @@ pub fn run_worker_thread(
let opt_request = process_response(
&mut rng,
pareto,
gamma,
&state.info_hashes,
&config,
&mut torrent_peers,

View file

@ -12,7 +12,7 @@ use crate::utils::*;
pub fn process_response(
rng: &mut impl Rng,
pareto: Gamma<f64>,
gamma: Gamma<f64>,
info_hashes: &Arc<Vec<InfoHash>>,
config: &Config,
torrent_peers: &mut TorrentPeerMap,
@ -32,7 +32,7 @@ pub fn process_response(
torrent_peer
})
.unwrap_or_else(|| {
create_torrent_peer(config, rng, pareto, info_hashes, r.connection_id)
create_torrent_peer(config, rng, gamma, info_hashes, r.connection_id)
});
let new_transaction_id = generate_transaction_id(rng);
@ -190,7 +190,7 @@ fn create_scrape_request(
fn create_torrent_peer(
config: &Config,
rng: &mut impl Rng,
pareto: Gamma<f64>,
gamma: Gamma<f64>,
info_hashes: &Arc<Vec<InfoHash>>,
connection_id: ConnectionId,
) -> TorrentPeer {
@ -199,10 +199,10 @@ fn create_torrent_peer(
let mut scrape_hash_indeces = Vec::new();
for _ in 0..num_scape_hashes {
scrape_hash_indeces.push(select_info_hash_index(config, rng, pareto))
scrape_hash_indeces.push(select_info_hash_index(config, rng, gamma))
}
let info_hash_index = select_info_hash_index(config, rng, pareto);
let info_hash_index = select_info_hash_index(config, rng, gamma);
TorrentPeer {
info_hash: info_hashes[info_hash_index],
@ -213,6 +213,6 @@ fn create_torrent_peer(
}
}
fn select_info_hash_index(config: &Config, rng: &mut impl Rng, pareto: Gamma<f64>) -> usize {
pareto_usize(rng, pareto, config.requests.number_of_torrents - 1)
fn select_info_hash_index(config: &Config, rng: &mut impl Rng, gamma: Gamma<f64>) -> usize {
gamma_usize(rng, gamma, config.requests.number_of_torrents - 1)
}