Skip to content

Commit

Permalink
fix: update manager for all metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed Jun 13, 2023
1 parent 833657f commit 353278e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 52 deletions.
37 changes: 8 additions & 29 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::collections::HashSet;
use std::io::BufWriter;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time;
use tdigest::TDigest;

use crate::metrics::{
self, GooseErrorMetricAggregate, GooseErrorMetrics, GooseRequestMetricAggregate,
Expand Down Expand Up @@ -76,18 +75,9 @@ fn merge_transactions_from_worker(
// Make a mutable copy where we can merge things
let mut merged_transaction = parent_transaction.clone();
// Iterate over user times, and merge into global time
merged_transaction.times =
metrics::merge_times(merged_transaction.times, user_transaction.times.clone());
// Increment total transaction time counter.
merged_transaction.total_time += &user_transaction.total_time;
// Increment count of how many transaction counters we've seen.
merged_transaction.counter += &user_transaction.counter;
// If user had new fastest transaction time, update global fastest transaction time.
merged_transaction.min_time =
metrics::update_min_time(merged_transaction.min_time, user_transaction.min_time);
// If user had new slowest transaction time, update global slowest transaction time.
merged_transaction.max_time =
metrics::update_max_time(merged_transaction.max_time, user_transaction.max_time);
merged_transaction.times = merged_transaction
.times
.merge(user_transaction.times.clone());
// Increment total success counter.
merged_transaction.success_count += &user_transaction.success_count;
// Increment total fail counter.
Expand All @@ -103,18 +93,7 @@ fn merge_scenarios_from_worker(
// Make a mutable copy where we can merge things
let mut merged_scenario = parent_scenario.clone();
// Iterate over user times, and merge into global time
merged_scenario.times =
metrics::merge_times(merged_scenario.times, user_scenario.times.clone());
// Increment total scenario time counter.
merged_scenario.total_time += &user_scenario.total_time;
// Increment count of how many scenario counters we've seen.
merged_scenario.counter += &user_scenario.counter;
// If user had new fastest scenario time, update global fastest scenario time.
merged_scenario.min_time =
metrics::update_min_time(merged_scenario.min_time, user_scenario.min_time);
// If user had new slowest scenario time, update global slowest scenario time.
merged_scenario.max_time =
metrics::update_max_time(merged_scenario.max_time, user_scenario.max_time);
merged_scenario.times = merged_scenario.times.merge(user_scenario.times.clone());
merged_scenario
}

Expand All @@ -127,10 +106,10 @@ fn merge_requests_from_worker(
// Make a mutable copy where we can merge things
let mut merged_request = parent_request.clone();
// Iterate over user response times, and merge into global response time
merged_request.raw_data.histogram = TDigest::merge_digests(vec![
merged_request.raw_data.histogram,
user_request.raw_data.histogram.clone(),
]);
merged_request.raw_data.times = merged_request
.raw_data
.times
.merge(user_request.raw_data.times.clone());
// Increment total success counter.
merged_request.success_count += &user_request.success_count;
// Increment total fail counter.
Expand Down
45 changes: 22 additions & 23 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,24 +547,23 @@ impl Digest {
self.digest = self.digest.merge_sorted(vec![time_elapsed as f64]);
}

pub(crate) fn total_time(&self) -> usize {
pub fn total_time(&self) -> usize {
self.digest.sum() as usize
}
pub fn count(&self) -> usize {
self.digest.count() as usize
}
pub(crate) fn min(&self) -> usize {
pub fn min(&self) -> usize {
self.digest.min() as usize
}
pub(crate) fn max(&self) -> usize {
pub fn max(&self) -> usize {
self.digest.max() as usize
}
pub(crate) fn mean(&self) -> f32 {
pub fn mean(&self) -> f32 {
self.digest.mean() as f32
}
// TODO use f64
pub(crate) fn quantile(&self, q: f64) -> usize {
self.digest.estimate_quantile(q) as usize
pub fn quantile(&self, q: f64) -> f64 {
self.digest.estimate_quantile(q)
}
}

Expand Down Expand Up @@ -1385,7 +1384,7 @@ impl GooseMetrics {
average,
format_number(transaction.times.min()),
format_number(transaction.times.max()),
format_number(transaction.times.quantile(0.5)),
format_number(transaction.times.quantile(0.5) as usize),
avg_precision = average_precision,
)?;
}
Expand All @@ -1411,7 +1410,7 @@ impl GooseMetrics {
average,
format_number(aggregate_min_transaction_time),
format_number(aggregate_max_transaction_time),
format_number(aggregate_transaction_times.quantile(0.5)),
format_number(aggregate_transaction_times.quantile(0.5) as usize),
avg_precision = average_precision,
)?;
}
Expand Down Expand Up @@ -1550,7 +1549,7 @@ impl GooseMetrics {
average,
format_number(scenario.times.min()),
format_number(scenario.times.max()),
format_number(scenario.times.quantile(0.5)),
format_number(scenario.times.quantile(0.5) as usize),
avg_precision = average_precision,
)?;
}
Expand All @@ -1572,7 +1571,7 @@ impl GooseMetrics {
average,
format_number(aggregate_min_scenario_time),
format_number(aggregate_max_scenario_time),
format_number(aggregate_scenario_times.quantile(0.5)),
format_number(aggregate_scenario_times.quantile(0.5) as usize),
avg_precision = average_precision,
)?;
}
Expand Down Expand Up @@ -1642,7 +1641,7 @@ impl GooseMetrics {
raw_average,
format_number(request.raw_data.times.min()),
format_number(request.raw_data.times.max()),
format_number(request.raw_data.times.quantile(0.5)),
format_number(request.raw_data.times.quantile(0.5) as usize),
raw_avg_precision = raw_average_precision,
)?;
}
Expand All @@ -1666,7 +1665,7 @@ impl GooseMetrics {
raw_average,
format_number(aggregate_raw_min_time),
format_number(aggregate_raw_max_time),
format_number(aggregate_raw_times.quantile(0.5)),
format_number(aggregate_raw_times.quantile(0.5) as usize),
avg_precision = raw_average_precision,
)?;
}
Expand Down Expand Up @@ -1736,7 +1735,7 @@ impl GooseMetrics {
co_average,
standard_deviation,
format_number(co_maximum),
format_number(co_data.times.quantile(0.5)),
format_number(co_data.times.quantile(0.5) as usize),
co_avg_precision = co_average_precision,
sd_precision = standard_deviation_precision,
)?;
Expand Down Expand Up @@ -1775,7 +1774,7 @@ impl GooseMetrics {
co_average,
standard_deviation,
format_number(aggregate_co_max_time),
format_number(aggregate_co_times.quantile(0.5)),
format_number(aggregate_co_times.quantile(0.5) as usize),
avg_precision = co_average_precision,
sd_precision = standard_deviation_precision,
)?;
Expand Down Expand Up @@ -3307,7 +3306,7 @@ pub(crate) fn update_max_time(mut global_max: usize, max: usize) -> usize {

/// Get the response time that a certain number of percent of the requests finished within.
pub(crate) fn calculate_response_time_percentile(response_times: &Digest, q: f64) -> String {
format_number(response_times.quantile(q))
format_number(response_times.quantile(q) as usize)
}

/// Helper to count and aggregate seen status codes.
Expand Down Expand Up @@ -3383,7 +3382,7 @@ mod test {
local_response_times.record_time(2);
local_response_times.record_time(2);
global_response_times = global_response_times.merge(local_response_times.clone());
assert_eq!(global_response_times.quantile(0.5), 2);
assert_eq!(global_response_times.quantile(0.5) as usize, 2);
}

#[test]
Expand Down Expand Up @@ -3587,7 +3586,7 @@ mod test {
// Tracking another response time updates all related fields.
request.record_time(10, false);
// We've seen [1ms, 10ms, 10ms] the median should be 10ms
assert_eq!(request.raw_data.times.quantile(0.5), 10);
assert_eq!(request.raw_data.times.quantile(0.5) as usize, 10);
// Minimum doesn't change.
assert_eq!(request.raw_data.times.min(), 1);
// Maximum doesn't change.
Expand All @@ -3600,7 +3599,7 @@ mod test {
// Tracking another response time updates all related fields.
request.record_time(101, false);
// We've seen [1ms, 10ms, 10ms, 101ms] the median should be 10ms
assert_eq!(request.raw_data.times.quantile(0.5), 10);
assert_eq!(request.raw_data.times.quantile(0.5) as usize, 10);
// Minimum doesn't change.
assert_eq!(request.raw_data.times.min(), 1);
// Maximum increases to actual maximum, not rounded maximum.
Expand All @@ -3613,7 +3612,7 @@ mod test {
// Tracking another response time updates all related fields.
request.record_time(102, false);
// We've seen [1ms, 10ms, 10ms, 101ms, 102ms] the 75th should be 102ms
assert_eq!(request.raw_data.times.quantile(0.75), 102);
assert_eq!(request.raw_data.times.quantile(0.75) as usize, 102);
// Minimum doesn't change.
assert_eq!(request.raw_data.times.min(), 1);
// Maximum increases to actual maximum, not rounded maximum.
Expand All @@ -3626,7 +3625,7 @@ mod test {
// Tracking another response time updates all related fields.
request.record_time(155, false);
// We've seen [1ms, 10ms, 10ms, 101ms, 102ms, 155ms] the 75th should be 102ms
assert_eq!(request.raw_data.times.quantile(0.75), 102);
assert_eq!(request.raw_data.times.quantile(0.75) as usize, 102);
// Minimum doesn't change.
assert_eq!(request.raw_data.times.min(), 1);
// Maximum increases to actual maximum, not rounded maximum.
Expand All @@ -3639,7 +3638,7 @@ mod test {
// Tracking another response time updates all related fields.
request.record_time(2345, false);
// We've seen [1ms, 10ms, 10ms, 101ms, 102ms, 155ms, 2345ms] the 75th should be 102ms
assert_eq!(request.raw_data.times.quantile(0.75), 102);
assert_eq!(request.raw_data.times.quantile(0.75) as usize, 102);
// Minimum doesn't change.
assert_eq!(request.raw_data.times.min(), 1);
// Maximum increases to actual maximum, not rounded maximum.
Expand All @@ -3652,7 +3651,7 @@ mod test {
// Tracking another response time updates all related fields.
request.record_time(987654321, false);
// We've seen [1ms, 10ms, 10ms, 101ms, 102ms, 155ms, 2345ms, 988764321ms] the 75th should be 102ms
assert_eq!(request.raw_data.times.quantile(0.75), 155);
assert_eq!(request.raw_data.times.quantile(0.75) as usize, 155);
// Minimum doesn't change.
assert_eq!(request.raw_data.times.min(), 1);
// Maximum increases to actual maximum, not rounded maximum.
Expand Down

0 comments on commit 353278e

Please sign in to comment.