mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-24 03:06:48 +01:00
955d36357c
Allocations are reduced by re-using the byte buffer when converting
labels to string keys.
```
name old allocs/op new allocs/op delta
GetStaleSeries-10 703 ± 0% 203 ± 0% ~ (p=1.000 n=1+1)
```
Signed-off-by: hagen1778 <roman@victoriametrics.com>
(cherry picked from commit b0c1f3d819
)
37 lines
723 B
Go
37 lines
723 B
Go
package rule
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
|
)
|
|
|
|
func BenchmarkGetStaleSeries(b *testing.B) {
|
|
ts := time.Now()
|
|
n := 100
|
|
payload := make([]prompbmarshal.TimeSeries, n)
|
|
for i := 0; i < n; i++ {
|
|
s := fmt.Sprintf("%d", i)
|
|
labels := toPromLabels(b,
|
|
"__name__", "foo", ""+
|
|
"instance", s,
|
|
"job", s,
|
|
"state", s,
|
|
)
|
|
payload = append(payload, newTimeSeriesPB([]float64{1}, []int64{ts.Unix()}, labels))
|
|
}
|
|
|
|
e := &executor{
|
|
previouslySentSeriesToRW: make(map[uint64]map[string][]prompbmarshal.Label),
|
|
}
|
|
ar := &AlertingRule{RuleID: 1}
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
e.getStaleSeries(ar, payload, ts)
|
|
}
|
|
}
|