rust-prometheus icon indicating copy to clipboard operation
rust-prometheus copied to clipboard

(Local)IntHistogram

Open breezewish opened this issue 6 years ago • 6 comments
trafficstars

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.

breezewish avatar Jun 22 '19 15:06 breezewish

Mostly, we use the histogram to record operation duration in TiKV, using Int can help us, but we need to update Grafana.

siddontang avatar Jun 23 '19 16:06 siddontang

Yes, currently we use seconds and we need to update to milliseconds in order to use IntHistogram.

breezewish avatar Jun 23 '19 16:06 breezewish

Is there a block of example code which could be used to benchmark this?

hdost avatar Dec 06 '20 21:12 hdost

@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.

mxinden avatar Dec 06 '20 21:12 mxinden

Yes indeed I wasn't sure if the bench_counter_no_labels_concurrent_write would appear in the bench tests.

hdost avatar Dec 07 '20 18:12 hdost

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

hdost avatar Feb 09 '21 20:02 hdost