Use a fake SeriesIterator (that generates samples on the fly instead of using a slice) for BufferedSeriesIterator, to reduce the variance of benchmark results due to memory pressure. (#4847)

Signed-off-by: Alin Sinpalean <alin.sinpalean@gmail.com>
This commit is contained in:
Alin Sinpalean 2018-12-18 12:22:33 +01:00 committed by Brian Brazil
parent a2766a94a3
commit d6adfe2ae2

View file

@ -163,21 +163,8 @@ func TestBufferedSeriesIteratorNoBadAt(t *testing.T) {
}
func BenchmarkBufferedSeriesIterator(b *testing.B) {
var (
samples []sample
lastT int64
)
for i := 0; i < b.N; i++ {
lastT += 30
samples = append(samples, sample{
t: lastT,
v: 123, // doesn't matter
})
}
// Simulate a 5 minute rate.
it := NewBufferIterator(newListSeriesIterator(samples), 5*60)
it := NewBufferIterator(newFakeSeriesIterator(int64(b.N), 30), 5*60)
b.SetBytes(int64(b.N * 16))
b.ReportAllocs()
@ -255,3 +242,31 @@ func (it *listSeriesIterator) Seek(t int64) bool {
func (it *listSeriesIterator) Err() error {
return nil
}
type fakeSeriesIterator struct {
nsamples int64
step int64
idx int64
}
func newFakeSeriesIterator(nsamples, step int64) *fakeSeriesIterator {
return &fakeSeriesIterator{nsamples: nsamples, step: step, idx: -1}
}
func (it *fakeSeriesIterator) At() (int64, float64) {
return it.idx * it.step, 123 // value doesn't matter
}
func (it *fakeSeriesIterator) Next() bool {
it.idx++
return it.idx < it.nsamples
}
func (it *fakeSeriesIterator) Seek(t int64) bool {
it.idx = t / it.step
return it.idx < it.nsamples
}
func (it *fakeSeriesIterator) Err() error {
return nil
}