skeg-telemetry
Zero-overhead atomic counters and histograms for skeg.
Design
- Every public API entry is
#[inline(always)]. - All counters and histograms are static
AtomicU64arrays. NoHashMap, noMutex, no allocation on the hot path. - Per-op counters are sharded across
MAX_SHARDS = 32to avoid false sharing on M-series P-cores. - Histograms are fixed exponential buckets (1 µs → 1 s, plus
+Inf). - When the crate is compiled with no features, every public function is an
empty body and the caller's arguments are sunk into
let _ = …— verified withcargo asmto compile to a tail call elimination.
Features
| feature | default | what it adds |
|---|---|---|
stats |
yes | static counters + stats::dump_text() (used by RESP3 STATS) |
http |
no | tiny HTTP exporter on a dedicated thread (/metrics) |
When neither feature is on, this crate is a no-op.
Hot-path cost budget
record_op is gated by benches/overhead.rs:
| call | budget | typical (Apple M1) |
|---|---|---|
record_op(Op, shard, dur) |
< 50 ns | ~ 3–5 ns |
tick_counter(Counter) |
< 20 ns | ~ 1–2 ns |
set_gauge(Gauge, u64) |
< 20 ns | ~ 1–2 ns |
CI fails if any benchmark drifts past its budget.
Usage
use ;
let t0 = now;
do_vsearch;
record_op;
For the HTTP exporter:
spawn?;
For the RESP3 STATS command body:
let body = dump_text;