mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 02:35:31 +00:00
Run rustfmt, clean up aquatic_http_protocol/Cargo.toml
This commit is contained in:
parent
0cc312a78d
commit
d0e716f80b
65 changed files with 1754 additions and 2590 deletions
|
|
@ -1,10 +1,9 @@
|
|||
use std::sync::{Arc, atomic::AtomicUsize};
|
||||
use std::sync::{atomic::AtomicUsize, Arc};
|
||||
|
||||
use rand_distr::Pareto;
|
||||
|
||||
pub use aquatic_ws_protocol::*;
|
||||
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Statistics {
|
||||
pub requests: AtomicUsize,
|
||||
|
|
@ -15,7 +14,6 @@ pub struct Statistics {
|
|||
pub responses_scrape: AtomicUsize,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LoadTestState {
|
||||
pub info_hashes: Arc<Vec<InfoHash>>,
|
||||
|
|
@ -23,9 +21,8 @@ pub struct LoadTestState {
|
|||
pub pareto: Arc<Pareto<f64>>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
pub enum RequestType {
|
||||
Announce,
|
||||
Scrape
|
||||
}
|
||||
Scrape,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use std::net::SocketAddr;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
|
|
@ -14,10 +13,8 @@ pub struct Config {
|
|||
pub torrents: TorrentConfig,
|
||||
}
|
||||
|
||||
|
||||
impl aquatic_cli_helpers::Config for Config {}
|
||||
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct NetworkConfig {
|
||||
|
|
@ -26,14 +23,13 @@ pub struct NetworkConfig {
|
|||
pub poll_event_capacity: usize,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct TorrentConfig {
|
||||
pub offers_per_request: usize,
|
||||
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
|
||||
|
|
@ -46,7 +42,6 @@ pub struct TorrentConfig {
|
|||
pub weight_scrape: usize,
|
||||
}
|
||||
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
@ -70,7 +65,6 @@ impl Default for NetworkConfig {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Default for TorrentConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use std::sync::{atomic::Ordering, Arc};
|
||||
use std::thread;
|
||||
use std::sync::{Arc, atomic::Ordering};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use rand::prelude::*;
|
||||
|
|
@ -14,27 +14,24 @@ use common::*;
|
|||
use config::*;
|
||||
use network::*;
|
||||
|
||||
|
||||
#[global_allocator]
|
||||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||
|
||||
|
||||
pub fn main(){
|
||||
pub fn main() {
|
||||
aquatic_cli_helpers::run_app_with_cli_and_config::<Config>(
|
||||
"aquatic_ws_load_test: WebTorrent load tester",
|
||||
run,
|
||||
None
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
fn run(config: Config) -> ::anyhow::Result<()> {
|
||||
if config.torrents.weight_announce + config.torrents.weight_scrape == 0 {
|
||||
panic!("Error: at least one weight must be larger than zero.");
|
||||
}
|
||||
|
||||
println!("Starting client with config: {:#?}", config);
|
||||
|
||||
|
||||
let mut info_hashes = Vec::with_capacity(config.torrents.number_of_torrents);
|
||||
|
||||
let mut rng = SmallRng::from_entropy();
|
||||
|
|
@ -43,10 +40,7 @@ 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 pareto = Pareto::new(1.0, config.torrents.torrent_selection_pareto_shape).unwrap();
|
||||
|
||||
let state = LoadTestState {
|
||||
info_hashes: Arc::new(info_hashes),
|
||||
|
|
@ -58,22 +52,15 @@ fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
let config = config.clone();
|
||||
let state = state.clone();
|
||||
|
||||
thread::spawn(move || run_socket_thread(&config, state,));
|
||||
thread::spawn(move || run_socket_thread(&config, state));
|
||||
}
|
||||
|
||||
monitor_statistics(
|
||||
state,
|
||||
&config
|
||||
);
|
||||
monitor_statistics(state, &config);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn monitor_statistics(
|
||||
state: LoadTestState,
|
||||
config: &Config,
|
||||
){
|
||||
fn monitor_statistics(state: LoadTestState, config: &Config) {
|
||||
let start_time = Instant::now();
|
||||
let mut report_avg_response_vec: Vec<f64> = Vec::new();
|
||||
|
||||
|
|
@ -85,38 +72,40 @@ fn monitor_statistics(
|
|||
|
||||
let statistics = state.statistics.as_ref();
|
||||
|
||||
let responses_announce = statistics.responses_announce
|
||||
.fetch_and(0, Ordering::SeqCst) as f64;
|
||||
let responses_announce =
|
||||
statistics.responses_announce.fetch_and(0, Ordering::SeqCst) as f64;
|
||||
// let response_peers = statistics.response_peers
|
||||
// .fetch_and(0, Ordering::SeqCst) as f64;
|
||||
|
||||
let requests_per_second = statistics.requests
|
||||
.fetch_and(0, Ordering::SeqCst) as f64 / interval_f64;
|
||||
let responses_offer_per_second = statistics.responses_offer
|
||||
.fetch_and(0, Ordering::SeqCst) as f64 / interval_f64;
|
||||
let responses_answer_per_second = statistics.responses_answer
|
||||
.fetch_and(0, Ordering::SeqCst) as f64 / interval_f64;
|
||||
let responses_scrape_per_second = statistics.responses_scrape
|
||||
.fetch_and(0, Ordering::SeqCst) as f64 / interval_f64;
|
||||
let requests_per_second =
|
||||
statistics.requests.fetch_and(0, Ordering::SeqCst) as f64 / interval_f64;
|
||||
let responses_offer_per_second =
|
||||
statistics.responses_offer.fetch_and(0, Ordering::SeqCst) as f64 / interval_f64;
|
||||
let responses_answer_per_second =
|
||||
statistics.responses_answer.fetch_and(0, Ordering::SeqCst) as f64 / interval_f64;
|
||||
let responses_scrape_per_second =
|
||||
statistics.responses_scrape.fetch_and(0, Ordering::SeqCst) as f64 / interval_f64;
|
||||
|
||||
let responses_announce_per_second = responses_announce / interval_f64;
|
||||
let responses_announce_per_second = responses_announce / interval_f64;
|
||||
|
||||
let responses_per_second =
|
||||
responses_announce_per_second +
|
||||
responses_offer_per_second +
|
||||
responses_answer_per_second +
|
||||
responses_scrape_per_second;
|
||||
let responses_per_second = responses_announce_per_second
|
||||
+ responses_offer_per_second
|
||||
+ responses_answer_per_second
|
||||
+ responses_scrape_per_second;
|
||||
|
||||
report_avg_response_vec.push(responses_per_second);
|
||||
|
||||
println!();
|
||||
println!("Requests out: {:.2}/second", requests_per_second);
|
||||
println!("Responses in: {:.2}/second", responses_per_second);
|
||||
println!(" - Announce responses: {:.2}", responses_announce_per_second);
|
||||
println!(
|
||||
" - Announce responses: {:.2}",
|
||||
responses_announce_per_second
|
||||
);
|
||||
println!(" - Offer responses: {:.2}", responses_offer_per_second);
|
||||
println!(" - Answer responses: {:.2}", responses_answer_per_second);
|
||||
println!(" - Scrape responses: {:.2}", responses_scrape_per_second);
|
||||
|
||||
|
||||
let time_elapsed = start_time.elapsed();
|
||||
let duration = Duration::from_secs(config.duration as u64);
|
||||
|
||||
|
|
@ -136,7 +125,7 @@ fn monitor_statistics(
|
|||
config
|
||||
);
|
||||
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,24 @@
|
|||
use std::io::ErrorKind;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
use std::io::ErrorKind;
|
||||
|
||||
use hashbrown::HashMap;
|
||||
use mio::{net::TcpStream, Events, Poll, Interest, Token};
|
||||
use rand::{rngs::SmallRng, prelude::*};
|
||||
use tungstenite::{WebSocket, HandshakeError, ClientHandshake, handshake::MidHandshake};
|
||||
use mio::{net::TcpStream, Events, Interest, Poll, Token};
|
||||
use rand::{prelude::*, rngs::SmallRng};
|
||||
use tungstenite::{handshake::MidHandshake, ClientHandshake, HandshakeError, WebSocket};
|
||||
|
||||
use crate::common::*;
|
||||
use crate::config::*;
|
||||
use crate::utils::create_random_request;
|
||||
|
||||
|
||||
// Allow large enum variant WebSocket because it should be very common
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum ConnectionState {
|
||||
TcpStream(TcpStream),
|
||||
WebSocket(WebSocket<TcpStream>),
|
||||
MidHandshake(MidHandshake<ClientHandshake<TcpStream>>)
|
||||
MidHandshake(MidHandshake<ClientHandshake<TcpStream>>),
|
||||
}
|
||||
|
||||
|
||||
impl ConnectionState {
|
||||
fn advance(self, config: &Config) -> Option<Self> {
|
||||
match self {
|
||||
|
|
@ -31,33 +29,27 @@ impl ConnectionState {
|
|||
config.server_address.port()
|
||||
);
|
||||
|
||||
match ::tungstenite::client(req, stream){
|
||||
Ok((ws, _)) => {
|
||||
Some(ConnectionState::WebSocket(ws))
|
||||
},
|
||||
match ::tungstenite::client(req, stream) {
|
||||
Ok((ws, _)) => Some(ConnectionState::WebSocket(ws)),
|
||||
Err(HandshakeError::Interrupted(handshake)) => {
|
||||
Some(ConnectionState::MidHandshake(handshake))
|
||||
},
|
||||
}
|
||||
Err(HandshakeError::Failure(err)) => {
|
||||
eprintln!("handshake error: {:?}", err);
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
},
|
||||
Self::MidHandshake(handshake) => {
|
||||
match handshake.handshake() {
|
||||
Ok((ws, _)) => {
|
||||
Some(ConnectionState::WebSocket(ws))
|
||||
},
|
||||
Err(HandshakeError::Interrupted(handshake)) => {
|
||||
Some(ConnectionState::MidHandshake(handshake))
|
||||
},
|
||||
Err(HandshakeError::Failure(err)) => {
|
||||
eprintln!("handshake error: {:?}", err);
|
||||
}
|
||||
Self::MidHandshake(handshake) => match handshake.handshake() {
|
||||
Ok((ws, _)) => Some(ConnectionState::WebSocket(ws)),
|
||||
Err(HandshakeError::Interrupted(handshake)) => {
|
||||
Some(ConnectionState::MidHandshake(handshake))
|
||||
}
|
||||
Err(HandshakeError::Failure(err)) => {
|
||||
eprintln!("handshake error: {:?}", err);
|
||||
|
||||
None
|
||||
}
|
||||
None
|
||||
}
|
||||
},
|
||||
Self::WebSocket(ws) => Some(Self::WebSocket(ws)),
|
||||
|
|
@ -65,7 +57,6 @@ impl ConnectionState {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct Connection {
|
||||
stream: ConnectionState,
|
||||
peer_id: PeerId,
|
||||
|
|
@ -73,7 +64,6 @@ pub struct Connection {
|
|||
send_answer: Option<(PeerId, OfferId)>,
|
||||
}
|
||||
|
||||
|
||||
impl Connection {
|
||||
pub fn create_and_register(
|
||||
config: &Config,
|
||||
|
|
@ -83,27 +73,31 @@ impl Connection {
|
|||
token_counter: &mut usize,
|
||||
) -> anyhow::Result<()> {
|
||||
let mut stream = TcpStream::connect(config.server_address)?;
|
||||
|
||||
|
||||
poll.registry()
|
||||
.register(&mut stream, Token(*token_counter), Interest::READABLE | Interest::WRITABLE)
|
||||
.register(
|
||||
&mut stream,
|
||||
Token(*token_counter),
|
||||
Interest::READABLE | Interest::WRITABLE,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let connection = Connection {
|
||||
let connection = Connection {
|
||||
stream: ConnectionState::TcpStream(stream),
|
||||
peer_id: PeerId(rng.gen()),
|
||||
can_send: false,
|
||||
send_answer: None,
|
||||
};
|
||||
|
||||
|
||||
connections.insert(*token_counter, connection);
|
||||
|
||||
*token_counter += 1;
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn advance(self, config: &Config) -> Option<Self> {
|
||||
if let Some(stream) = self.stream.advance(config){
|
||||
if let Some(stream) = self.stream.advance(config) {
|
||||
let can_send = matches!(stream, ConnectionState::WebSocket(_));
|
||||
|
||||
Some(Self {
|
||||
|
|
@ -117,52 +111,53 @@ impl Connection {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read_responses(
|
||||
&mut self,
|
||||
state: &LoadTestState,
|
||||
) -> bool { // bool = drop connection
|
||||
pub fn read_responses(&mut self, state: &LoadTestState) -> bool {
|
||||
// bool = drop connection
|
||||
if let ConnectionState::WebSocket(ref mut ws) = self.stream {
|
||||
loop {
|
||||
match ws.read_message(){
|
||||
Ok(message) => {
|
||||
match OutMessage::from_ws_message(message){
|
||||
Ok(OutMessage::Offer(offer)) => {
|
||||
state.statistics.responses_offer
|
||||
.fetch_add(1, Ordering::SeqCst);
|
||||
|
||||
self.send_answer = Some((
|
||||
offer.peer_id,
|
||||
offer.offer_id
|
||||
));
|
||||
match ws.read_message() {
|
||||
Ok(message) => match OutMessage::from_ws_message(message) {
|
||||
Ok(OutMessage::Offer(offer)) => {
|
||||
state
|
||||
.statistics
|
||||
.responses_offer
|
||||
.fetch_add(1, Ordering::SeqCst);
|
||||
|
||||
self.can_send = true;
|
||||
},
|
||||
Ok(OutMessage::Answer(_)) => {
|
||||
state.statistics.responses_answer
|
||||
.fetch_add(1, Ordering::SeqCst);
|
||||
self.send_answer = Some((offer.peer_id, offer.offer_id));
|
||||
|
||||
self.can_send = true;
|
||||
},
|
||||
Ok(OutMessage::AnnounceResponse(_)) => {
|
||||
state.statistics.responses_announce
|
||||
.fetch_add(1, Ordering::SeqCst);
|
||||
self.can_send = true;
|
||||
}
|
||||
Ok(OutMessage::Answer(_)) => {
|
||||
state
|
||||
.statistics
|
||||
.responses_answer
|
||||
.fetch_add(1, Ordering::SeqCst);
|
||||
|
||||
self.can_send = true;
|
||||
},
|
||||
Ok(OutMessage::ScrapeResponse(_)) => {
|
||||
state.statistics.responses_scrape
|
||||
.fetch_add(1, Ordering::SeqCst);
|
||||
self.can_send = true;
|
||||
}
|
||||
Ok(OutMessage::AnnounceResponse(_)) => {
|
||||
state
|
||||
.statistics
|
||||
.responses_announce
|
||||
.fetch_add(1, Ordering::SeqCst);
|
||||
|
||||
self.can_send = true;
|
||||
},
|
||||
Err(err) => {
|
||||
eprintln!("error deserializing offer: {:?}", err);
|
||||
}
|
||||
self.can_send = true;
|
||||
}
|
||||
Ok(OutMessage::ScrapeResponse(_)) => {
|
||||
state
|
||||
.statistics
|
||||
.responses_scrape
|
||||
.fetch_add(1, Ordering::SeqCst);
|
||||
|
||||
self.can_send = true;
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("error deserializing offer: {:?}", err);
|
||||
}
|
||||
},
|
||||
Err(tungstenite::Error::Io(err)) if err.kind() == ErrorKind::WouldBlock => {
|
||||
return false;
|
||||
},
|
||||
}
|
||||
Err(_) => {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -178,18 +173,14 @@ impl Connection {
|
|||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
) -> bool { // bool = remove connection
|
||||
) -> bool {
|
||||
// bool = remove connection
|
||||
if !self.can_send {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let ConnectionState::WebSocket(ref mut ws) = self.stream {
|
||||
let request = create_random_request(
|
||||
&config,
|
||||
&state,
|
||||
rng,
|
||||
self.peer_id
|
||||
);
|
||||
let request = create_random_request(&config, &state, rng, self.peer_id);
|
||||
|
||||
// If self.send_answer is set and request is announce request, make
|
||||
// the request an offer answer
|
||||
|
|
@ -211,20 +202,16 @@ impl Connection {
|
|||
request
|
||||
};
|
||||
|
||||
match ws.write_message(request.to_ws_message()){
|
||||
match ws.write_message(request.to_ws_message()) {
|
||||
Ok(()) => {
|
||||
state.statistics.requests.fetch_add(1, Ordering::SeqCst);
|
||||
|
||||
self.can_send = false;
|
||||
|
||||
false
|
||||
},
|
||||
Err(tungstenite::Error::Io(err)) if err.kind() == ErrorKind::WouldBlock => {
|
||||
false
|
||||
}
|
||||
Err(_) => {
|
||||
true
|
||||
}
|
||||
Err(tungstenite::Error::Io(err)) if err.kind() == ErrorKind::WouldBlock => false,
|
||||
Err(_) => true,
|
||||
}
|
||||
} else {
|
||||
println!("send request can't send to non-ws stream");
|
||||
|
|
@ -234,14 +221,9 @@ impl Connection {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub type ConnectionMap = HashMap<usize, Connection>;
|
||||
|
||||
|
||||
pub fn run_socket_thread(
|
||||
config: &Config,
|
||||
state: LoadTestState,
|
||||
) {
|
||||
pub fn run_socket_thread(config: &Config, state: LoadTestState) {
|
||||
let timeout = Duration::from_micros(config.network.poll_timeout_microseconds);
|
||||
let create_conn_interval = 2 ^ config.network.connection_creation_interval;
|
||||
|
||||
|
|
@ -259,11 +241,11 @@ pub fn run_socket_thread(
|
|||
poll.poll(&mut events, Some(timeout))
|
||||
.expect("failed polling");
|
||||
|
||||
for event in events.iter(){
|
||||
for event in events.iter() {
|
||||
let token = event.token();
|
||||
|
||||
if event.is_readable(){
|
||||
if let Some(connection) = connections.get_mut(&token.0){
|
||||
if event.is_readable() {
|
||||
if let Some(connection) = connections.get_mut(&token.0) {
|
||||
if let ConnectionState::WebSocket(_) = connection.stream {
|
||||
let drop_connection = connection.read_responses(&state);
|
||||
|
||||
|
|
@ -276,26 +258,22 @@ pub fn run_socket_thread(
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(connection) = connections.remove(&token.0){
|
||||
if let Some(connection) = connection.advance(config){
|
||||
if let Some(connection) = connections.remove(&token.0) {
|
||||
if let Some(connection) = connection.advance(config) {
|
||||
connections.insert(token.0, connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (k, connection) in connections.iter_mut(){
|
||||
let drop_connection = connection.send_request(
|
||||
config,
|
||||
&state,
|
||||
&mut rng,
|
||||
);
|
||||
for (k, connection) in connections.iter_mut() {
|
||||
let drop_connection = connection.send_request(config, &state, &mut rng);
|
||||
|
||||
if drop_connection {
|
||||
drop_keys.push(*k)
|
||||
}
|
||||
}
|
||||
|
||||
for k in drop_keys.drain(..){
|
||||
for k in drop_keys.drain(..) {
|
||||
connections.remove(&k);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,49 +1,33 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use rand::distributions::WeightedIndex;
|
||||
use rand_distr::Pareto;
|
||||
use rand::prelude::*;
|
||||
use rand_distr::Pareto;
|
||||
|
||||
use crate::common::*;
|
||||
use crate::config::*;
|
||||
|
||||
|
||||
pub fn create_random_request(
|
||||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
peer_id: PeerId
|
||||
peer_id: PeerId,
|
||||
) -> InMessage {
|
||||
let weights = [
|
||||
config.torrents.weight_announce as u32,
|
||||
config.torrents.weight_scrape as u32,
|
||||
config.torrents.weight_scrape as u32,
|
||||
];
|
||||
|
||||
let items = [
|
||||
RequestType::Announce,
|
||||
RequestType::Scrape,
|
||||
];
|
||||
let items = [RequestType::Announce, RequestType::Scrape];
|
||||
|
||||
let dist = WeightedIndex::new(&weights)
|
||||
.expect("random request weighted index");
|
||||
let dist = WeightedIndex::new(&weights).expect("random request weighted index");
|
||||
|
||||
match items[dist.sample(rng)] {
|
||||
RequestType::Announce => create_announce_request(
|
||||
config,
|
||||
state,
|
||||
rng,
|
||||
peer_id
|
||||
),
|
||||
RequestType::Scrape => create_scrape_request(
|
||||
config,
|
||||
state,
|
||||
rng,
|
||||
)
|
||||
RequestType::Announce => create_announce_request(config, state, rng, peer_id),
|
||||
RequestType::Scrape => create_scrape_request(config, state, rng),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[inline]
|
||||
fn create_announce_request(
|
||||
config: &Config,
|
||||
|
|
@ -61,10 +45,8 @@ fn create_announce_request(
|
|||
|
||||
let info_hash_index = select_info_hash_index(config, &state, rng);
|
||||
|
||||
let mut offers = Vec::with_capacity(
|
||||
config.torrents.offers_per_request
|
||||
);
|
||||
|
||||
let mut offers = Vec::with_capacity(config.torrents.offers_per_request);
|
||||
|
||||
for _ in 0..config.torrents.offers_per_request {
|
||||
offers.push(AnnounceRequestOffer {
|
||||
offer_id: OfferId(rng.gen()),
|
||||
|
|
@ -88,13 +70,8 @@ fn create_announce_request(
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
fn create_scrape_request(
|
||||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
) -> InMessage {
|
||||
fn create_scrape_request(config: &Config, state: &LoadTestState, rng: &mut impl Rng) -> InMessage {
|
||||
let mut scrape_hashes = Vec::with_capacity(5);
|
||||
|
||||
for _ in 0..5 {
|
||||
|
|
@ -109,25 +86,15 @@ fn create_scrape_request(
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
fn select_info_hash_index(
|
||||
config: &Config,
|
||||
state: &LoadTestState,
|
||||
rng: &mut impl Rng,
|
||||
) -> usize {
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
fn pareto_usize(
|
||||
rng: &mut impl Rng,
|
||||
pareto: &Arc<Pareto<f64>>,
|
||||
max: usize,
|
||||
) -> usize {
|
||||
fn pareto_usize(rng: &mut impl Rng, pareto: &Arc<Pareto<f64>>, max: usize) -> usize {
|
||||
let p: f64 = pareto.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