mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 10:45:30 +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,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue