Skip to content

Commit

Permalink
metrics: add minor fixes to LFHistogram refactor
Browse files Browse the repository at this point in the history
Implement median, fix percentiles.
Fix Snapshot visibility.
  • Loading branch information
QuerthDP committed Jan 5, 2025
1 parent 4ffb454 commit d7b32d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion scylla/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,4 @@ pub use transport::retry_policy;
pub use transport::speculative_execution;

#[cfg(feature = "metrics")]
pub use transport::metrics::{Metrics, MetricsError};
pub use transport::metrics::{Metrics, MetricsError, Snapshot};
23 changes: 9 additions & 14 deletions scylla/src/transport/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,20 @@ impl Metrics {

let (min, max) = Self::minmax(h.clone())?;

let percentile_args = [0.75, 0.9, 0.95, 0.99, 0.999];
let percentile_args = [50.0, 75.0, 90.0, 95.0, 99.0, 99.9];
let percentiles = Self::percentiles(&h, &percentile_args)?;

Ok(Snapshot {
min,
max,
mean: Self::mean(h.clone())?,
stddev: Self::stddev(h.clone())?,
median: Self::median(h)?,
percentile_75: percentiles[0],
percentile_90: percentiles[1],
percentile_95: percentiles[2],
percentile_99: percentiles[3],
percentile_99_9: percentiles[4],
stddev: Self::stddev(h)?,
median: percentiles[0],
percentile_75: percentiles[1],
percentile_90: percentiles[2],
percentile_95: percentiles[3],
percentile_99: percentiles[4],
percentile_99_9: percentiles[5],
})
}

Expand Down Expand Up @@ -181,11 +181,6 @@ impl Metrics {
}
}

fn median(h: Histogram) -> Result<u64, MetricsError> {
// TODO: get the real median by iterating through the buckets.
Ok(0)
}

fn percentiles(h: &Histogram, percentiles: &[f64]) -> Result<Vec<u64>, MetricsError> {
let res = h.percentiles(percentiles)?;
if let Some(ps) = res {
Expand Down Expand Up @@ -218,7 +213,7 @@ impl Metrics {
fn minmax(h: Histogram) -> Result<(u64, u64), MetricsError> {
let mut min = u64::MAX;
let mut max = 0;
for bucket in h.clone().into_iter() {
for bucket in h.into_iter() {
if bucket.count() == 0 {
continue;
}
Expand Down

0 comments on commit d7b32d0

Please sign in to comment.