2023-01-04 06:19:18 +00:00
|
|
|
package streamaggr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
|
|
|
)
|
|
|
|
|
2024-03-03 22:45:48 +00:00
|
|
|
var benchOutputs = []string{
|
|
|
|
"total",
|
|
|
|
"total_prometheus",
|
|
|
|
"increase",
|
|
|
|
"increase_prometheus",
|
|
|
|
"count_series",
|
|
|
|
"count_samples",
|
|
|
|
"unique_samples",
|
|
|
|
"sum_samples",
|
|
|
|
"last",
|
|
|
|
"min",
|
|
|
|
"max",
|
|
|
|
"avg",
|
|
|
|
"stddev",
|
|
|
|
"stdvar",
|
|
|
|
"histogram_bucket",
|
|
|
|
"quantiles(0, 0.5, 1)",
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkAggregatorsPush(b *testing.B) {
|
|
|
|
for _, output := range benchOutputs {
|
2023-01-04 06:19:18 +00:00
|
|
|
b.Run(fmt.Sprintf("output=%s", output), func(b *testing.B) {
|
|
|
|
benchmarkAggregatorsPush(b, output)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-03 22:45:48 +00:00
|
|
|
func BenchmarkAggregatorsFlushSerial(b *testing.B) {
|
|
|
|
for _, output := range benchOutputs {
|
|
|
|
b.Run(fmt.Sprintf("output=%s", output), func(b *testing.B) {
|
|
|
|
benchmarkAggregatorsFlushSerial(b, output)
|
|
|
|
})
|
2023-01-04 06:19:18 +00:00
|
|
|
}
|
2024-03-03 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func benchmarkAggregatorsFlushSerial(b *testing.B, output string) {
|
|
|
|
a := newBenchAggregators(output)
|
2023-01-04 06:19:18 +00:00
|
|
|
defer a.MustStop()
|
|
|
|
|
2024-03-03 22:45:48 +00:00
|
|
|
var matchIdxs []byte
|
|
|
|
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.SetBytes(int64(len(benchSeries)))
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
matchIdxs = a.Push(benchSeries, matchIdxs)
|
|
|
|
for _, aggr := range a.as {
|
|
|
|
aggr.flush()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func benchmarkAggregatorsPush(b *testing.B, output string) {
|
|
|
|
a := newBenchAggregators(output)
|
|
|
|
defer a.MustStop()
|
|
|
|
|
|
|
|
const loops = 100
|
2024-02-29 00:39:00 +00:00
|
|
|
|
2023-01-04 06:19:18 +00:00
|
|
|
b.ReportAllocs()
|
2024-02-29 00:39:00 +00:00
|
|
|
b.SetBytes(int64(len(benchSeries) * loops))
|
2023-01-04 06:19:18 +00:00
|
|
|
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() {
|
2024-02-29 00:39:00 +00:00
|
|
|
for i := 0; i < loops; i++ {
|
2024-03-03 22:45:48 +00:00
|
|
|
matchIdxs = a.Push(benchSeries, matchIdxs)
|
2024-02-29 00:39:00 +00:00
|
|
|
}
|
2023-01-04 06:19:18 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-03-03 22:45:48 +00:00
|
|
|
func newBenchAggregators(output string) *Aggregators {
|
|
|
|
config := fmt.Sprintf(`
|
|
|
|
- match: http_requests_total
|
|
|
|
interval: 24h
|
|
|
|
without: [job]
|
|
|
|
outputs: [%q]
|
|
|
|
`, output)
|
|
|
|
pushFunc := func(tss []prompbmarshal.TimeSeries) {}
|
|
|
|
a, err := newAggregatorsFromData([]byte(config), pushFunc, 0)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("unexpected error when initializing aggregators: %s", err))
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2024-02-29 00:39:00 +00:00
|
|
|
func newBenchSeries(seriesCount int) []prompbmarshal.TimeSeries {
|
|
|
|
a := make([]string, seriesCount)
|
|
|
|
for j := 0; j < seriesCount; j++ {
|
|
|
|
s := fmt.Sprintf(`http_requests_total{path="/foo/%d",job="foo",instance="bar",pod="pod-123232312",namespace="kube-foo-bar",node="node-123-3434-443",`+
|
|
|
|
`some_other_label="foo-bar-baz",environment="prod",label1="value1",label2="value2",label3="value3"} %d`, j, j*1000)
|
|
|
|
a = append(a, s)
|
2023-01-04 06:19:18 +00:00
|
|
|
}
|
|
|
|
metrics := strings.Join(a, "\n")
|
|
|
|
return mustParsePromMetrics(metrics)
|
|
|
|
}
|
|
|
|
|
2024-02-29 00:39:00 +00:00
|
|
|
const seriesCount = 10_000
|
2023-01-04 06:19:18 +00:00
|
|
|
|
2024-02-29 00:39:00 +00:00
|
|
|
var benchSeries = newBenchSeries(seriesCount)
|