-
Notifications
You must be signed in to change notification settings - Fork 314
/
bombardier_performance_test.go
71 lines (65 loc) · 1.68 KB
/
bombardier_performance_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
package main
import (
"flag"
"runtime"
"testing"
"time"
)
var (
serverPort = flag.String("port", "8080", "port to use for benchmarks")
clientType = flag.String("client-type", "fasthttp",
"client to use in benchmarks")
)
var (
longDuration = 9001 * time.Hour
highRate = uint64(1000000)
)
func BenchmarkBombardierSingleReqPerf(b *testing.B) {
addr := "localhost:" + *serverPort
benchmarkFireRequest(config{
numConns: defaultNumberOfConns,
numReqs: nil,
duration: &longDuration,
url: ParseURLOrPanic("http://" + addr),
headers: new(headersList),
timeout: defaultTimeout,
method: "GET",
body: "",
printLatencies: false,
clientType: clientTypeFromString(*clientType),
format: knownFormat("json"),
}, b)
}
func BenchmarkBombardierRateLimitPerf(b *testing.B) {
addr := "localhost:" + *serverPort
benchmarkFireRequest(config{
numConns: defaultNumberOfConns,
numReqs: nil,
duration: &longDuration,
url: ParseURLOrPanic("http://" + addr),
headers: new(headersList),
timeout: defaultTimeout,
method: "GET",
body: "",
printLatencies: false,
rate: &highRate,
clientType: clientTypeFromString(*clientType),
format: knownFormat("json"),
}, b)
}
func benchmarkFireRequest(c config, bm *testing.B) {
b, e := newBombardier(c)
if e != nil {
bm.Error(e)
}
b.disableOutput()
bm.SetParallelism(int(defaultNumberOfConns) / runtime.NumCPU())
bm.ResetTimer()
bm.RunParallel(func(pb *testing.PB) {
done := b.barrier.done()
for pb.Next() {
b.ratelimiter.pace(done)
b.performSingleRequest()
}
})
}