benchmark: add WithWork benchmarks for realistic CAS contention testing#1970
Open
raeperd wants to merge 4 commits into
Open
benchmark: add WithWork benchmarks for realistic CAS contention testing#1970raeperd wants to merge 4 commits into
raeperd wants to merge 4 commits into
Conversation
Add benchmarks that simulate realistic application usage by performing CPU work between metric operations, covering Counter.Add, Counter.Inc, Gauge.Add, Gauge.Set, Histogram.Observe, and Summary.Observe at concurrency levels 1/2/4/8. These complement the existing tight-loop benchmarks and are designed to catch regressions like prometheus#1748, where a CAS backoff optimization caused 10x latency spikes in real workloads that the existing benchmarks missed. Relates to prometheus#1759. Signed-off-by: raeperd <raeperd117@gmail.com>
Signed-off-by: raeperd <raeperd117@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
PR #1661 added CAS exponential backoff that showed 53-64% improvement in tight-loop benchmarks, but caused 10x latency regression in production at just 4 goroutines (#1748). The existing benchmarks couldn't detect this because real applications do work between metric updates — tight loops create artificial maximum contention where backoff genuinely helps.
Changes
Add "WithWork" benchmarks that perform ~few μs of CPU work between metric operations, simulating real application behavior. Each benchmark runs at concurrency 1/2/4/8:
BenchmarkCounterAddWithWorkAdd(1.5)BenchmarkCounterIncWithWorkInc()BenchmarkGaugeAddWithWorkAdd(1.5)BenchmarkGaugeSetWithWorkSet(1.5)BenchmarkHistogramObserveWithWorkObserve(1.5)BenchmarkSummaryObserveWithWorkObserve(1.5)Counter uses
Add(1.5)specifically to hit the CAS loop — integer values take theatomic.AddUint64fast path and would bypass the code under test.Work simulation uses 10,000 iterations matching the regression reporter's test in #1748.
Out of scope
benchstatintegration into the release process (acceptance criterion 2 of #1759) is left for separate discussion as a process/CI decision.I'd appreciate any feedback on the approach — happy to adjust the work simulation, concurrency levels, or benchmark structure based on your preferences.
Relates to #1759.