Lock-free Observations for Prometheus Histograms
summary
Shows how Prometheus histograms get near lock-free updates by using the atomic package to write into a hot buffer while reads snapshot a cold buffer, switching them by atomically flipping a packed 64-bit word that holds a counter and a 1-bit index (63-bit packing). Unit tests run a million iterations and expose a flaky failure caused by 64-bit alignment and slice layout on 32-bit platforms, fixed by heap-allocating the counters, after which the approach reliably works.
AI-written summary · about
chapters (5)
- 0:00Start
- 16:00Write method part 1
- 17:26attempt 1: Wait for cool-down
- 22:19Lock-free observe revised
- 23:13Write method revised
related talks
25mTackling Contention : The Monster in sync.Locker
01h 32mLock-free programming with modern C++
01h 38mLock-free Programming is Dead - Long Live Lock-free Programming!
01h 22mBeyond Sequential Consistency - Leveraging Atomics for Fun & Profit
01h 14m“C++ atomics, from basic to advanced. What do they really do?”
01h 04mDebugging data races
43mC++ Atomics...
01h 28mA lock-free std::atomic std::shared_ptr
