udp load test: use Gamma distribution for torrent selection

This commit is contained in:
Joakim Frostegård 2022-10-26 19:45:39 +02:00
parent 15f8d30518
commit 2b9db63984
5 changed files with 22 additions and 17 deletions

View file

@ -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,
}
}

View file

@ -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

View file

@ -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<f64>, max: usize) -> usize {
pub fn pareto_usize(rng: &mut impl Rng, pareto: Gamma<f64>, max: usize) -> usize {
let p: f64 = rng.sample(pareto);
let p = (p.min(101.0f64) - 1.0) / 100.0;

View file

@ -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<f64>,
pareto: Gamma<f64>,
config: &Config,
addr: SocketAddr,
) {

View file

@ -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<f64>,
pareto: Gamma<f64>,
info_hashes: &Arc<Vec<InfoHash>>,
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<f64>,
pareto: Gamma<f64>,
info_hashes: &Arc<Vec<InfoHash>>,
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<f64>) -> usize {
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)
}