mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 10:15:31 +00:00
Use gamma distribution for all load testers
This commit is contained in:
parent
2b9db63984
commit
db561a1101
12 changed files with 65 additions and 55 deletions
|
|
@ -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)
|
||||
})?;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue