rust-prometheus
rust-prometheus copied to clipboard
(Local)IntHistogram
We need to implement a int version for Histogram, like Counter and Gauge, since atomic float implementation (loop + lock cmpxchg) is much slower than native atomic integer instruction (lock add).
For example, according to benchmarks:
test bench_counter_no_labels ... bench: 14 ns/iter (+/- 0)
test bench_int_counter_no_labels ... bench: 7 ns/iter (+/- 1)
When there is no concurrent write, float atomic implemented via CAS is 1x slower than int atomic.
test bench_counter_no_labels_concurrent_write ... bench: 5,263 ns/iter (+/- 1,204)
test bench_int_counter_no_labels_concurrent_write ... bench: 892 ns/iter (+/- 100)
When there is concurrent write, float atomic is 5x slower than int atomic.
Mostly, we use the histogram to record operation duration in TiKV, using Int can help us, but we need to update Grafana.
Yes, currently we use seconds and we need to update to milliseconds in order to use IntHistogram.
Is there a block of example code which could be used to benchmark this?
@hdost today histograms don't support anything other than AtomicF64, thus there is no benchmark comparing AtomicF64 with e.g. AtomicU64. Benchmark running AtomicF64 can be found here.
Yes indeed I wasn't sure if the bench_counter_no_labels_concurrent_write would appear in the bench tests.
I've started on a rather large draft here: #388 before going too much further down the rabbit hole I wouldn't mind a once over. It doesn't compile and I am well aware of hat but I am curious if this path is worth pursing