Skip to content

Commit b02f03f

Browse files
author
Roman Zavodskikh
committed
Added histograms for endpointregistry tests
This is needed to improve the performance impact of this component. Signed-off-by: Roman Zavodskikh <[email protected]>
1 parent 7f45e4e commit b02f03f

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ require (
7272
github.com/OneOfOne/xxhash v1.2.8 // indirect
7373
github.com/agnivade/levenshtein v1.1.1 // indirect
7474
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
75+
github.com/benburkert/pbench v0.0.0-20160623210926-4ec5821845ef // indirect
7576
github.com/beorn7/perks v1.0.1 // indirect
7677
github.com/bmizerany/perks v0.0.0-20141205001514-d9a9656a3a4b // indirect
7778
github.com/bytecodealliance/wasmtime-go/v3 v3.0.2 // indirect
@@ -93,6 +94,7 @@ require (
9394
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
9495
github.com/felixge/httpsnoop v1.0.3 // indirect
9596
github.com/fsnotify/fsnotify v1.6.0 // indirect
97+
github.com/gavv/monotime v0.0.0-20190418164738-30dba4353424 // indirect
9698
github.com/go-ini/ini v1.67.0 // indirect
9799
github.com/go-logr/logr v1.2.4 // indirect
98100
github.com/go-logr/stdr v1.2.2 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZ
3939
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
4040
github.com/aryszka/jobqueue v0.0.2 h1:LYPhzklo0XFpVF+QtzfP9XRQPEsbJ2EW5Pur6pxxaS4=
4141
github.com/aryszka/jobqueue v0.0.2/go.mod h1:SdxqI6HZ4E1Lss94tey5OfjcAu3bdCDWS1AQzzIN4m4=
42+
github.com/benburkert/pbench v0.0.0-20160623210926-4ec5821845ef h1:+7ZJvJGiV4hUBdjhEDhfGdjBCOmhVi0YQ5n+6g/ei+k=
43+
github.com/benburkert/pbench v0.0.0-20160623210926-4ec5821845ef/go.mod h1:hrhDSsc41bBqGejYXbvMh6qexfcC2vXjodP5gufwWyI=
4244
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
4345
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
4446
github.com/bmizerany/perks v0.0.0-20141205001514-d9a9656a3a4b h1:AP/Y7sqYicnjGDfD5VcY4CIfh1hRXBUavxrvELjTiOE=
@@ -139,6 +141,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
139141
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
140142
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
141143
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
144+
github.com/gavv/monotime v0.0.0-20190418164738-30dba4353424 h1:Vh7rylVZRZCj6W41lRlP17xPk4Nq260H4Xo/DDYmEZk=
145+
github.com/gavv/monotime v0.0.0-20190418164738-30dba4353424/go.mod h1:vmp8DIyckQMXOPl0AQVHt+7n5h7Gb7hS6CUydiV8QeA=
142146
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
143147
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
144148
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=

routing/endpointregistry_test.go

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package routing_test
33
import (
44
"fmt"
55
"runtime/metrics"
6-
"sync"
76
"testing"
87
"time"
98

9+
"github.com/benburkert/pbench"
1010
"github.com/stretchr/testify/assert"
1111
"github.com/zalando/skipper/eskip"
1212
"github.com/zalando/skipper/routing"
@@ -131,29 +131,27 @@ func benchmarkIncInflightRequests(b *testing.B, name string, goroutines int) {
131131
const key string = "some key"
132132
const mapSize int = 10000
133133

134-
b.Run(name, func(b *testing.B) {
134+
percentileBench := pbench.New(b)
135+
percentileBench.ReportPercentile(0.95)
136+
percentileBench.ReportPercentile(0.99)
137+
138+
percentileBench.Run(name, func(b *pbench.B) {
135139
r := routing.NewEndpointRegistry(routing.RegistryOptions{})
136140
for i := 1; i < mapSize; i++ {
137141
r.IncInflightRequest(fmt.Sprintf("foo-%d", i))
138142
}
139143
r.IncInflightRequest(key)
140144
r.IncInflightRequest(key)
141-
142-
wg := sync.WaitGroup{}
143145
b.ResetTimer()
144-
for i := 0; i < goroutines; i++ {
145-
wg.Add(1)
146-
go func() {
147-
defer wg.Done()
148-
for n := 0; n < b.N/goroutines; n++ {
149-
r.IncInflightRequest(key)
150-
}
151-
}()
152-
}
153-
wg.Wait()
154146

155-
printTotalMutexWaitTime(b)
147+
b.RunParallel(func(pb *pbench.PB) {
148+
for pb.Next() {
149+
r.IncInflightRequest(key)
150+
}
151+
})
156152
})
153+
154+
printTotalMutexWaitTime(b)
157155
}
158156

159157
func BenchmarkIncInflightRequests(b *testing.B) {
@@ -167,31 +165,29 @@ func benchmarkGetInflightRequests(b *testing.B, name string, goroutines int) {
167165
const key string = "some key"
168166
const mapSize int = 10000
169167

170-
b.Run(name, func(b *testing.B) {
168+
percentileBench := pbench.New(b)
169+
percentileBench.ReportPercentile(0.95)
170+
percentileBench.ReportPercentile(0.99)
171+
172+
percentileBench.Run(name, func(b *pbench.B) {
171173
r := routing.NewEndpointRegistry(routing.RegistryOptions{})
172174
for i := 1; i < mapSize; i++ {
173175
r.IncInflightRequest(fmt.Sprintf("foo-%d", i))
174176
}
175177
r.IncInflightRequest(key)
176178
r.IncInflightRequest(key)
179+
b.ResetTimer()
177180

178181
var dummy int64
179-
wg := sync.WaitGroup{}
180-
b.ResetTimer()
181-
for i := 0; i < goroutines; i++ {
182-
wg.Add(1)
183-
go func() {
184-
defer wg.Done()
185-
for n := 0; n < b.N/goroutines; n++ {
186-
dummy = r.GetMetrics(key).InflightRequests()
187-
}
188-
}()
189-
}
182+
b.RunParallel(func(pb *pbench.PB) {
183+
for pb.Next() {
184+
dummy = r.GetMetrics(key).InflightRequests()
185+
}
186+
})
190187
dummy++
191-
wg.Wait()
192-
193-
printTotalMutexWaitTime(b)
194188
})
189+
190+
printTotalMutexWaitTime(b)
195191
}
196192

197193
func BenchmarkGetInflightRequests(b *testing.B) {

0 commit comments

Comments
 (0)