Expand description
Fixed-bucket latency histogram with lock-free inserts + a global
registry keyed by (fn, path) tag for emit_timing integration.
Records microsecond latencies into log-scale buckets (powers of 2). 30 buckets covers 1µs to ~1 hour, enough for our actual workload (S3 GET 10-100ms, Metal decode 1-2s, daemon RPC <µs to ms). p50/p90/p99/p99.9 derived via bucket-boundary interpolation.
§Why fixed buckets vs HDR or T-digest
- HDR (hdrhistogram crate): more accurate but heavy dep and each instance is ~100KB. We want one histogram per (fn, path) tag, easily 20+ tags → 2MB+ per daemon. Overkill for alpha.
- T-digest: better accuracy at the tails but requires a merge operation that’s not lock-free.
- Fixed log-scale buckets: cheap (240 bytes per histogram), lock-free, perfect-enough percentile accuracy for our alpha “is the tail blowing up?” question.
Each bucket boundary = 2^bucket_idx microseconds. Bucket N
covers [2^N, 2^(N+1)) µs. Bucket 0 = 1-2µs; bucket 20 = 1.05s
to 2.1s; bucket 30 = ~17min to ~34min.
§Use
ⓘ
use wombatkv_node::latency_histogram::LatencyHistogram;
let h = LatencyHistogram::new();
h.record_us(123);
h.record_us(456);
let snap = h.snapshot();
assert!(snap.total_count() == 2);Structs§
- Histogram
Snapshot - Point-in-time snapshot of a
LatencyHistogram. - Latency
Histogram - Lock-free fixed-bucket latency histogram.
Constants§
- HISTOGRAM_
BUCKETS - Number of log-scale buckets. 30 covers 1µs to ~17min.
Functions§
- emit_
snapshot_ jsonl - Emit a single MyelonInstr line per (tag, snapshot), the same
shape as
embed::emit_timingevents so existing log consumers can pick it up without schema changes. - record_
global - Record a latency observation against the global registry under
tag. Creates the histogram on first use. Read-lock-fast path for repeat tags; write-lock only on first-use insert. - reset_
all - Reset every histogram in the registry. Useful for periodic-emit windows where each window’s stats are reported then zeroed.
- snapshot_
all - Snapshot every histogram in the registry.