From 8d929301406ff79cc05021afb39e4294aeff8f74 Mon Sep 17 00:00:00 2001 From: Marco Pracucci Date: Thu, 28 Sep 2023 10:46:22 +0200 Subject: [PATCH] Make the benchmark more realistic, returning some postings Signed-off-by: Marco Pracucci --- tsdb/postings_for_matchers_cache_test.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tsdb/postings_for_matchers_cache_test.go b/tsdb/postings_for_matchers_cache_test.go index f06057a739..d7dc3c40ba 100644 --- a/tsdb/postings_for_matchers_cache_test.go +++ b/tsdb/postings_for_matchers_cache_test.go @@ -340,7 +340,10 @@ func TestPostingsForMatchersCache(t *testing.T) { } func BenchmarkPostingsForMatchersCache(b *testing.B) { - const numMatchers = 100 + const ( + numMatchers = 100 + numPostings = 100 + ) var ( ctx = context.Background() @@ -353,11 +356,17 @@ func BenchmarkPostingsForMatchersCache(b *testing.B) { matchersLists[i] = []*labels.Matcher{labels.MustNewMatcher(labels.MatchEqual, "matchers", fmt.Sprintf("%d", i))} } + // Create a postings list. + refs := make([]storage.SeriesRef, numPostings) + for r := range refs { + refs[r] = storage.SeriesRef(r) + } + b.Run("no evictions", func(b *testing.B) { // Configure the cache to never evict. cache := NewPostingsForMatchersCache(time.Hour, 1000000, 1024*1024*1024, true) cache.postingsForMatchers = func(ctx context.Context, ix IndexPostingsReader, ms ...*labels.Matcher) (index.Postings, error) { - return index.NewListPostings(nil), nil + return index.NewListPostings(refs), nil } b.ResetTimer() @@ -374,7 +383,7 @@ func BenchmarkPostingsForMatchersCache(b *testing.B) { // Configure the cache to evict continuously. cache := NewPostingsForMatchersCache(time.Hour, 1, 1, true) cache.postingsForMatchers = func(ctx context.Context, ix IndexPostingsReader, ms ...*labels.Matcher) (index.Postings, error) { - return index.NewListPostings(nil), nil + return index.NewListPostings(refs), nil } b.ResetTimer()