Skip to content

Commit

Permalink
Added histograms for endpointregistry tests
Browse files Browse the repository at this point in the history
This is needed to improve the performance impact of this component.

Signed-off-by: Roman Zavodskikh <[email protected]>
  • Loading branch information
Roman Zavodskikh committed Oct 23, 2023
1 parent 7f45e4e commit b02f03f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ require (
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
github.com/benburkert/pbench v0.0.0-20160623210926-4ec5821845ef // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bmizerany/perks v0.0.0-20141205001514-d9a9656a3a4b // indirect
github.com/bytecodealliance/wasmtime-go/v3 v3.0.2 // indirect
Expand All @@ -93,6 +94,7 @@ require (
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gavv/monotime v0.0.0-20190418164738-30dba4353424 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZ
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/aryszka/jobqueue v0.0.2 h1:LYPhzklo0XFpVF+QtzfP9XRQPEsbJ2EW5Pur6pxxaS4=
github.com/aryszka/jobqueue v0.0.2/go.mod h1:SdxqI6HZ4E1Lss94tey5OfjcAu3bdCDWS1AQzzIN4m4=
github.com/benburkert/pbench v0.0.0-20160623210926-4ec5821845ef h1:+7ZJvJGiV4hUBdjhEDhfGdjBCOmhVi0YQ5n+6g/ei+k=
github.com/benburkert/pbench v0.0.0-20160623210926-4ec5821845ef/go.mod h1:hrhDSsc41bBqGejYXbvMh6qexfcC2vXjodP5gufwWyI=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bmizerany/perks v0.0.0-20141205001514-d9a9656a3a4b h1:AP/Y7sqYicnjGDfD5VcY4CIfh1hRXBUavxrvELjTiOE=
Expand Down Expand Up @@ -139,6 +141,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/gavv/monotime v0.0.0-20190418164738-30dba4353424 h1:Vh7rylVZRZCj6W41lRlP17xPk4Nq260H4Xo/DDYmEZk=
github.com/gavv/monotime v0.0.0-20190418164738-30dba4353424/go.mod h1:vmp8DIyckQMXOPl0AQVHt+7n5h7Gb7hS6CUydiV8QeA=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
Expand Down
56 changes: 26 additions & 30 deletions routing/endpointregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package routing_test
import (
"fmt"
"runtime/metrics"
"sync"
"testing"
"time"

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

b.Run(name, func(b *testing.B) {
percentileBench := pbench.New(b)
percentileBench.ReportPercentile(0.95)
percentileBench.ReportPercentile(0.99)

percentileBench.Run(name, func(b *pbench.B) {
r := routing.NewEndpointRegistry(routing.RegistryOptions{})
for i := 1; i < mapSize; i++ {
r.IncInflightRequest(fmt.Sprintf("foo-%d", i))
}
r.IncInflightRequest(key)
r.IncInflightRequest(key)

wg := sync.WaitGroup{}
b.ResetTimer()
for i := 0; i < goroutines; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for n := 0; n < b.N/goroutines; n++ {
r.IncInflightRequest(key)
}
}()
}
wg.Wait()

printTotalMutexWaitTime(b)
b.RunParallel(func(pb *pbench.PB) {
for pb.Next() {
r.IncInflightRequest(key)
}
})
})

printTotalMutexWaitTime(b)
}

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

b.Run(name, func(b *testing.B) {
percentileBench := pbench.New(b)
percentileBench.ReportPercentile(0.95)
percentileBench.ReportPercentile(0.99)

percentileBench.Run(name, func(b *pbench.B) {
r := routing.NewEndpointRegistry(routing.RegistryOptions{})
for i := 1; i < mapSize; i++ {
r.IncInflightRequest(fmt.Sprintf("foo-%d", i))
}
r.IncInflightRequest(key)
r.IncInflightRequest(key)
b.ResetTimer()

var dummy int64
wg := sync.WaitGroup{}
b.ResetTimer()
for i := 0; i < goroutines; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for n := 0; n < b.N/goroutines; n++ {
dummy = r.GetMetrics(key).InflightRequests()
}
}()
}
b.RunParallel(func(pb *pbench.PB) {
for pb.Next() {
dummy = r.GetMetrics(key).InflightRequests()
}
})
dummy++
wg.Wait()

printTotalMutexWaitTime(b)
})

printTotalMutexWaitTime(b)
}

func BenchmarkGetInflightRequests(b *testing.B) {
Expand Down

0 comments on commit b02f03f

Please sign in to comment.