perf: Add benchmarks for timeseries query (exemplars) performance#4665
Merged
perf: Add benchmarks for timeseries query (exemplars) performance#4665
Conversation
simonswine
reviewed
Dec 12, 2025
Contributor
simonswine
left a comment
There was a problem hiding this comment.
I was quickly suspicious, as the different time ranges don't have different outcomes and rightly so: none of those benchmarks, hits points in time where the sample block contain data, therefore they only cover the cost for setting up a query.
I have experimented locally and this actually hits data:
diff --git a/pkg/querybackend/query_time_series_test.go b/pkg/querybackend/query_time_series_test.go
index 6d59509cf..aa40bdc44 100644
--- a/pkg/querybackend/query_time_series_test.go
+++ b/pkg/querybackend/query_time_series_test.go
@@ -158,10 +158,23 @@ func sanitizeMetadata(meta []*metastorev1.BlockMeta) {
// runTimeSeriesQuery executes a timeseries query with the given parameters.
func (f *benchmarkFixture) runTimeSeriesQuery(b *testing.B, req *queryv1.InvokeRequest) {
b.Helper()
- _, err := f.reader.Invoke(f.ctx, req)
+ resp, err := f.reader.Invoke(f.ctx, req)
if err != nil {
b.Fatalf("query failed: %v", err)
}
+ for _, r := range resp.Reports {
+ if r.ReportType != queryv1.ReportType_REPORT_TIME_SERIES {
+ continue
+ }
+ for _, s := range r.TimeSeries.TimeSeries {
+ for _, p := range s.Points {
+ if p.Value > 0 {
+ return
+ }
+ }
+ }
+ }
+ panic("no data found")
}
// makeTimeSeriesRequest creates a timeseries query request with the given parameters.
@@ -196,9 +209,6 @@ func (f *benchmarkFixture) makeTimeSeriesRequest(
func BenchmarkTimeSeriesQuery(b *testing.B) {
fixture := setupBenchmarkFixture(b)
- now := time.Now()
- oneHourAgo := now.Add(-1 * time.Hour)
-
benchmarks := []struct {
name string
exemplarType typesv1.ExemplarType
@@ -210,7 +220,7 @@ func BenchmarkTimeSeriesQuery(b *testing.B) {
for _, bm := range benchmarks {
b.Run(bm.name, func(b *testing.B) {
req := fixture.makeTimeSeriesRequest(
- oneHourAgo, now,
+ startTime, startTime.Add(time.Hour),
"{}",
[]string{"service_name"},
bm.exemplarType,
@@ -234,7 +244,6 @@ func BenchmarkTimeSeriesQuery(b *testing.B) {
// Expected results: Overhead ratio should remain constant across time ranges.
func BenchmarkTimeSeriesQuery_TimeRange(b *testing.B) {
fixture := setupBenchmarkFixture(b)
- now := time.Now()
timeRanges := []struct {
name string
@@ -259,7 +268,7 @@ func BenchmarkTimeSeriesQuery_TimeRange(b *testing.B) {
for _, et := range exemplarTypes {
b.Run(et.name, func(b *testing.B) {
req := fixture.makeTimeSeriesRequest(
- now.Add(-tr.duration), now,
+ startTime, startTime.Add(tr.duration),
"{}",
[]string{"service_name"},
et.typ,
The slow down is higher, but it could be still in a acceptable range, we will find this better out with real data queriers.
In any case thanks for adding the benchmark they will help us optimising, when we are seeing the impact.
Contributor
Author
Performance ResultsNow with the fix suggested by @simonswine Command Used: # Run all timeseries benchmarks (base + time range variants)
go test -bench=BenchmarkTimeSeriesQuery -benchmem ./pkg/querybackend/Results: Basic Comparison (1 Hour Query)
|
simonswine
approved these changes
Jan 13, 2026
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.
Adds benchmarks to measure and validate the performance of timeseries queries, particularly focusing on the exemplar collection overhead introduced in #4615.
Performance Results
Part 1: Refactoring Cost (NoExemplars vs weekly/f145)
We refactored
profileEntryIteratorto use a flexible options pattern. This section measures the cost of that refactoring even when exemplars are disabled.Comparison Setup:
weekly/f145branch (old simple implementation, before exemplar PR)NoExemplars(new options pattern, exemplars disabled)Commands Used:
Analysis:
Potential memory trade-off explanation:
The refactored
profileEntryIteratoruses a flexible options pattern with:Part 2: Exemplar Feature Overhead (NoExemplars vs WithExemplars)
This section measures the additional cost of enabling exemplars on top of the refactored baseline.
Command Used:
Analysis:
Overhead explanation:
When exemplars are enabled, additional data must be fetched:
The allocation increase comes primarily from fetching full label sets and processing profile IDs for each matching profile.
Overhead consistency across time ranges:
Overhead remains consistent:
Summary
Changes to default path (NoExemplars)
Exemplar overhead
Key findings
Note: Exemplars feature will be opt-in. Users who don't request exemplars are unaffected by the time and allocation overhead. The overhead is inherent to fetching additional data (profile IDs and complete label sets), but future optimizations could reduce the impact if needed.