From 1c6f22db8517fd8d866a80bc9563e0c874ce5b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Mon, 20 Jul 2020 18:02:16 +0200 Subject: [PATCH] aquatic http load test: track and display bandwidth --- aquatic_http_load_test/src/common.rs | 12 ++---------- aquatic_http_load_test/src/main.rs | 11 +++++++++++ aquatic_http_load_test/src/network.rs | 17 ++++++++++++++--- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/aquatic_http_load_test/src/common.rs b/aquatic_http_load_test/src/common.rs index d6a7b72..2776255 100644 --- a/aquatic_http_load_test/src/common.rs +++ b/aquatic_http_load_test/src/common.rs @@ -27,6 +27,8 @@ pub struct Statistics { pub responses_announce: AtomicUsize, pub responses_scrape: AtomicUsize, pub responses_failure: AtomicUsize, + pub bytes_sent: AtomicUsize, + pub bytes_received: AtomicUsize, } @@ -42,14 +44,4 @@ pub struct LoadTestState { pub enum RequestType { Announce, Scrape -} - - -#[derive(Default)] -pub struct SocketWorkerLocalStatistics { - pub requests: usize, - pub response_peers: usize, - pub responses_announce: usize, - pub responses_scrape: usize, - pub responses_failure: usize, } \ No newline at end of file diff --git a/aquatic_http_load_test/src/main.rs b/aquatic_http_load_test/src/main.rs index d2528d7..59348a6 100644 --- a/aquatic_http_load_test/src/main.rs +++ b/aquatic_http_load_test/src/main.rs @@ -19,6 +19,10 @@ use network::*; static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; +/// Multiply bytes during a second with this to get Mbit/s +const MBITS_FACTOR: f64 = 1.0 / ((1024.0 * 1024.0) / 8.0); + + pub fn main(){ aquatic_cli_helpers::run_app_with_cli_and_config::( "aquatic: udp bittorrent tracker: load tester", @@ -103,6 +107,11 @@ fn monitor_statistics( let responses_failure_per_second = statistics.responses_failure .fetch_and(0, Ordering::SeqCst) as f64 / interval_f64; + let bytes_sent_per_second = statistics.bytes_sent + .fetch_and(0, Ordering::SeqCst) as f64 / interval_f64; + let bytes_received_per_second = statistics.bytes_received + .fetch_and(0, Ordering::SeqCst) as f64 / interval_f64; + let responses_announce_per_second = responses_announce / interval_f64; let responses_per_second = @@ -119,6 +128,8 @@ fn monitor_statistics( println!(" - Scrape responses: {:.2}", responses_scrape_per_second); println!(" - Failure responses: {:.2}", responses_failure_per_second); println!("Peers per announce response: {:.2}", response_peers / responses_announce); + println!("Bandwidth out: {:.2}Mbit/s", bytes_sent_per_second * MBITS_FACTOR); + println!("Bandwidth in: {:.2}Mbit/s", bytes_received_per_second * MBITS_FACTOR); let time_elapsed = start_time.elapsed(); let duration = Duration::from_secs(config.duration as u64); diff --git a/aquatic_http_load_test/src/network.rs b/aquatic_http_load_test/src/network.rs index a4c2f4b..d5d23b8 100644 --- a/aquatic_http_load_test/src/network.rs +++ b/aquatic_http_load_test/src/network.rs @@ -78,6 +78,9 @@ impl Connection { } }; + state.statistics.bytes_received + .fetch_add(self.bytes_read, Ordering::SeqCst); + let res_response = Response::from_bytes( &self.read_buffer[..self.bytes_read] ); @@ -123,7 +126,7 @@ impl Connection { rng ); - match self.send_request_inner(&request.as_bytes()){ + match self.send_request_inner(state, &request.as_bytes()){ Ok(_) => { state.statistics.requests.fetch_add(1, Ordering::SeqCst); }, @@ -135,8 +138,16 @@ impl Connection { self.can_send_initial = false; } - fn send_request_inner(&mut self, request: &[u8]) -> ::std::io::Result<()> { - self.stream.write(request)?; + fn send_request_inner( + &mut self, + state: &LoadTestState, + request: &[u8] + ) -> ::std::io::Result<()> { + let bytes_sent = self.stream.write(request)?; + + state.statistics.bytes_sent + .fetch_add(bytes_sent, Ordering::SeqCst); + self.stream.flush()?; Ok(())