mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25:30 +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 crossbeam_channel::{Receiver, Sender};
|
||||||
use indicatif::ProgressIterator;
|
use indicatif::ProgressIterator;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand_distr::Pareto;
|
use rand_distr::Gamma;
|
||||||
|
|
||||||
use aquatic_udp::common::*;
|
use aquatic_udp::common::*;
|
||||||
use aquatic_udp_protocol::*;
|
use aquatic_udp_protocol::*;
|
||||||
|
|
@ -81,14 +81,14 @@ pub fn create_requests(
|
||||||
info_hashes: &[InfoHash],
|
info_hashes: &[InfoHash],
|
||||||
number: usize,
|
number: usize,
|
||||||
) -> Vec<(AnnounceRequest, CanonicalSocketAddr)> {
|
) -> 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 max_index = info_hashes.len() - 1;
|
||||||
|
|
||||||
let mut requests = Vec::new();
|
let mut requests = Vec::new();
|
||||||
|
|
||||||
for _ in 0..number {
|
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 {
|
let request = AnnounceRequest {
|
||||||
connection_id: ConnectionId(0),
|
connection_id: ConnectionId(0),
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
use rand::Rng;
|
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 const NUM_INFO_HASHES: usize = 10_000;
|
||||||
|
|
||||||
pub fn create_progress_bar(name: &str, iterations: u64) -> ProgressBar {
|
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)
|
ProgressBar::new(iterations).with_style(style)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pareto_usize(rng: &mut impl Rng, pareto: Pareto<f64>, max: usize) -> usize {
|
pub fn gamma_usize(rng: &mut impl Rng, gamma: Gamma<f64>, max: usize) -> usize {
|
||||||
let p: f64 = rng.sample(pareto);
|
let p: f64 = rng.sample(gamma);
|
||||||
let p = (p.min(101.0f64) - 1.0) / 100.0;
|
let p = (p.min(101.0f64) - 1.0) / 100.0;
|
||||||
|
|
||||||
(p * max as f64) as usize
|
(p * max as f64) as usize
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use aquatic_common::CanonicalSocketAddr;
|
||||||
use crossbeam_channel::{Receiver, Sender};
|
use crossbeam_channel::{Receiver, Sender};
|
||||||
use indicatif::ProgressIterator;
|
use indicatif::ProgressIterator;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use rand_distr::Pareto;
|
use rand_distr::Gamma;
|
||||||
|
|
||||||
use aquatic_udp::common::*;
|
use aquatic_udp::common::*;
|
||||||
use aquatic_udp_protocol::*;
|
use aquatic_udp_protocol::*;
|
||||||
|
|
@ -93,7 +93,7 @@ pub fn create_requests(
|
||||||
number: usize,
|
number: usize,
|
||||||
hashes_per_request: usize,
|
hashes_per_request: usize,
|
||||||
) -> Vec<(ScrapeRequest, CanonicalSocketAddr)> {
|
) -> 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;
|
let max_index = info_hashes.len() - 1;
|
||||||
|
|
||||||
|
|
@ -103,7 +103,7 @@ pub fn create_requests(
|
||||||
let mut request_info_hashes = Vec::new();
|
let mut request_info_hashes = Vec::new();
|
||||||
|
|
||||||
for _ in 0..hashes_per_request {
|
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])
|
request_info_hashes.push(info_hashes[info_hash_index])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue