From b2fa1c952450d4158adc71d64e9dc6defd134371 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 30 Dec 2024 17:42:52 +0000 Subject: [PATCH] TSDB benchmarks: Commit periodically to speed up init When creating dummy data for benchmarks, call `Commit()` periodically to avoid growing the appender to enormous size. Signed-off-by: Bryan Boreham --- tsdb/querier_bench_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tsdb/querier_bench_test.go b/tsdb/querier_bench_test.go index 8b8f092a81..038052e340 100644 --- a/tsdb/querier_bench_test.go +++ b/tsdb/querier_bench_test.go @@ -55,6 +55,8 @@ func BenchmarkQuerier(b *testing.B) { addSeries(labels.FromStrings("i", strconv.Itoa(i)+postingsBenchSuffix, "n", "1_"+strconv.Itoa(n)+postingsBenchSuffix, "j", "bar")) addSeries(labels.FromStrings("i", strconv.Itoa(i)+postingsBenchSuffix, "n", "2_"+strconv.Itoa(n)+postingsBenchSuffix, "j", "foo")) } + require.NoError(b, app.Commit()) + app = h.Appender(context.Background()) } require.NoError(b, app.Commit()) @@ -270,6 +272,10 @@ func createHeadForBenchmarkSelect(b *testing.B, numSeries int, addSeries func(ap app := h.Appender(context.Background()) for i := 0; i < numSeries; i++ { addSeries(app, i) + if i%1000 == 999 { // Commit every so often, so the appender doesn't get too big. + require.NoError(b, app.Commit()) + app = h.Appender(context.Background()) + } } require.NoError(b, app.Commit()) return h, db