TSDB: extend BenchmarkMemPostings_PostingsForLabelMatching to check merge speed

We need to create more postings entries so the merger has some work to do.
Not material for the regexp ones as they match so few series.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2024-07-26 18:17:35 +01:00
parent 5b5fee08af
commit e630ffdbed

View file

@ -1410,12 +1410,15 @@ func BenchmarkMemPostings_PostingsForLabelMatching(b *testing.B) {
slowRegexp := "^" + slowRegexpString() + "$"
b.Logf("Slow regexp length = %d", len(slowRegexp))
slow := regexp.MustCompile(slowRegexp)
const seriesPerLabel = 10
for _, labelValueCount := range []int{1_000, 10_000, 100_000} {
b.Run(fmt.Sprintf("labels=%d", labelValueCount), func(b *testing.B) {
mp := NewMemPostings()
for i := 0; i < labelValueCount; i++ {
mp.Add(storage.SeriesRef(i), labels.FromStrings("label", strconv.Itoa(i)))
for j := 0; j < seriesPerLabel; j++ {
mp.Add(storage.SeriesRef(i*seriesPerLabel+j), labels.FromStrings("__name__", strconv.Itoa(j), "label", strconv.Itoa(i)))
}
}
fp, err := ExpandPostings(mp.PostingsForLabelMatching(context.Background(), "label", fast.MatchString))
@ -1435,6 +1438,18 @@ func BenchmarkMemPostings_PostingsForLabelMatching(b *testing.B) {
mp.PostingsForLabelMatching(context.Background(), "label", slow.MatchString).Next()
}
})
b.Run("matcher=all", func(b *testing.B) {
for i := 0; i < b.N; i++ {
// Match everything.
p := mp.PostingsForLabelMatching(context.Background(), "label", func(_ string) bool { return true })
var sum storage.SeriesRef
// Iterate through all results to exercise merge function.
for p.Next() {
sum += p.At()
}
}
})
})
}
}