Skip to content

Commit 79742f8

Browse files
committed
Add test bacj
Signed-off-by: Alan Protasio <[email protected]>
1 parent 50884d9 commit 79742f8

File tree

2 files changed

+45
-44
lines changed

2 files changed

+45
-44
lines changed

pkg/querier/batch/batch.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ func (a *iteratorAdapter) Seek(t int64) bool {
101101
}
102102
return true
103103
} else {
104-
// In this case, t is after the end of the current batch. Here we try to calculate if we are seeking to samples
105-
// in the same chunks, and if so, we foward the iterator to the right point in time - we do that this
106-
// is more efficient than the seek call
104+
// In this case, t is after the end of the current batch.
105+
// Here we assume that the scrape interval is 30s and try to calculate how many samples ahead we are trying to seek.
106+
// If the number of samples is < 60 (each chunk has 120 samples) we assume that the samples belongs to the current
107+
// chunk and we forward the iterator to the right point - this is more efficient than the seek call.
107108
approxNumberOfSamples := model.Time(t).Sub(model.Time(a.curr.Timestamps[a.curr.Length-1])) / (30 * time.Second)
108109
if approxNumberOfSamples < 60 {
109110
for a.underlying.Next(promchunk.BatchSize) {

pkg/querier/batch/batch_test.go

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,47 @@ import (
1313
promchunk "github.com/cortexproject/cortex/pkg/chunk/encoding"
1414
)
1515

16-
//func BenchmarkNewChunkMergeIterator_CreateAndIterate(b *testing.B) {
17-
// scenarios := []struct {
18-
// numChunks int
19-
// numSamplesPerChunk int
20-
// duplicationFactor int
21-
// enc promchunk.Encoding
22-
// }{
23-
// {numChunks: 1000, numSamplesPerChunk: 100, duplicationFactor: 1, enc: promchunk.PrometheusXorChunk},
24-
// {numChunks: 1000, numSamplesPerChunk: 100, duplicationFactor: 3, enc: promchunk.PrometheusXorChunk},
25-
// {numChunks: 100, numSamplesPerChunk: 100, duplicationFactor: 1, enc: promchunk.PrometheusXorChunk},
26-
// {numChunks: 100, numSamplesPerChunk: 100, duplicationFactor: 3, enc: promchunk.PrometheusXorChunk},
27-
// {numChunks: 1, numSamplesPerChunk: 100, duplicationFactor: 1, enc: promchunk.PrometheusXorChunk},
28-
// {numChunks: 1, numSamplesPerChunk: 100, duplicationFactor: 3, enc: promchunk.PrometheusXorChunk},
29-
// }
30-
//
31-
// for _, scenario := range scenarios {
32-
// name := fmt.Sprintf("chunks: %d samples per chunk: %d duplication factor: %d encoding: %s",
33-
// scenario.numChunks,
34-
// scenario.numSamplesPerChunk,
35-
// scenario.duplicationFactor,
36-
// scenario.enc.String())
37-
//
38-
// chunks := createChunks(b, scenario.numChunks, scenario.numSamplesPerChunk, scenario.duplicationFactor, scenario.enc)
39-
//
40-
// b.Run(name, func(b *testing.B) {
41-
// b.ReportAllocs()
42-
//
43-
// for n := 0; n < b.N; n++ {
44-
// it := NewChunkMergeIterator(chunks, 0, 0)
45-
// for it.Next() != chunkenc.ValNone {
46-
// it.At()
47-
// }
48-
//
49-
// // Ensure no error occurred.
50-
// if it.Err() != nil {
51-
// b.Fatal(it.Err().Error())
52-
// }
53-
// }
54-
// })
55-
// }
56-
//}
16+
func BenchmarkNewChunkMergeIterator_CreateAndIterate(b *testing.B) {
17+
scenarios := []struct {
18+
numChunks int
19+
numSamplesPerChunk int
20+
duplicationFactor int
21+
enc promchunk.Encoding
22+
}{
23+
{numChunks: 1000, numSamplesPerChunk: 100, duplicationFactor: 1, enc: promchunk.PrometheusXorChunk},
24+
{numChunks: 1000, numSamplesPerChunk: 100, duplicationFactor: 3, enc: promchunk.PrometheusXorChunk},
25+
{numChunks: 100, numSamplesPerChunk: 100, duplicationFactor: 1, enc: promchunk.PrometheusXorChunk},
26+
{numChunks: 100, numSamplesPerChunk: 100, duplicationFactor: 3, enc: promchunk.PrometheusXorChunk},
27+
{numChunks: 1, numSamplesPerChunk: 100, duplicationFactor: 1, enc: promchunk.PrometheusXorChunk},
28+
{numChunks: 1, numSamplesPerChunk: 100, duplicationFactor: 3, enc: promchunk.PrometheusXorChunk},
29+
}
30+
31+
for _, scenario := range scenarios {
32+
name := fmt.Sprintf("chunks: %d samples per chunk: %d duplication factor: %d encoding: %s",
33+
scenario.numChunks,
34+
scenario.numSamplesPerChunk,
35+
scenario.duplicationFactor,
36+
scenario.enc.String())
37+
38+
chunks := createChunks(b, step, scenario.numChunks, scenario.numSamplesPerChunk, scenario.duplicationFactor, scenario.enc)
39+
40+
b.Run(name, func(b *testing.B) {
41+
b.ReportAllocs()
42+
43+
for n := 0; n < b.N; n++ {
44+
it := NewChunkMergeIterator(chunks, 0, 0)
45+
for it.Next() != chunkenc.ValNone {
46+
it.At()
47+
}
48+
49+
// Ensure no error occurred.
50+
if it.Err() != nil {
51+
b.Fatal(it.Err().Error())
52+
}
53+
}
54+
})
55+
}
56+
}
5757

5858
func BenchmarkNewChunkMergeIterator_Seek(b *testing.B) {
5959
scrapeInterval := 30 * time.Second

0 commit comments

Comments
 (0)