mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 10:45:30 +00:00
udp load test: use Gamma distribution for torrent selection
This commit is contained in:
parent
15f8d30518
commit
2b9db63984
5 changed files with 22 additions and 17 deletions
|
|
@ -101,10 +101,10 @@ pub struct RequestConfig {
|
||||||
/// Probability that a generated request is a scrape request, as part
|
/// Probability that a generated request is a scrape request, as part
|
||||||
/// of sum of the various weight arguments.
|
/// of sum of the various weight arguments.
|
||||||
pub weight_scrape: usize,
|
pub weight_scrape: usize,
|
||||||
/// Pareto shape
|
/// Peers choose torrents according to this Gamma distribution shape
|
||||||
///
|
pub torrent_gamma_shape: f64,
|
||||||
/// Fake peers choose torrents according to Pareto distribution.
|
/// Peers choose torrents according to this Gamma distribution scale
|
||||||
pub torrent_selection_pareto_shape: f64,
|
pub torrent_gamma_scale: f64,
|
||||||
/// Probability that a generated peer is a seeder
|
/// Probability that a generated peer is a seeder
|
||||||
pub peer_seeder_probability: f64,
|
pub peer_seeder_probability: f64,
|
||||||
/// Probability that an additional connect request will be sent for each
|
/// Probability that an additional connect request will be sent for each
|
||||||
|
|
@ -116,12 +116,13 @@ impl Default for RequestConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
number_of_torrents: 10_000,
|
number_of_torrents: 10_000,
|
||||||
peer_seeder_probability: 0.25,
|
|
||||||
scrape_max_torrents: 50,
|
scrape_max_torrents: 50,
|
||||||
weight_connect: 0,
|
weight_connect: 0,
|
||||||
weight_announce: 5,
|
weight_announce: 100,
|
||||||
weight_scrape: 1,
|
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,
|
additional_request_probability: 0.5,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use std::time::{Duration, Instant};
|
||||||
|
|
||||||
#[cfg(feature = "cpu-pinning")]
|
#[cfg(feature = "cpu-pinning")]
|
||||||
use aquatic_common::cpu_pinning::{pin_current_if_configured_to, WorkerIndex};
|
use aquatic_common::cpu_pinning::{pin_current_if_configured_to, WorkerIndex};
|
||||||
use rand_distr::Pareto;
|
use rand_distr::Gamma;
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
mod config;
|
mod config;
|
||||||
|
|
@ -58,7 +58,11 @@ fn run(config: Config) -> ::anyhow::Result<()> {
|
||||||
statistics: Arc::new(Statistics::default()),
|
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
|
// Start workers
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use rand_distr::Pareto;
|
use rand_distr::Gamma;
|
||||||
|
|
||||||
use aquatic_udp_protocol::*;
|
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: f64 = rng.sample(pareto);
|
||||||
let p = (p.min(101.0f64) - 1.0) / 100.0;
|
let p = (p.min(101.0f64) - 1.0) / 100.0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use std::time::Duration;
|
||||||
use mio::{net::UdpSocket, Events, Interest, Poll, Token};
|
use mio::{net::UdpSocket, Events, Interest, Poll, Token};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand::{prelude::SmallRng, thread_rng, SeedableRng};
|
use rand::{prelude::SmallRng, thread_rng, SeedableRng};
|
||||||
use rand_distr::Pareto;
|
use rand_distr::Gamma;
|
||||||
use socket2::{Domain, Protocol, Socket, Type};
|
use socket2::{Domain, Protocol, Socket, Type};
|
||||||
|
|
||||||
use aquatic_udp_protocol::*;
|
use aquatic_udp_protocol::*;
|
||||||
|
|
@ -21,7 +21,7 @@ const MAX_PACKET_SIZE: usize = 8192;
|
||||||
|
|
||||||
pub fn run_worker_thread(
|
pub fn run_worker_thread(
|
||||||
state: LoadTestState,
|
state: LoadTestState,
|
||||||
pareto: Pareto<f64>,
|
pareto: Gamma<f64>,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use rand::distributions::WeightedIndex;
|
use rand::distributions::WeightedIndex;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use rand_distr::Pareto;
|
use rand_distr::Gamma;
|
||||||
|
|
||||||
use aquatic_udp_protocol::*;
|
use aquatic_udp_protocol::*;
|
||||||
|
|
||||||
|
|
@ -12,7 +12,7 @@ use crate::utils::*;
|
||||||
|
|
||||||
pub fn process_response(
|
pub fn process_response(
|
||||||
rng: &mut impl Rng,
|
rng: &mut impl Rng,
|
||||||
pareto: Pareto<f64>,
|
pareto: Gamma<f64>,
|
||||||
info_hashes: &Arc<Vec<InfoHash>>,
|
info_hashes: &Arc<Vec<InfoHash>>,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
torrent_peers: &mut TorrentPeerMap,
|
torrent_peers: &mut TorrentPeerMap,
|
||||||
|
|
@ -190,7 +190,7 @@ fn create_scrape_request(
|
||||||
fn create_torrent_peer(
|
fn create_torrent_peer(
|
||||||
config: &Config,
|
config: &Config,
|
||||||
rng: &mut impl Rng,
|
rng: &mut impl Rng,
|
||||||
pareto: Pareto<f64>,
|
pareto: Gamma<f64>,
|
||||||
info_hashes: &Arc<Vec<InfoHash>>,
|
info_hashes: &Arc<Vec<InfoHash>>,
|
||||||
connection_id: ConnectionId,
|
connection_id: ConnectionId,
|
||||||
) -> TorrentPeer {
|
) -> 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)
|
pareto_usize(rng, pareto, config.requests.number_of_torrents - 1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue