aquatic http load test: track and display bandwidth

This commit is contained in:
Joakim Frostegård 2020-07-20 18:02:16 +02:00
parent 45940a05a9
commit 1c6f22db85
3 changed files with 27 additions and 13 deletions

View file

@ -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,
}
@ -43,13 +45,3 @@ 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,
}

View file

@ -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::<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);

View file

@ -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(())