Skip to content

Commit

Permalink
Truncated mean statistic added
Browse files Browse the repository at this point in the history
  • Loading branch information
xnuter committed Dec 9, 2020
1 parent e3bfd2e commit 745f109
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
18 changes: 13 additions & 5 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ impl BenchRunMetrics {
self.summary.entry(stats.status).or_insert(0).add_assign(1);
}

pub fn truncated_mean(&self, threshold: f64) -> u64 {
let histogram = &self.success_latency;
pub fn truncated_mean(histogram: &Histogram, threshold: f64) -> u64 {
let lowest = histogram.percentile(threshold).unwrap_or_default() as i64;
let highest = histogram.percentile(100. - threshold).unwrap_or_default() as i64;
let mut ignored_count = 0;
Expand Down Expand Up @@ -162,9 +161,18 @@ impl BenchRunReport {
("Max".to_string(), latency.maximum().unwrap_or_default()),
("Mean".to_string(), latency.mean().unwrap_or_default()),
("StdDev".to_string(), latency.stddev().unwrap_or_default()),
("tm95".to_string(), metrics.truncated_mean(5.0)),
("tm99".to_string(), metrics.truncated_mean(1.0)),
("tm99.9".to_string(), metrics.truncated_mean(0.1)),
(
"tm95".to_string(),
BenchRunMetrics::truncated_mean(&latency, 5.0),
),
(
"tm99".to_string(),
BenchRunMetrics::truncated_mean(&latency, 1.0),
),
(
"tm99.9".to_string(),
BenchRunMetrics::truncated_mean(&latency, 0.1),
),
]
}
}
Expand Down
35 changes: 16 additions & 19 deletions src/prometheus_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,6 @@ impl PrometheusReporter {
"Bytes received/sent",
bench_run_metrics.total_bytes as i64,
);
PrometheusReporter::register_gauge(
&registry,
"tm95",
"Truncated mean, 95%",
bench_run_metrics.truncated_mean(1.) as i64,
);
PrometheusReporter::register_gauge(
&registry,
"tm99",
"Truncated mean, 99%",
bench_run_metrics.truncated_mean(1.) as i64,
);
PrometheusReporter::register_gauge(
&registry,
"tm99_9",
"Truncated mean, 99.9%",
bench_run_metrics.truncated_mean(0.1) as i64,
);

PrometheusReporter::register_codes(
&registry,
Expand Down Expand Up @@ -228,6 +210,18 @@ impl PrometheusReporter {
("max".to_string(), histogram.maximum().unwrap_or_default()),
("mean".to_string(), histogram.mean().unwrap_or_default()),
("stddev".to_string(), histogram.stddev().unwrap_or_default()),
(
"tm95".to_string(),
BenchRunMetrics::truncated_mean(&histogram, 5.0),
),
(
"tm99".to_string(),
BenchRunMetrics::truncated_mean(&histogram, 1.0),
),
(
"tm99_9".to_string(),
BenchRunMetrics::truncated_mean(&histogram, 0.1),
),
];
for (label, value) in percentiles {
PrometheusReporter::register_gauge(
Expand Down Expand Up @@ -299,7 +293,7 @@ mod test {

let metrics = registry.gather();

assert_eq!(10, metrics.len());
assert_eq!(13, metrics.len());
assert_eq!("latency", metrics[0].get_name());
assert_eq!("Latency of requests", metrics[0].get_help());
assert_eq!(MetricType::HISTOGRAM, metrics[0].get_field_type());
Expand All @@ -324,6 +318,9 @@ mod test {
"latency_max",
"latency_mean",
"latency_stddev",
"latency_tm95",
"latency_tm99",
"latency_tm99_9",
];

precalculated.sort();
Expand Down

0 comments on commit 745f109

Please sign in to comment.