-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_test.go
100 lines (89 loc) · 1.99 KB
/
batch_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package logstore
import (
"context"
"testing"
gofakeit "github.com/brianvoe/gofakeit/v6"
"go.k6.io/k6/js/modulestest"
"go.k6.io/k6/lib"
"go.k6.io/k6/metrics"
)
func BenchmarkNewBatch(b *testing.B) {
samples := make(chan metrics.SampleContainer)
state := &lib.State{
Samples: samples,
VUID: 15,
}
ctx, cancel := context.WithCancel(context.Background())
vu := &modulestest.VU{
CtxField: ctx,
StateField: state,
}
defer cancel()
defer close(samples)
go func() { // this is so that we read the send samples
for range samples {
}
}()
faker := gofakeit.New(12345)
cardinalities := map[string]int{
"app": 5,
"namespace": 10,
"pod": 100,
}
streams, minBatchSize, maxBatchSize := 5, 500, 1000
labels := newLabelPool(faker, cardinalities)
c := Client{
vu: vu,
labels: transformLabelPool(labels),
}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = c.newBatch(streams, minBatchSize, maxBatchSize)
}
}
func BenchmarkEncode(b *testing.B) {
samples := make(chan metrics.SampleContainer)
state := &lib.State{
Samples: samples,
VUID: 15,
}
ctx, cancel := context.WithCancel(context.Background())
vu := &modulestest.VU{
CtxField: ctx,
StateField: state,
}
defer cancel()
defer close(samples)
go func() { // this is so that we read the send samples
for range samples {
}
}()
faker := gofakeit.New(12345)
cardinalities := map[string]int{
"app": 5,
"namespace": 10,
"pod": 100,
}
streams, minBatchSize, maxBatchSize := 5, 500, 1000
labels := newLabelPool(faker, cardinalities)
c := Client{
vu: vu,
labels: transformLabelPool(labels),
}
batch := c.newBatch(streams, minBatchSize, maxBatchSize)
b.Run("encode protobuf", func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, _ = batch.encodeSnappy()
}
})
b.Run("encode json", func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, _ = batch.encodeJSON()
}
})
}