forked from grafana/xk6-loki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch_test.go
83 lines (73 loc) · 1.76 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
package loki
import (
"context"
"testing"
gofakeit "github.com/brianvoe/gofakeit/v6"
"go.k6.io/k6/lib"
"go.k6.io/k6/stats"
)
func BenchmarkNewBatch(b *testing.B) {
samples := make(chan stats.SampleContainer)
state := &lib.State{
Samples: samples,
VUID: 15,
}
ctx, cancel := context.WithCancel(context.Background())
ctx = lib.WithState(ctx, 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)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = newBatch(ctx, labels, streams, minBatchSize, maxBatchSize)
}
}
func BenchmarkEncode(b *testing.B) {
samples := make(chan stats.SampleContainer)
state := &lib.State{
Samples: samples,
VUID: 15,
}
ctx, cancel := context.WithCancel(context.Background())
ctx = lib.WithState(ctx, 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)
b.ReportAllocs()
batch := newBatch(ctx, labels, streams, minBatchSize, maxBatchSize)
b.Run("encode protobuf", func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = batch.createPushRequest()
}
})
b.Run("encode json", func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = batch.createJSONPushRequest()
}
})
}