mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +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
|
|
@ -1,6 +1,6 @@
|
|||
use std::sync::{atomic::AtomicUsize, Arc};
|
||||
|
||||
use rand_distr::Pareto;
|
||||
use rand_distr::Gamma;
|
||||
|
||||
pub use aquatic_http_protocol::common::*;
|
||||
pub use aquatic_http_protocol::request::*;
|
||||
|
|
@ -29,7 +29,7 @@ pub struct Statistics {
|
|||
pub struct LoadTestState {
|
||||
pub info_hashes: Arc<Vec<InfoHash>>,
|
||||
pub statistics: Arc<Statistics>,
|
||||
pub pareto: Arc<Pareto<f64>>,
|
||||
pub gamma: Arc<Gamma<f64>>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
|
|
|
|||
|
|
@ -33,24 +33,6 @@ impl aquatic_common::cli::Config for Config {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, TomlConfig, Deserialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
pub struct TorrentConfig {
|
||||
pub number_of_torrents: usize,
|
||||
/// Pareto shape
|
||||
///
|
||||
/// Fake peers choose torrents according to Pareto distribution.
|
||||
pub torrent_selection_pareto_shape: f64,
|
||||
/// Probability that a generated peer is a seeder
|
||||
pub peer_seeder_probability: f64,
|
||||
/// Probability that a generated request is a announce request, as part
|
||||
/// of sum of the various weight arguments.
|
||||
pub weight_announce: usize,
|
||||
/// Probability that a generated request is a scrape request, as part
|
||||
/// of sum of the various weight arguments.
|
||||
pub weight_scrape: usize,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
@ -68,14 +50,33 @@ impl Default for Config {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, TomlConfig, Deserialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
pub struct TorrentConfig {
|
||||
pub number_of_torrents: usize,
|
||||
/// Probability that a generated peer is a seeder
|
||||
pub peer_seeder_probability: f64,
|
||||
/// Probability that a generated request is a announce request, as part
|
||||
/// of sum of the various weight arguments.
|
||||
pub weight_announce: usize,
|
||||
/// Probability that a generated request is a scrape request, as part
|
||||
/// of sum of the various weight arguments.
|
||||
pub weight_scrape: usize,
|
||||
/// 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,
|
||||
}
|
||||
|
||||
impl Default for TorrentConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
number_of_torrents: 10_000,
|
||||
peer_seeder_probability: 0.25,
|
||||
torrent_selection_pareto_shape: 2.0,
|
||||
weight_announce: 5,
|
||||
weight_scrape: 0,
|
||||
torrent_gamma_shape: 0.2,
|
||||
torrent_gamma_scale: 100.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use ::glommio::LocalExecutorBuilder;
|
|||
use aquatic_common::cpu_pinning::glommio::{get_worker_placement, set_affinity_for_util_worker};
|
||||
use aquatic_common::cpu_pinning::WorkerIndex;
|
||||
use rand::prelude::*;
|
||||
use rand_distr::Pareto;
|
||||
use rand_distr::Gamma;
|
||||
|
||||
mod common;
|
||||
mod config;
|
||||
|
|
@ -47,12 +47,16 @@ fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
info_hashes.push(InfoHash(rng.gen()));
|
||||
}
|
||||
|
||||
let pareto = Pareto::new(1.0, config.torrents.torrent_selection_pareto_shape).unwrap();
|
||||
let gamma = Gamma::new(
|
||||
config.torrents.torrent_gamma_shape,
|
||||
config.torrents.torrent_gamma_scale,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let state = LoadTestState {
|
||||
info_hashes: Arc::new(info_hashes),
|
||||
statistics: Arc::new(Statistics::default()),
|
||||
pareto: Arc::new(pareto),
|
||||
gamma: Arc::new(gamma),
|
||||
};
|
||||
|
||||
let tls_config = create_tls_config().unwrap();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
|||
|
||||
use rand::distributions::WeightedIndex;
|
||||
use rand::prelude::*;
|
||||
use rand_distr::Pareto;
|
||||
use rand_distr::Gamma;
|
||||
|
||||
use crate::common::*;
|
||||
use crate::config::*;
|
||||
|
|
@ -69,12 +69,12 @@ fn create_scrape_request(config: &Config, state: &LoadTestState, rng: &mut impl
|
|||
|
||||
#[inline]
|
||||
fn select_info_hash_index(config: &Config, state: &LoadTestState, rng: &mut impl Rng) -> usize {
|
||||
pareto_usize(rng, &state.pareto, config.torrents.number_of_torrents - 1)
|
||||
gamma_usize(rng, &state.gamma, config.torrents.number_of_torrents - 1)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn pareto_usize(rng: &mut impl Rng, pareto: &Arc<Pareto<f64>>, max: usize) -> usize {
|
||||
let p: f64 = pareto.sample(rng);
|
||||
fn gamma_usize(rng: &mut impl Rng, gamma: &Arc<Gamma<f64>>, max: usize) -> usize {
|
||||
let p: f64 = gamma.sample(rng);
|
||||
let p = (p.min(101.0f64) - 1.0) / 100.0;
|
||||
|
||||
(p * max as f64) as usize
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue