2023-01-04 06:19:18 +00:00
|
|
|
package streamaggr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkAggregatorsPushByJobAvg(b *testing.B) {
|
|
|
|
for _, output := range []string{
|
|
|
|
"total",
|
|
|
|
"increase",
|
|
|
|
"count_series",
|
|
|
|
"count_samples",
|
|
|
|
"sum_samples",
|
|
|
|
"last",
|
|
|
|
"min",
|
|
|
|
"max",
|
|
|
|
"avg",
|
|
|
|
"stddev",
|
|
|
|
"stdvar",
|
|
|
|
"histogram_bucket",
|
|
|
|
"quantiles(0, 0.5, 1)",
|
|
|
|
} {
|
|
|
|
b.Run(fmt.Sprintf("output=%s", output), func(b *testing.B) {
|
|
|
|
benchmarkAggregatorsPush(b, output)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func benchmarkAggregatorsPush(b *testing.B, output string) {
|
|
|
|
config := fmt.Sprintf(`
|
|
|
|
- match: http_requests_total
|
|
|
|
interval: 24h
|
|
|
|
without: [job]
|
|
|
|
outputs: [%q]
|
|
|
|
`, output)
|
2023-07-24 23:44:09 +00:00
|
|
|
pushCalls := 0
|
2023-01-04 06:19:18 +00:00
|
|
|
pushFunc := func(tss []prompbmarshal.TimeSeries) {
|
2023-07-24 23:44:09 +00:00
|
|
|
pushCalls++
|
|
|
|
if pushCalls > 1 {
|
|
|
|
panic(fmt.Errorf("pushFunc is expected to be called exactly once at MustStop"))
|
2023-07-24 23:33:30 +00:00
|
|
|
}
|
2023-01-04 06:19:18 +00:00
|
|
|
}
|
2024-01-24 10:31:27 +00:00
|
|
|
a, err := newAggregatorsFromData([]byte(config), pushFunc, 0)
|
2023-01-04 06:19:18 +00:00
|
|
|
if err != nil {
|
|
|
|
b.Fatalf("unexpected error when initializing aggregators: %s", err)
|
|
|
|
}
|
|
|
|
defer a.MustStop()
|
|
|
|
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.SetBytes(int64(len(benchSeries)))
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
2023-07-24 23:44:09 +00:00
|
|
|
var matchIdxs []byte
|
2023-01-04 06:19:18 +00:00
|
|
|
for pb.Next() {
|
2023-07-24 23:44:09 +00:00
|
|
|
matchIdxs = a.Push(benchSeries, matchIdxs)
|
2023-01-04 06:19:18 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-24 23:44:09 +00:00
|
|
|
func newBenchSeries(seriesCount, samplesPerSeries int) []prompbmarshal.TimeSeries {
|
2023-01-04 06:19:18 +00:00
|
|
|
a := make([]string, seriesCount*samplesPerSeries)
|
|
|
|
for i := 0; i < samplesPerSeries; i++ {
|
|
|
|
for j := 0; j < seriesCount; j++ {
|
2023-07-24 23:44:09 +00:00
|
|
|
s := fmt.Sprintf(`http_requests_total{path="/foo/%d",job="foo",instance="bar"} %d`, j, i*10)
|
2023-01-04 06:19:18 +00:00
|
|
|
a = append(a, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
metrics := strings.Join(a, "\n")
|
|
|
|
return mustParsePromMetrics(metrics)
|
|
|
|
}
|
|
|
|
|
|
|
|
const seriesCount = 10000
|
|
|
|
const samplesPerSeries = 10
|
|
|
|
|
2023-07-24 23:44:09 +00:00
|
|
|
var benchSeries = newBenchSeries(seriesCount, samplesPerSeries)
|