Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite of the histogram crate #66

Merged
merged 53 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b1a6472
rewrite of the histogram crate
brayniac Aug 25, 2023
c22d3e7
rustfmt
brayniac Aug 25, 2023
bc6495f
fixup manifest
brayniac Aug 25, 2023
c7af23b
reorder manifest fields
brayniac Aug 25, 2023
9657d5f
add clear for plain basic histogram, doc updates
brayniac Aug 25, 2023
bfc0d02
longer sleep in test
brayniac Aug 25, 2023
e3c308f
make clocksource duration more usable
brayniac Aug 25, 2023
5118a2e
add benchmarks and change minimum interval for sliding window
brayniac Aug 28, 2023
48438a1
simplify percentile logic
brayniac Aug 29, 2023
70a135a
rustfmt
brayniac Aug 29, 2023
460476b
Merge branch 'main' into histogram-sliding
brayniac Aug 29, 2023
d2ad66d
bump version number for clocksource dep
brayniac Aug 29, 2023
83e59b3
return build errors if interval too short or long
brayniac Aug 29, 2023
7474708
cleanup benchmark a bit
brayniac Aug 29, 2023
9208dfa
add a README
brayniac Aug 29, 2023
bb77487
address some review feedback
brayniac Aug 30, 2023
95227ae
add from impls for standard and atomic histograms
brayniac Aug 30, 2023
b160c22
custom deserialize for compact
brayniac Aug 30, 2023
0d3e648
finish custom deserializer
brayniac Aug 30, 2023
7ff598e
add test and fix tick for std sliding window
brayniac Aug 30, 2023
2d2f04f
add merge for basic histograms
brayniac Aug 30, 2023
23c6827
add comment about cutoff power
brayniac Aug 30, 2023
148e081
check the vec lengths on deserialize
brayniac Aug 30, 2023
d2c3ac9
add another test for deserialize
brayniac Aug 30, 2023
c02bc10
dep versions
brayniac Aug 30, 2023
58ceb10
this doesn't actually panic
brayniac Aug 30, 2023
2e2c022
fix
brayniac Aug 30, 2023
35d2fa2
use a macro to reduce duplication
brayniac Aug 31, 2023
b44becd
rustfmt
brayniac Sep 1, 2023
443df0e
reworking this to simplify
brayniac Sep 11, 2023
baf4bbb
use range types and refactor a bit
brayniac Sep 11, 2023
c7740ae
fix
brayniac Sep 11, 2023
3edb6be
changes the semantics for snapshot reporting
brayniac Sep 11, 2023
e0a5201
changes the semantics for snapshot reporting
brayniac Sep 11, 2023
60934e5
fixes
brayniac Sep 11, 2023
fed1172
more doc comments
brayniac Sep 12, 2023
8aac41b
remove compact histogram
brayniac Sep 12, 2023
800af4e
minor cleanup
brayniac Sep 12, 2023
d64b215
fixes from end-to-end testing
brayniac Sep 13, 2023
3779278
Merge branch 'main' into histogram-sliding
brayniac Sep 14, 2023
b6fd2bc
fix typos
brayniac Sep 14, 2023
77b7414
simplify this function
brayniac Sep 14, 2023
d26c309
test index to range too
brayniac Sep 14, 2023
446ce1d
add a parameters type, centralize documentation
brayniac Sep 14, 2023
88114eb
more docs and rustfmt
brayniac Sep 15, 2023
978ceb4
delete old file
brayniac Sep 18, 2023
6f59460
simplify parameters
brayniac Sep 19, 2023
1159534
improve the docs
brayniac Sep 21, 2023
97df76b
dramatically simplify
brayniac Sep 25, 2023
0a9f8e0
add more operations for histogram, better names, better errors
brayniac Sep 25, 2023
809c03d
rework after more feedback and brainstorming
brayniac Sep 26, 2023
77f58c7
fixes
brayniac Sep 26, 2023
5500832
fix benchmarks
brayniac Sep 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion clocksource/src/precise/duration.rs
brayniac marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ impl Duration {
}
}

/// Create a new `Duration` from a whole number of milliseconds.
pub const fn from_millis(millis: u32) -> Self {
Self {
ns: millis as u64 * Self::MILLISECOND.as_nanos()
}
}

/// Create a new `Duration` from a whole number of milliseconds.
///
/// *Note*: this will return an error on overflow.
Expand All @@ -47,10 +54,17 @@ impl Duration {
}
}

/// Create a new `Duration` from a whole number of microseconds.
pub const fn from_micros(micros: u32) -> Self {
Self {
ns: micros as u64 * Self::MICROSECOND.as_nanos()
}
}

/// Create a new `Duration` from a whole number of microseconds.
///
/// *Note*: this will return an error on overflow.
pub const fn from_micros(micros: u64) -> Result<Self, TryFromError> {
pub const fn try_from_micros(micros: u64) -> Result<Self, TryFromError> {
if let Some(ns) = micros.checked_mul(Self::MICROSECOND.as_nanos()) {
Ok(Self { ns })
} else {
Expand Down
2 changes: 1 addition & 1 deletion heatmap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = "https://github.com/pelikan-io/rustcommon"

[dependencies]
clocksource = { version = "0.6.0" }
histogram = { version = "0.7.4", path = "../histogram" }
histogram = { version = "0.7.4" }
parking_lot = "0.12.1"
thiserror = "1.0.34"

Expand Down
23 changes: 11 additions & 12 deletions histogram/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
[package]
name = "histogram"
version = "0.7.4"
version = "0.8.0"
edition = "2021"
authors = ["Brian Martin <brian@pelikan.io>"]
license = "Apache-2.0"
description = "Fast and simple atomic histograms"
homepage = "https://github.com/pelikan-io/rustcommon/histogram"
license = "MIT OR Apache-2.0"
description = "A collection of histogram datastructures"
brayniac marked this conversation as resolved.
Show resolved Hide resolved
homepage = "https://github.com/pelikan-io/rustcommon"
repository = "https://github.com/pelikan-io/rustcommon"

[dependencies]
clocksource = { version = "0.7.0", path = "../clocksource" }
serde = { version = "1.0.144", features = ["derive"], optional = true }
thiserror = "1.0.38"

[dev-dependencies]
criterion = "0.4.0"
itertools = "0.11.0"
thiserror = "1.0.47"

[features]
default = ["serde-serialize"]
serde-serialize = ["serde"]
serde = ["dep:serde"]

[[bench]]
name = "bench"
name = "histogram"
harness = false

[dev-dependencies]
criterion = "0.3"
29 changes: 0 additions & 29 deletions histogram/README.md

This file was deleted.

20 changes: 0 additions & 20 deletions histogram/benches/bench.rs

This file was deleted.

102 changes: 102 additions & 0 deletions histogram/benches/histogram.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
use core::time::Duration;
use criterion::Throughput;
use histogram::Histogram;
use histogram::atomic::Histogram as AtomicHistogram;

// use criterion::BenchmarkId;
use criterion::Criterion;
use criterion::{criterion_group, criterion_main};

fn histogram(c: &mut Criterion) {
let mut histogram = Histogram::new(0,7,64).unwrap();

let mut group = c.benchmark_group("histogram");
group.throughput(Throughput::Elements(1));
group.bench_function("increment/1", |b| b.iter(|| histogram.increment(1)));

histogram.clear();
group.bench_function("increment/max", |b| b.iter(|| histogram.increment(u64::MAX)));

group.finish();
}

fn histogram_atomic(c: &mut Criterion) {
let histogram = AtomicHistogram::new(0,7,64).unwrap();

let mut group = c.benchmark_group("histogram::atomic");
group.throughput(Throughput::Elements(1));
group.bench_function("increment/1", |b| b.iter(|| histogram.increment(1)));

histogram.clear();
group.bench_function("increment/max", |b| b.iter(|| histogram.increment(u64::MAX)));

group.finish();
}

brayniac marked this conversation as resolved.
Show resolved Hide resolved
fn sliding_window(c: &mut Criterion) {
// microsecond resolution

let mut histogram = histogram::sliding_window::Histogram::new(0,7,64, Duration::from_micros(1), 100).unwrap();

let mut group = c.benchmark_group("histogram::sliding_window/microseconds");
group.throughput(Throughput::Elements(1));
group.bench_function("increment/1", |b| b.iter(|| histogram.increment(1)));
group.bench_function("increment/max", |b| b.iter(|| histogram.increment(u64::MAX)));
group.finish();

// millisecond resolution

let mut histogram = histogram::sliding_window::Histogram::new(0,7,64, Duration::from_millis(1), 100).unwrap();

let mut group = c.benchmark_group("histogram::sliding_window/milliseconds");
brayniac marked this conversation as resolved.
Show resolved Hide resolved
group.throughput(Throughput::Elements(1));
group.bench_function("increment/1", |b| b.iter(|| histogram.increment(1)));
group.bench_function("increment/max", |b| b.iter(|| histogram.increment(u64::MAX)));
group.finish();

// second resolution

let mut histogram = histogram::sliding_window::Histogram::new(0,7,64, Duration::from_secs(1), 100).unwrap();

let mut group = c.benchmark_group("histogram::sliding_window/seconds");
group.throughput(Throughput::Elements(1));
group.bench_function("increment/1", |b| b.iter(|| histogram.increment(1)));
group.bench_function("increment/max", |b| b.iter(|| histogram.increment(u64::MAX)));
group.finish();
}

fn sliding_window_atomic(c: &mut Criterion) {
// // microsecond resolution

// let histogram = histogram::sliding_window::atomic::Histogram::new(0,7,64, Duration::from_micros(1), 100).unwrap();

// let mut group = c.benchmark_group("histogram::sliding_window::atomic/microseconds");
// group.throughput(Throughput::Elements(1));
// group.bench_function("increment/1", |b| b.iter(|| histogram.increment(1)));
// group.bench_function("increment/max", |b| b.iter(|| histogram.increment(u64::MAX)));
// group.finish();

// millisecond resolution

let histogram = histogram::sliding_window::atomic::Histogram::new(0,7,64, Duration::from_millis(1), 100).unwrap();

let mut group = c.benchmark_group("histogram::sliding_window::atomic/milliseconds");
group.throughput(Throughput::Elements(1));
group.bench_function("increment/1", |b| b.iter(|| histogram.increment(1)));
group.bench_function("increment/max", |b| b.iter(|| histogram.increment(u64::MAX)));
group.finish();

// second resolution

let histogram = histogram::sliding_window::atomic::Histogram::new(0,7,64, Duration::from_secs(1), 100).unwrap();

let mut group = c.benchmark_group("histogram::sliding_window::atomic/seconds");
group.throughput(Throughput::Elements(1));
group.bench_function("increment/1", |b| b.iter(|| histogram.increment(1)));
group.bench_function("increment/max", |b| b.iter(|| histogram.increment(u64::MAX)));
group.finish();
}


criterion_group!(benches, histogram, histogram_atomic, sliding_window, sliding_window_atomic);
criterion_main!(benches);
Loading
Loading