mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-26 04:10:08 +01:00
f325410c26
- Return meta-labels for the discovered targets via promutils.Labels instead of map[string]string. This improves the speed of generating meta-labels for discovered targets by up to 5x. - Remove memory allocations in hot paths during ScrapeWork generation. The ScrapeWork contains scrape settings for a single discovered target. This improves the service discovery speed by up to 2x.
36 lines
751 B
Go
36 lines
751 B
Go
package kubernetes
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkPodGetTargetLabels(b *testing.B) {
|
|
r := bytes.NewBufferString(testPodsList)
|
|
objectsByKey, _, err := parsePodList(r)
|
|
if err != nil {
|
|
panic(fmt.Errorf("BUG: unexpected error: %s", err))
|
|
}
|
|
var o object
|
|
for _, srcObject := range objectsByKey {
|
|
o = srcObject
|
|
break
|
|
}
|
|
if o == nil {
|
|
panic(fmt.Errorf("BUG: expecting at least a single pod object"))
|
|
}
|
|
gw := newTestGroupWatcher()
|
|
b.ReportAllocs()
|
|
b.SetBytes(1)
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
for pb.Next() {
|
|
labelss := o.getTargetLabels(gw)
|
|
if len(labelss) != 1 {
|
|
panic(fmt.Errorf("BUG: unexpected number of labelss returned: %d; want 1", len(labelss)))
|
|
}
|
|
putLabelssToPool(labelss)
|
|
}
|
|
})
|
|
}
|