From 0d283effa86bf3284c6ec7c7c519b63626ae5428 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sat, 26 Aug 2023 09:40:59 +0000 Subject: [PATCH] promql: force mmap of head chunks in BenchmarkRangeQuery Otherwise we have a highly unusual situation of over 100 chunks in the headChunks list of each series, which heavily skews performance. Signed-off-by: Bryan Boreham --- promql/bench_test.go | 3 +++ tsdb/db.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/promql/bench_test.go b/promql/bench_test.go index c6a528f7b..a4bde6c41 100644 --- a/promql/bench_test.go +++ b/promql/bench_test.go @@ -66,6 +66,8 @@ func setupRangeQueryTestData(stor *teststorage.TestStorage, _ *Engine, interval, return err } } + stor.DB.ForceHeadMMap() // Ensure we have at most one head chunk for every series. + stor.DB.Compact() return nil } @@ -222,6 +224,7 @@ func rangeQueryCases() []benchCase { func BenchmarkRangeQuery(b *testing.B) { stor := teststorage.New(b) + stor.DB.DisableCompactions() // Don't want auto-compaction disrupting timings. defer stor.Close() opts := EngineOpts{ Logger: nil, diff --git a/tsdb/db.go b/tsdb/db.go index 58ba6900b..111f0cb21 100644 --- a/tsdb/db.go +++ b/tsdb/db.go @@ -1797,6 +1797,11 @@ func (db *DB) EnableCompactions() { level.Info(db.logger).Log("msg", "Compactions enabled") } +// ForceHeadMMap is intended for use only in tests and benchmarks. +func (db *DB) ForceHeadMMap() { + db.head.mmapHeadChunks() +} + // Snapshot writes the current data to the directory. If withHead is set to true it // will create a new block containing all data that's currently in the memory buffer/WAL. func (db *DB) Snapshot(dir string, withHead bool) error {