storage: add BenchmarkFanoutAppenderV2

Signed-off-by: bwplotka <bwplotka@gmail.com>
This commit is contained in:
bwplotka 2026-01-30 15:19:35 +00:00
parent 88f6ee4c8e
commit 91b0f353b0

View file

@ -16,6 +16,7 @@ package storage_test
import (
"context"
"errors"
"strconv"
"testing"
"github.com/prometheus/common/model"
@ -563,3 +564,38 @@ func TestFanoutAppenderV2(t *testing.T) {
})
}
}
// Recommended CLI invocation:
/*
export bench=fanoutAppender && go test ./storage/... \
-run '^$' -bench '^BenchmarkFanoutAppenderV2' \
-benchtime 2s -count 6 -cpu 2 -timeout 999m \
| tee ${bench}.txt
*/
func BenchmarkFanoutAppenderV2(b *testing.B) {
ex := exemplar.Exemplar{Value: 1}
var series []labels.Labels
for i := range 1000 {
series = append(series, labels.FromStrings(model.MetricNameLabel, "metric1", "i", strconv.Itoa(i)))
}
for _, tt := range fanoutAppenderTestCases(nil) {
b.Run(tt.name, func(b *testing.B) {
f := storage.NewFanout(nil, mockStorage{appV2: tt.primary}, mockStorage{appV2: tt.secondary})
b.ReportAllocs()
b.ResetTimer()
for b.Loop() {
app := f.AppenderV2(b.Context())
for _, s := range series {
// Purposefully skip errors as we want to benchmark error cases too (majority of the fanout logic).
_, _ = app.Append(0, s, 0, 0, 1, nil, nil, storage.AOptions{
Exemplars: []exemplar.Exemplar{ex},
})
}
require.NoError(b, app.Rollback())
}
})
}
}