From bedc0eda1f25e61db2d78407ca67708ce1f4dd28 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Sun, 18 Sep 2016 22:58:39 +0100 Subject: [PATCH] Added BenchmarkQueryRange --- storage/local/storage_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/storage/local/storage_test.go b/storage/local/storage_test.go index cd9e866f5..a19f753ae 100644 --- a/storage/local/storage_test.go +++ b/storage/local/storage_test.go @@ -19,6 +19,7 @@ import ( "math" "math/rand" "os" + "strconv" "testing" "testing/quick" "time" @@ -469,6 +470,38 @@ func BenchmarkLabelMatching(b *testing.B) { b.StopTimer() } +func BenchmarkQueryRange(b *testing.B) { + now := model.Now() + insertStart := now.Add(-2 * time.Hour) + + s, closer := NewTestStorage(b, 2) + defer closer.Close() + + // Stop maintenance loop to prevent actual purging. + close(s.loopStopping) + <-s.loopStopped + <-s.logThrottlingStopped + // Recreate channel to avoid panic when we really shut down. + s.loopStopping = make(chan struct{}) + + for i := 0; i < 8192; i++ { + s.Append(&model.Sample{ + Metric: model.Metric{"__name__": model.LabelValue(strconv.Itoa(i)), "job": "test"}, + Timestamp: insertStart, + Value: 1, + }) + } + s.WaitForIndexing() + + b.ResetTimer() + b.RunParallel(func(pb *testing.PB) { + lm, _ := metric.NewLabelMatcher(metric.Equal, "job", "test") + for pb.Next() { + s.QueryRange(context.Background(), insertStart, now, lm) + } + }) +} + func TestRetentionCutoff(t *testing.T) { now := model.Now() insertStart := now.Add(-2 * time.Hour)