This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 288
/
tracer_bench_test.go
198 lines (175 loc) Β· 5.39 KB
/
tracer_bench_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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// Copyright (c) 2019 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package jaeger
import (
"fmt"
"testing"
"time"
"github.com/uber/jaeger-client-go/thrift-gen/sampling"
"github.com/opentracing/opentracing-go"
)
type benchSampler struct {
name string
sampler Sampler
}
func (b benchSampler) String() string {
return b.name
}
func benchAdaptiveSampler(lateBinding bool, prob float64) Sampler {
ops := makeOps(5)
samplingRates := make([]*sampling.OperationSamplingStrategy, 5)
for i, op := range ops {
samplingRates[i] = &sampling.OperationSamplingStrategy{
Operation: op,
ProbabilisticSampling: &sampling.ProbabilisticSamplingStrategy{SamplingRate: prob},
}
}
strategies := &sampling.PerOperationSamplingStrategies{
DefaultSamplingProbability: prob,
DefaultLowerBoundTracesPerSecond: 0,
PerOperationStrategies: samplingRates,
}
return NewPerOperationSampler(PerOperationSamplerParams{
MaxOperations: 7,
OperationNameLateBinding: lateBinding,
Strategies: strategies,
})
// Change to below when running on <=2.19
//return newAdaptiveSampler(strategies, 7)
}
func BenchmarkTracer(b *testing.B) {
axes := []axis{
{
name: "sampler",
values: []interface{}{
benchSampler{name: "NeverSample", sampler: NewConstSampler(false)},
benchSampler{name: "AlwaysSample", sampler: NewConstSampler(true)},
benchSampler{name: "AdaptiveNeverSampleNoLateBinding", sampler: benchAdaptiveSampler(false, 0)},
benchSampler{name: "AdaptiveAlwaysSampleNoLateBinding", sampler: benchAdaptiveSampler(false, 1)},
benchSampler{name: "AdaptiveNeverSampleWithLateBinding", sampler: benchAdaptiveSampler(true, 0)},
benchSampler{name: "AdaptiveAlwaysSampleWithLateBinding", sampler: benchAdaptiveSampler(true, 1)},
},
},
// adding remote sampler on top of others did not show significant impact, keeping it off for now.
{name: "remoteSampler", values: []interface{}{false}},
{name: "children", values: []interface{}{false, true}},
// tags and ops dimensions did not show significant impact, so keeping to one value only for now.
{name: "tags", values: []interface{}{5}},
{name: "ops", values: []interface{}{10}},
}
for _, entry := range combinations(axes) {
b.Run(entry.encode(axes)+"cpus", func(b *testing.B) {
sampler := entry["sampler"].(benchSampler).sampler
if entry["remoteSampler"].(bool) {
sampler = NewRemotelyControlledSampler("service",
SamplerOptions.InitialSampler(sampler),
SamplerOptions.SamplingRefreshInterval(time.Minute),
)
}
options := benchOptions{
tags: entry["tags"].(int),
ops: entry["ops"].(int),
sampler: sampler,
children: entry["children"].(bool),
}
benchmarkTracer(b, options)
})
}
}
type benchOptions struct {
tags int
ops int
sampler Sampler
children bool
}
func benchmarkTracer(b *testing.B, options benchOptions) {
tags := makeStrings("tag", options.tags)
ops := makeOps(options.ops)
sampler := options.sampler
tracer, closer := NewTracer("service", sampler, NewNullReporter())
defer closer.Close()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var parent opentracing.SpanContext
var op int
for pb.Next() {
span := tracer.StartSpan(ops[op], opentracing.ChildOf(parent))
for i := range tags {
span.SetTag(tags[i], tags[i])
}
if options.children {
parent = span.Context()
}
span.Finish()
op = (op + 1) % len(ops)
}
})
}
func makeOps(num int) []string {
return makeStrings("span", num)
}
func makeStrings(prefix string, num int) []string {
values := make([]string, num)
for i := 0; i < num; i++ {
values[i] = fmt.Sprintf("%s%02d", prefix, i)
}
return values
}
// combinations takes a list axes and their values and
// returns a collection of entries which contain all combinations of each axis
// value with every other axis' values.
func combinations(axes []axis) []permutation {
if len(axes) == 0 {
return nil
}
if len(axes) == 1 {
return axes[0].entries()
}
var entries []permutation
// combos := combinations(axes[1:])
last := len(axes) - 1
combos := combinations(axes[:last])
for _, remaining := range combos {
for _, entry := range axes[last].entries() {
for k, v := range remaining {
entry[k] = v
}
entries = append(entries, entry)
}
}
return entries
}
type axis struct {
name string
values []interface{}
}
func (x axis) entries() []permutation {
items := make([]permutation, len(x.values))
for i, value := range x.values {
items[i] = permutation{x.name: value}
}
return items
}
type permutation map[string]interface{}
// encode converts a permutation into a string "k=v/k=v/...".
// The axes argument is used to provide a definitive order of keys.
func (p permutation) encode(axes []axis) string {
name := ""
for _, axis := range axes {
k := axis.name
v := p[k]
name = name + fmt.Sprintf("%s=%v", k, v) + "/"
}
return name
}