mirror of https://github.com/prometheus/prometheus
Add benchmark for querying a persisted block (#425)
Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>pull/5805/head
parent
1dd9a6bd29
commit
f4afc7dff2
|
@ -15,11 +15,14 @@ package tsdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/go-kit/kit/log"
|
||||||
"github.com/prometheus/tsdb/index"
|
"github.com/prometheus/tsdb/index"
|
||||||
|
"github.com/prometheus/tsdb/labels"
|
||||||
"github.com/prometheus/tsdb/testutil"
|
"github.com/prometheus/tsdb/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -73,3 +76,44 @@ func createEmptyBlock(t *testing.T, dir string, meta *BlockMeta) *Block {
|
||||||
testutil.Ok(t, err)
|
testutil.Ok(t, err)
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// createPopulatedBlock creates a block with nSeries series, and nSamples samples.
|
||||||
|
func createPopulatedBlock(tb testing.TB, dir string, nSeries, nSamples int) *Block {
|
||||||
|
head, err := NewHead(nil, nil, nil, 2*60*60*1000)
|
||||||
|
testutil.Ok(tb, err)
|
||||||
|
defer head.Close()
|
||||||
|
|
||||||
|
lbls, err := labels.ReadLabels(filepath.Join("testdata", "20kseries.json"), nSeries)
|
||||||
|
testutil.Ok(tb, err)
|
||||||
|
refs := make([]uint64, nSeries)
|
||||||
|
|
||||||
|
for n := 0; n < nSamples; n++ {
|
||||||
|
app := head.Appender()
|
||||||
|
ts := n * 1000
|
||||||
|
for i, lbl := range lbls {
|
||||||
|
if refs[i] != 0 {
|
||||||
|
err := app.AddFast(refs[i], int64(ts), rand.Float64())
|
||||||
|
if err == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ref, err := app.Add(lbl, int64(ts), rand.Float64())
|
||||||
|
testutil.Ok(tb, err)
|
||||||
|
refs[i] = ref
|
||||||
|
}
|
||||||
|
err := app.Commit()
|
||||||
|
testutil.Ok(tb, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
compactor, err := NewLeveledCompactor(nil, log.NewNopLogger(), []int64{1000000}, nil)
|
||||||
|
testutil.Ok(tb, err)
|
||||||
|
|
||||||
|
testutil.Ok(tb, os.MkdirAll(dir, 0777))
|
||||||
|
|
||||||
|
ulid, err := compactor.Write(dir, head, head.MinTime(), head.MaxTime(), nil)
|
||||||
|
testutil.Ok(tb, err)
|
||||||
|
|
||||||
|
blk, err := OpenBlock(filepath.Join(dir, ulid.String()), nil)
|
||||||
|
testutil.Ok(tb, err)
|
||||||
|
return blk
|
||||||
|
}
|
||||||
|
|
|
@ -15,8 +15,10 @@ package tsdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -1296,6 +1298,41 @@ func BenchmarkMergedSeriesSet(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkPersistedQueries(b *testing.B) {
|
||||||
|
for _, nSeries := range []int{10, 100} {
|
||||||
|
for _, nSamples := range []int{1000, 10000, 100000} {
|
||||||
|
b.Run(fmt.Sprintf("series=%d,samplesPerSeries=%d", nSeries, nSamples), func(b *testing.B) {
|
||||||
|
dir, err := ioutil.TempDir("", "bench_persisted")
|
||||||
|
testutil.Ok(b, err)
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
block := createPopulatedBlock(b, dir, nSeries, nSamples)
|
||||||
|
defer block.Close()
|
||||||
|
|
||||||
|
q, err := NewBlockQuerier(block, block.Meta().MinTime, block.Meta().MaxTime)
|
||||||
|
testutil.Ok(b, err)
|
||||||
|
defer q.Close()
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
b.ReportAllocs()
|
||||||
|
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
ss, err := q.Select(labels.NewMustRegexpMatcher("__name__", ".+"))
|
||||||
|
for ss.Next() {
|
||||||
|
s := ss.At()
|
||||||
|
s.Labels()
|
||||||
|
it := s.Iterator()
|
||||||
|
for it.Next() {
|
||||||
|
}
|
||||||
|
testutil.Ok(b, it.Err())
|
||||||
|
}
|
||||||
|
testutil.Ok(b, ss.Err())
|
||||||
|
testutil.Ok(b, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type mockChunkReader map[uint64]chunkenc.Chunk
|
type mockChunkReader map[uint64]chunkenc.Chunk
|
||||||
|
|
||||||
func (cr mockChunkReader) Chunk(id uint64) (chunkenc.Chunk, error) {
|
func (cr mockChunkReader) Chunk(id uint64) (chunkenc.Chunk, error) {
|
||||||
|
|
Loading…
Reference in New Issue