mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 09:45:31 +00:00
udp bench: use gamma distribution for torrent selection
This commit is contained in:
parent
db561a1101
commit
84f420e2c5
3 changed files with 12 additions and 10 deletions
|
|
@ -5,7 +5,7 @@ use aquatic_common::CanonicalSocketAddr;
|
|||
use crossbeam_channel::{Receiver, Sender};
|
||||
use indicatif::ProgressIterator;
|
||||
use rand::Rng;
|
||||
use rand_distr::Pareto;
|
||||
use rand_distr::Gamma;
|
||||
|
||||
use aquatic_udp::common::*;
|
||||
use aquatic_udp_protocol::*;
|
||||
|
|
@ -81,14 +81,14 @@ pub fn create_requests(
|
|||
info_hashes: &[InfoHash],
|
||||
number: usize,
|
||||
) -> Vec<(AnnounceRequest, CanonicalSocketAddr)> {
|
||||
let pareto = Pareto::new(1., PARETO_SHAPE).unwrap();
|
||||
let gamma = Gamma::new(GAMMA_SHAPE, GAMMA_SCALE).unwrap();
|
||||
|
||||
let max_index = info_hashes.len() - 1;
|
||||
|
||||
let mut requests = Vec::new();
|
||||
|
||||
for _ in 0..number {
|
||||
let info_hash_index = pareto_usize(rng, pareto, max_index);
|
||||
let info_hash_index = gamma_usize(rng, gamma, max_index);
|
||||
|
||||
let request = AnnounceRequest {
|
||||
connection_id: ConnectionId(0),
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use rand::Rng;
|
||||
use rand_distr::Pareto;
|
||||
use rand_distr::Gamma;
|
||||
|
||||
pub const GAMMA_SHAPE: f64 = 0.2;
|
||||
pub const GAMMA_SCALE: f64 = 100.0;
|
||||
|
||||
pub const PARETO_SHAPE: f64 = 0.1;
|
||||
pub const NUM_INFO_HASHES: usize = 10_000;
|
||||
|
||||
pub fn create_progress_bar(name: &str, iterations: u64) -> ProgressBar {
|
||||
|
|
@ -12,8 +14,8 @@ pub fn create_progress_bar(name: &str, iterations: u64) -> ProgressBar {
|
|||
ProgressBar::new(iterations).with_style(style)
|
||||
}
|
||||
|
||||
pub fn pareto_usize(rng: &mut impl Rng, pareto: Pareto<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
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use aquatic_common::CanonicalSocketAddr;
|
|||
use crossbeam_channel::{Receiver, Sender};
|
||||
use indicatif::ProgressIterator;
|
||||
use rand::Rng;
|
||||
use rand_distr::Pareto;
|
||||
use rand_distr::Gamma;
|
||||
|
||||
use aquatic_udp::common::*;
|
||||
use aquatic_udp_protocol::*;
|
||||
|
|
@ -93,7 +93,7 @@ pub fn create_requests(
|
|||
number: usize,
|
||||
hashes_per_request: usize,
|
||||
) -> Vec<(ScrapeRequest, CanonicalSocketAddr)> {
|
||||
let pareto = Pareto::new(1., PARETO_SHAPE).unwrap();
|
||||
let gamma = Gamma::new(GAMMA_SHAPE, GAMMA_SCALE).unwrap();
|
||||
|
||||
let max_index = info_hashes.len() - 1;
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ pub fn create_requests(
|
|||
let mut request_info_hashes = Vec::new();
|
||||
|
||||
for _ in 0..hashes_per_request {
|
||||
let info_hash_index = pareto_usize(rng, pareto, max_index);
|
||||
let info_hash_index = gamma_usize(rng, gamma, max_index);
|
||||
request_info_hashes.push(info_hashes[info_hash_index])
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue