Skip to content

Commit

Permalink
update metriken to replace heatmaps (iopsystems#52)
Browse files Browse the repository at this point in the history
Updates metriken library to replace heatmaps with histograms which
have better runtime performance characteristics and lower memory
footprint.

---------

Co-authored-by: Mihir Nanavati <code@mihirnanavati.com>
  • Loading branch information
brayniac and mihirn authored Oct 17, 2023
1 parent 66a15f2 commit 55c0f3b
Show file tree
Hide file tree
Showing 16 changed files with 697 additions and 627 deletions.
434 changes: 214 additions & 220 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ repository = { workspace = true }
license = { workspace = true }

[workspace.dependencies]
histogram = "0.7.4"
serde = "1.0.185"
histogram = "0.8.0"
serde = { version = "1.0.185", features = ["derive"] }

[dependencies]
ahash = "0.8.3"
Expand All @@ -35,9 +35,10 @@ hyper = { version = "1.0.0-rc.4", features = ["http1", "http2", "client"]}
histogram = { workspace = true }
humantime = "2.1.0"
momento = "0.31.0"
metriken = "0.2.3"
metriken = "0.3.0"
mio = "0.8.8"
net = { git = "https://github.com/pelikan-io/pelikan" }
once_cell = "1.18.0"
paste = "1.0.14"
protocol-memcache = { git = "https://github.com/pelikan-io/pelikan" }
protocol-ping = { git = "https://github.com/pelikan-io/pelikan" }
Expand All @@ -46,7 +47,7 @@ rand_distr = "0.4.3"
rand_xoshiro = "0.6.0"
ratelimit = "0.7.0"
redis = { version = "0.22.3", features = ["tokio-comp"] }
ringlog = "0.2.0"
ringlog = "0.3.0"
rpcperf-dataspec = { path = "lib/dataspec" }
serde = { workspace = true }
serde_json = "1.0.105"
Expand All @@ -56,8 +57,8 @@ slab = "0.4.9"
tokio = { version = "1.32.0", features = ["full"] }
tokio-boring = "2.1.5"
toml = "0.7.6"
zipf = "7.0.1"
warp = "0.3.6"
zipf = "7.0.1"

[workspace]
members = [
Expand Down
46 changes: 20 additions & 26 deletions lib/dataspec/src/histogram.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use thiserror::Error;

use histogram::Histogram as _Histogram;
use histogram::Snapshot;

/// This histogram is a sparse, columnar representation of the regular
/// Histogram. It is significantly smaller than a regular Histogram
Expand All @@ -14,13 +14,12 @@ use histogram::Histogram as _Histogram;
pub struct Histogram {
/// parameters representing the resolution and the range of
/// the histogram tracking request latencies
pub m: u32,
pub r: u32,
pub n: u32,
pub grouping_power: u8,
pub max_value_power: u8,
/// indices for the non-zero buckets in the histogram
pub index: Vec<usize>,
/// histogram bucket counts corresponding to the indices
pub count: Vec<u32>,
pub count: Vec<u64>,
}

/// Errors returned for operations on histograms.
Expand All @@ -32,7 +31,7 @@ pub enum Error {
}

impl Histogram {
fn add_bucket(&mut self, idx: usize, n: u32) {
fn add_bucket(&mut self, idx: usize, n: u64) {
self.index.push(idx);
self.count.push(n);
}
Expand All @@ -43,14 +42,13 @@ impl Histogram {
/// Buckets which have values in both histograms are allowed to wrap.
#[allow(clippy::comparison_chain)]
pub fn merge(&self, h: &Histogram) -> Result<Histogram, Error> {
if self.m != h.m || self.r != h.r || self.n != h.n {
if self.grouping_power != h.grouping_power || self.max_value_power != h.max_value_power {
return Err(Error::MismatchedParams);
}

let mut histogram = Histogram {
m: self.m,
r: self.r,
n: self.n,
grouping_power: self.grouping_power,
max_value_power: self.max_value_power,
index: Vec::new(),
count: Vec::new(),
};
Expand Down Expand Up @@ -89,12 +87,12 @@ impl Histogram {
}
}

impl From<&_Histogram> for Histogram {
fn from(histogram: &_Histogram) -> Self {
impl From<&Snapshot> for Histogram {
fn from(snapshot: &Snapshot) -> Self {
let mut index = Vec::new();
let mut count = Vec::new();

for (i, bucket) in histogram
for (i, bucket) in snapshot
.into_iter()
.enumerate()
.filter(|(_i, bucket)| bucket.count() != 0)
Expand All @@ -103,11 +101,10 @@ impl From<&_Histogram> for Histogram {
count.push(bucket.count());
}

let p = histogram.parameters();
let config = snapshot.config();
Self {
m: p.0,
r: p.1,
n: p.2,
grouping_power: config.grouping_power(),
max_value_power: config.max_value_power(),
index,
count,
}
Expand All @@ -121,25 +118,22 @@ mod tests {
#[test]
fn merge() {
let h1 = Histogram {
m: 0,
r: 7,
n: 32,
grouping_power: 8,
max_value_power: 32,
index: vec![1, 3, 5],
count: vec![6, 12, 7],
};

let h2 = Histogram {
m: 0,
r: 7,
n: 32,
grouping_power: 8,
max_value_power: 32,
index: Vec::new(),
count: Vec::new(),
};

let h3 = Histogram {
m: 0,
r: 7,
n: 32,
grouping_power: 8,
max_value_power: 32,
index: vec![2, 3, 4, 11],
count: vec![5, 7, 3, 15],
};
Expand Down
2 changes: 1 addition & 1 deletion lib/dataspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct ClientStats {
pub connections: Connections,
pub requests: Requests,
pub responses: Responses,
pub request_latency: Histogram,
pub response_latency: Histogram,
}

#[derive(Serialize, Deserialize)]
Expand Down
Loading

0 comments on commit 55c0f3b

Please sign in to comment.