fix rwv2 build write request benchmark, also change how the memory usage (#14925)

is reported for these benchmarks to more accurately reflect what's
actually allocated

Signed-off-by: Callum Styan <callumstyan@gmail.com>
pull/14931/head
Callum Styan 2 months ago committed by GitHub
parent b8d1336d42
commit c328d5fc88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1859,13 +1859,6 @@ func BenchmarkBuildWriteRequest(b *testing.B) {
} }
pBuf := proto.NewBuffer(nil) pBuf := proto.NewBuffer(nil)
// Warmup buffers
for i := 0; i < 10; i++ {
populateTimeSeries(batch, seriesBuff, true, true)
buildWriteRequest(noopLogger, seriesBuff, nil, pBuf, &buff, nil, "snappy")
}
b.ResetTimer()
totalSize := 0 totalSize := 0
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
populateTimeSeries(batch, seriesBuff, true, true) populateTimeSeries(batch, seriesBuff, true, true)
@ -1897,45 +1890,43 @@ func BenchmarkBuildWriteRequest(b *testing.B) {
func BenchmarkBuildV2WriteRequest(b *testing.B) { func BenchmarkBuildV2WriteRequest(b *testing.B) {
noopLogger := log.NewNopLogger() noopLogger := log.NewNopLogger()
type testcase struct { bench := func(b *testing.B, batch []timeSeries) {
batch []timeSeries
}
testCases := []testcase{
{createDummyTimeSeries(2)},
{createDummyTimeSeries(10)},
{createDummyTimeSeries(100)},
}
for _, tc := range testCases {
symbolTable := writev2.NewSymbolTable() symbolTable := writev2.NewSymbolTable()
buff := make([]byte, 0) buff := make([]byte, 0)
seriesBuff := make([]writev2.TimeSeries, len(tc.batch)) seriesBuff := make([]writev2.TimeSeries, len(batch))
for i := range seriesBuff { for i := range seriesBuff {
seriesBuff[i].Samples = []writev2.Sample{{}} seriesBuff[i].Samples = []writev2.Sample{{}}
seriesBuff[i].Exemplars = []writev2.Exemplar{{}} seriesBuff[i].Exemplars = []writev2.Exemplar{{}}
} }
pBuf := []byte{} pBuf := []byte{}
// Warmup buffers
for i := 0; i < 10; i++ {
populateV2TimeSeries(&symbolTable, tc.batch, seriesBuff, true, true)
buildV2WriteRequest(noopLogger, seriesBuff, symbolTable.Symbols(), &pBuf, &buff, nil, "snappy")
}
b.Run(fmt.Sprintf("%d-instances", len(tc.batch)), func(b *testing.B) {
totalSize := 0 totalSize := 0
for j := 0; j < b.N; j++ { for i := 0; i < b.N; i++ {
populateV2TimeSeries(&symbolTable, tc.batch, seriesBuff, true, true) populateV2TimeSeries(&symbolTable, batch, seriesBuff, true, true)
b.ResetTimer()
req, _, _, err := buildV2WriteRequest(noopLogger, seriesBuff, symbolTable.Symbols(), &pBuf, &buff, nil, "snappy") req, _, _, err := buildV2WriteRequest(noopLogger, seriesBuff, symbolTable.Symbols(), &pBuf, &buff, nil, "snappy")
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
symbolTable.Reset()
totalSize += len(req) totalSize += len(req)
b.ReportMetric(float64(totalSize)/float64(b.N), "compressedSize/op") b.ReportMetric(float64(totalSize)/float64(b.N), "compressedSize/op")
} }
})
} }
twoBatch := createDummyTimeSeries(2)
tenBatch := createDummyTimeSeries(10)
hundredBatch := createDummyTimeSeries(100)
b.Run("2 instances", func(b *testing.B) {
bench(b, twoBatch)
})
b.Run("10 instances", func(b *testing.B) {
bench(b, tenBatch)
})
b.Run("1k instances", func(b *testing.B) {
bench(b, hundredBatch)
})
} }
func TestDropOldTimeSeries(t *testing.T) { func TestDropOldTimeSeries(t *testing.T) {

Loading…
Cancel
Save