ws load test: enable measuring once all connections are open

This commit is contained in:
Joakim Frostegård 2023-01-26 02:35:43 +01:00
parent 61ae6dd7e7
commit 373e8277e0
2 changed files with 46 additions and 18 deletions

View file

@ -15,6 +15,7 @@ pub struct Config {
pub num_connections_per_worker: usize, pub num_connections_per_worker: usize,
pub connection_creation_interval_ms: u64, pub connection_creation_interval_ms: u64,
pub duration: usize, pub duration: usize,
pub measure_after_max_connections_reached: bool,
pub torrents: TorrentConfig, pub torrents: TorrentConfig,
pub cpu_pinning: CpuPinningConfigDesc, pub cpu_pinning: CpuPinningConfigDesc,
} }
@ -34,6 +35,7 @@ impl Default for Config {
num_connections_per_worker: 16, num_connections_per_worker: 16,
connection_creation_interval_ms: 10, connection_creation_interval_ms: 10,
duration: 0, duration: 0,
measure_after_max_connections_reached: true,
torrents: TorrentConfig::default(), torrents: TorrentConfig::default(),
cpu_pinning: Default::default(), cpu_pinning: Default::default(),
} }

View file

@ -118,6 +118,7 @@ fn create_tls_config() -> anyhow::Result<Arc<rustls::ClientConfig>> {
fn monitor_statistics(state: LoadTestState, config: &Config) { fn monitor_statistics(state: LoadTestState, config: &Config) {
let start_time = Instant::now(); let start_time = Instant::now();
let mut time_max_connections_reached = None;
let mut report_avg_response_vec: Vec<f64> = Vec::new(); let mut report_avg_response_vec: Vec<f64> = Vec::new();
let interval = 5; let interval = 5;
@ -155,7 +156,15 @@ fn monitor_statistics(state: LoadTestState, config: &Config) {
+ responses_scrape_per_second + responses_scrape_per_second
+ responses_error_per_second; + responses_error_per_second;
report_avg_response_vec.push(responses_per_second); if !config.measure_after_max_connections_reached || time_max_connections_reached.is_some() {
report_avg_response_vec.push(responses_per_second);
} else if connections >= config.num_workers * config.num_connections_per_worker {
time_max_connections_reached = Some(Instant::now());
println!();
println!("Max connections reached");
println!();
}
println!(); println!();
println!("Requests out: {:.2}/second", requests_per_second); println!("Requests out: {:.2}/second", requests_per_second);
@ -170,26 +179,43 @@ fn monitor_statistics(state: LoadTestState, config: &Config) {
println!(" - Error responses: {:.2}", responses_error_per_second); println!(" - Error responses: {:.2}", responses_error_per_second);
println!("Active connections: {}", connections); println!("Active connections: {}", connections);
let time_elapsed = start_time.elapsed(); if config.measure_after_max_connections_reached {
let duration = Duration::from_secs(config.duration as u64); if let Some(start) = time_max_connections_reached {
let time_elapsed = start.elapsed();
if config.duration != 0 && time_elapsed >= duration { if config.duration != 0
let report_len = report_avg_response_vec.len() as f64; && time_elapsed >= Duration::from_secs(config.duration as u64)
let report_sum: f64 = report_avg_response_vec.into_iter().sum(); {
let report_avg: f64 = report_sum / report_len; report(config, report_avg_response_vec, time_elapsed);
println!( break;
concat!( }
"\n# aquatic load test report\n\n", }
"Test ran for {} seconds.\n", } else {
"Average responses per second: {:.2}\n\nConfig: {:#?}\n" let time_elapsed = start_time.elapsed();
),
time_elapsed.as_secs(),
report_avg,
config
);
break; if config.duration != 0 && time_elapsed >= Duration::from_secs(config.duration as u64) {
report(config, report_avg_response_vec, time_elapsed);
break;
}
} }
} }
} }
fn report(config: &Config, report_avg_response_vec: Vec<f64>, time_elapsed: Duration) {
let report_len = report_avg_response_vec.len() as f64;
let report_sum: f64 = report_avg_response_vec.into_iter().sum();
let report_avg: f64 = report_sum / report_len;
println!(
concat!(
"\n# aquatic load test report\n\n",
"Test ran for {} seconds.\n",
"Average responses per second: {:.2}\n\nConfig: {:#?}\n"
),
time_elapsed.as_secs(),
report_avg,
config
);
}