Skip to content

Commit

Permalink
Compute all statistics without using the log
Browse files Browse the repository at this point in the history
  • Loading branch information
pkolaczk committed Aug 10, 2024
1 parent 2d69bcb commit e2ff3d3
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 299 deletions.
24 changes: 19 additions & 5 deletions src/latency.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::autocorrelation::EffectiveSampleSizeEstimator;
use crate::histogram::SerializableHistogram;
use crate::percentiles::Percentiles;
use crate::stats::Mean;
use crate::timeseries::TimeSeriesStats;
use hdrhistogram::Histogram;
use serde::{Deserialize, Serialize};
use std::time::Duration;
Expand All @@ -18,15 +18,15 @@ pub struct LatencyDistribution {
#[derive(Clone, Debug)]
pub struct LatencyDistributionRecorder {
histogram_ns: Histogram<u64>,
ess_estimator: EffectiveSampleSizeEstimator,
ess_estimator: TimeSeriesStats,
}

impl LatencyDistributionRecorder {
pub fn record(&mut self, time: Duration) {
self.histogram_ns
.record(time.as_nanos().clamp(1, u64::MAX as u128) as u64)
.unwrap();
self.ess_estimator.record(time.as_secs_f64());
self.ess_estimator.record(time.as_secs_f64(), 1.0);
}

pub fn add(&mut self, other: &LatencyDistributionRecorder) {
Expand All @@ -41,19 +41,33 @@ impl LatencyDistributionRecorder {

pub fn distribution(&self) -> LatencyDistribution {
LatencyDistribution {
mean: Mean::from(&self.histogram_ns, 1e-6, 1),
mean: self.mean(1),
percentiles: Percentiles::compute(&self.histogram_ns, 1e-6),
histogram: SerializableHistogram(self.histogram_ns.clone()),
}
}

pub fn distribution_with_errors(&self) -> LatencyDistribution {
let ess = self.ess_estimator.effective_sample_size();
LatencyDistribution {
mean: Mean::from(&self.histogram_ns, 1e-6, ess),
mean: self.mean(ess),
percentiles: Percentiles::compute_with_errors(&self.histogram_ns, 1e-6, ess),
histogram: SerializableHistogram(self.histogram_ns.clone()),
}
}

fn mean(&self, effective_n: u64) -> Mean {
let scale = 1e-6;
Mean {
n: effective_n,
value: self.histogram_ns.mean() * scale,
std_err: if effective_n > 1 {
Some(self.histogram_ns.stdev() * scale / (effective_n as f64 - 1.0).sqrt())
} else {
None
},
}
}
}

impl Default for LatencyDistributionRecorder {
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use crate::stats::{BenchmarkCmp, BenchmarkStats, Recorder};
use crate::table::{Alignment, Table};
use crate::workload::{FnRef, Program, Workload, WorkloadStats, LOAD_FN};

mod autocorrelation;
mod chunks;
mod config;
mod context;
Expand All @@ -54,6 +53,8 @@ mod progress;
mod report;
mod stats;
mod table;
mod throughput;
mod timeseries;
mod workload;

const VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down
Loading

0 comments on commit e2ff3d3

Please sign in to comment.