-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathprocessor_benchmark_test.go
More file actions
89 lines (78 loc) · 2.21 KB
/
processor_benchmark_test.go
File metadata and controls
89 lines (78 loc) · 2.21 KB
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
// Copyright (c) F5, Inc.
//
// This source code is licensed under the Apache License, Version 2.0 license found in the
// LICENSE file in the root directory of this source tree.
package logsgzipprocessor
import (
"context"
"crypto/rand"
"math/big"
"testing"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/processor"
)
// Helper to generate logs with variable size and content
func generateLogs(numRecords, recordSize int) plog.Logs {
logs := plog.NewLogs()
rl := logs.ResourceLogs().AppendEmpty()
sl := rl.ScopeLogs().AppendEmpty()
for range numRecords {
lr := sl.LogRecords().AppendEmpty()
content, _ := randomString(recordSize)
lr.Body().SetStr(content)
}
return logs
}
func randomString(n int) (string, error) {
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
b := make([]byte, n)
lettersSize := big.NewInt(int64(len(letters)))
for i := range b {
num, err := rand.Int(rand.Reader, lettersSize)
if err != nil {
return "", err
}
b[i] = letters[num.Int64()]
}
return string(b), nil
}
func BenchmarkGzipProcessor(b *testing.B) {
benchmarks := []struct {
name string
numRecords int
recordSize int
}{
{"SmallRecords", 100, 50},
{"MediumRecords", 100, 500},
{"LargeRecords", 100, 5000},
{"ManySmallRecords", 10000, 50},
}
for _, bm := range benchmarks {
b.Run(bm.name, func(b *testing.B) {
b.ReportAllocs()
consumer := &consumertest.LogsSink{}
p := newLogsGzipProcessor(consumer, processor.Settings{})
logs := generateLogs(bm.numRecords, bm.recordSize)
b.ResetTimer()
for range b.N {
_ = p.ConsumeLogs(context.Background(), logs)
}
})
}
}
// Optional: Benchmark with concurrency to simulate real pipeline load
func BenchmarkGzipProcessor_Concurrent(b *testing.B) {
// nolint:unused // concurrent runs require total parallel workers to be specified
const workers = 8
logs := generateLogs(1000, 1000)
consumer := &consumertest.LogsSink{}
p := newLogsGzipProcessor(consumer, processor.Settings{})
b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_ = p.ConsumeLogs(context.Background(), logs)
}
})
}