Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add latencies for 2xx responses #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions bombardier.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ type bombardier struct {
ratelimiter limiter
wg sync.WaitGroup

timeTaken time.Duration
latencies *uhist.Histogram
requests *fhist.Histogram
timeTaken time.Duration
latencies *uhist.Histogram
latencies2xx *uhist.Histogram
requests *fhist.Histogram

client client
doneChan chan struct{}
Expand Down Expand Up @@ -66,6 +67,7 @@ func newBombardier(c config) (*bombardier, error) {
b := new(bombardier)
b.conf = c
b.latencies = uhist.Default()
b.latencies2xx = uhist.Default()
b.requests = fhist.Default()

if b.conf.testType() == counted {
Expand Down Expand Up @@ -236,6 +238,7 @@ func (b *bombardier) writeStatistics(
counter = &b.req1xx
case 2:
counter = &b.req2xx
b.latencies2xx.Increment(usTaken)
case 3:
counter = &b.req3xx
case 4:
Expand Down Expand Up @@ -388,8 +391,9 @@ func (b *bombardier) gatherInfo() internal.TestInfo {
Req5XX: b.req5xx,
Others: b.others,

Latencies: b.latencies,
Requests: b.requests,
Latencies: b.latencies,
Latencies2XX: b.latencies2xx,
Requests: b.requests,
},
}

Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ github.com/klauspost/compress v1.11.8 h1:difgzQsp5mdAz9v8lm3P/I+EpDKMU/6uTMw1y1F
github.com/klauspost/compress v1.11.8/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
Expand All @@ -38,6 +39,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
Expand All @@ -46,8 +48,10 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.21.0 h1:fJjaQ7cXdaSF9vDBujlHLDGj7AgoMTMIXvICeePzYbU=
github.com/valyala/fasthttp v1.21.0/go.mod h1:jjraHZVbKOXftJfsOYoAjaeygpj5hr8ermTRJNroD7A=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a h1:0R4NLDRDZX6JcmhJgXi5E4b8Wg84ihbmUKp/GvSPEzc=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0 h1:5kGOVHlq0euqwzgTC9Vu15p6fV1Wi0ArVi8da2urnVg=
Expand All @@ -61,10 +65,12 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
80 changes: 80 additions & 0 deletions internal/histogram_aggregates_float64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package internal

import (
"errors"
"math"
"sort"
)

// ReadonlyFloat64Histogram is a readonly histogram with float64 keys
type ReadonlyFloat64Histogram interface {
Get(float64) uint64
VisitAll(func(float64, uint64) bool)
Count() uint64
}

// float64Aggregates holds aggregates calculated from float64 histograms
type float64Aggregates struct {
Sum float64
Count uint64
Max float64
Pairs []struct {
k float64
v uint64
}
}

// NewFloat64HistogramAggregates calculates aggregates from a ReadonlyFloat64Histogram
func NewFloat64HistogramAggregates(histogram ReadonlyFloat64Histogram) (*float64Aggregates, error) {
aggregates := new(float64Aggregates)
aggregates.Pairs = make([]struct {
k float64
v uint64
}, 0, histogram.Count())
histogram.VisitAll(func(f float64, c uint64) bool {
if math.IsInf(f, 0) || math.IsNaN(f) {
return true
}
if f > aggregates.Max {
aggregates.Max = f
}
aggregates.Sum += f * float64(c)
aggregates.Count += c
aggregates.Pairs = append(aggregates.Pairs, struct {
k float64
v uint64
}{f, c})
return true
})
if aggregates.Count < 1 {
return nil, errors.New("Not enough values")
}
sort.Slice(aggregates.Pairs, func(i, j int) bool {
return aggregates.Pairs[i].k < aggregates.Pairs[j].k
})
return aggregates, nil
}

// percentilesMap gives the values for a list of percentiles given as input
func (a *float64Aggregates) percentilesMap(percentiles []float64) map[float64]float64 {
percentilesMap := map[float64]float64{}
for _, pc := range percentiles {
if _, calculated := percentilesMap[pc]; calculated {
continue
}
if pc < 0 || pc > 1 {
// Drop percentiles outside of [0, 1] range
continue
}
rank := uint64(pc*float64(a.Count) + 0.5)
total := uint64(0)
for _, p := range a.Pairs {
total += p.v
if total >= rank {
percentilesMap[pc] = p.k
break
}
}
}
return percentilesMap
}
73 changes: 73 additions & 0 deletions internal/histogram_aggregates_uint64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package internal

import (
"errors"
"sort"
)

// ReadonlyUint64Histogram is a readonly histogram with uint64 keys
type ReadonlyUint64Histogram interface {
Get(uint64) uint64
VisitAll(func(uint64, uint64) bool)
Count() uint64
}

// uint64Aggregates holds aggregates calculated from uint64 histograms
type uint64Aggregates struct {
Sum uint64
Count uint64
Max uint64
Pairs []struct {
k uint64
v uint64
}
}

// NewUint64HistogramAggregates calculates aggregates from a ReadonlyUint64Histogram
func NewUint64HistogramAggregates(histogram ReadonlyUint64Histogram) (*uint64Aggregates, error) {
aggregates := new(uint64Aggregates)
aggregates.Pairs = make([]struct {
k uint64
v uint64
}, 0, histogram.Count())
histogram.VisitAll(func(f uint64, c uint64) bool {
if f > aggregates.Max {
aggregates.Max = f
}
aggregates.Sum += f * c
aggregates.Count += c
aggregates.Pairs = append(aggregates.Pairs, struct{ k, v uint64 }{f, c})
return true
})
if aggregates.Count < 1 {
return nil, errors.New("Not enough values")
}
sort.Slice(aggregates.Pairs, func(i, j int) bool {
return aggregates.Pairs[i].k < aggregates.Pairs[j].k
})
return aggregates, nil
}

// percentilesMap gives the values for a list of percentiles given as input
func (a *uint64Aggregates) percentilesMap(percentiles []float64) map[float64]uint64 {
percentilesMap := map[float64]uint64{}
for _, pc := range percentiles {
if _, calculated := percentilesMap[pc]; calculated {
continue
}
if pc < 0 || pc > 1 {
// Drop percentiles outside of [0, 1] range
continue
}
rank := uint64(pc*float64(a.Count) + 0.5)
total := uint64(0)
for _, p := range a.Pairs {
total += p.v
if total >= rank {
percentilesMap[pc] = p.k
break
}
}
}
return percentilesMap
}
Loading