forked from valyala/httpteleport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_timing_test.go
145 lines (124 loc) · 4.12 KB
/
server_timing_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
package httpteleport
import (
"crypto/tls"
"github.com/valyala/fasthttp"
"runtime"
"sync/atomic"
"testing"
"time"
)
func BenchmarkEndToEndGetNoDelay1(b *testing.B) {
benchmarkEndToEndGet(b, 1, 0, CompressNone, false)
}
func BenchmarkEndToEndGetNoDelay10(b *testing.B) {
benchmarkEndToEndGet(b, 10, 0, CompressNone, false)
}
func BenchmarkEndToEndGetNoDelay100(b *testing.B) {
benchmarkEndToEndGet(b, 100, 0, CompressNone, false)
}
func BenchmarkEndToEndGetNoDelay1000(b *testing.B) {
benchmarkEndToEndGet(b, 1000, 0, CompressNone, false)
}
func BenchmarkEndToEndGetNoDelay10K(b *testing.B) {
benchmarkEndToEndGet(b, 10000, 0, CompressNone, false)
}
func BenchmarkEndToEndGetDelay1ms(b *testing.B) {
benchmarkEndToEndGet(b, 1000, time.Millisecond, CompressNone, false)
}
func BenchmarkEndToEndGetDelay2ms(b *testing.B) {
benchmarkEndToEndGet(b, 1000, 2*time.Millisecond, CompressNone, false)
}
func BenchmarkEndToEndGetDelay4ms(b *testing.B) {
benchmarkEndToEndGet(b, 1000, 4*time.Millisecond, CompressNone, false)
}
func BenchmarkEndToEndGetDelay8ms(b *testing.B) {
benchmarkEndToEndGet(b, 1000, 8*time.Millisecond, CompressNone, false)
}
func BenchmarkEndToEndGetDelay16ms(b *testing.B) {
benchmarkEndToEndGet(b, 1000, 16*time.Millisecond, CompressNone, false)
}
func BenchmarkEndToEndGetCompressNone(b *testing.B) {
benchmarkEndToEndGet(b, 1000, time.Millisecond, CompressNone, false)
}
func BenchmarkEndToEndGetCompressFlate(b *testing.B) {
benchmarkEndToEndGet(b, 1000, time.Millisecond, CompressFlate, false)
}
func BenchmarkEndToEndGetCompressSnappy(b *testing.B) {
benchmarkEndToEndGet(b, 1000, time.Millisecond, CompressSnappy, false)
}
func BenchmarkEndToEndGetTLSCompressNone(b *testing.B) {
benchmarkEndToEndGet(b, 1000, time.Millisecond, CompressNone, true)
}
func BenchmarkEndToEndGetTLSCompressFlate(b *testing.B) {
benchmarkEndToEndGet(b, 1000, time.Millisecond, CompressFlate, true)
}
func BenchmarkEndToEndGetTLSCompressSnappy(b *testing.B) {
benchmarkEndToEndGet(b, 1000, time.Millisecond, CompressSnappy, true)
}
func benchmarkEndToEndGet(b *testing.B, parallelism int, batchDelay time.Duration, compressType CompressType, isTLS bool) {
var tlsConfig *tls.Config
if isTLS {
tlsConfig = newTestServerTLSConfig()
}
var serverBatchDelay time.Duration
if batchDelay > 0 {
serverBatchDelay = 100 * time.Microsecond
}
expectedBody := "Hello world foobar baz aaa bbb ccc ddd eee gklj kljsdfsdf" +
"sdfasdaf asdf asdf dsa fasd fdasf afsgfdsg ertytrshdsf fds gf" +
"dfagsf asglsdkflaskdflkqowqiot asdkljlp 0293 4u09u0sd9fulksj lksfj lksdfj sdf" +
"sfjkko9u iodjsf-[9j lksdjf;lkasdj02r fsd fhjas;klfj asd;lfjwjfsd; "
s := &Server{
Handler: func(ctx *fasthttp.RequestCtx) {
ctx.SetBodyString(expectedBody)
},
Concurrency: parallelism * runtime.NumCPU(),
MaxBatchDelay: serverBatchDelay,
CompressType: compressType,
TLSConfig: tlsConfig,
}
serverStop, ln := newTestServerExt(s)
var cc []*Client
for i := 0; i < runtime.NumCPU(); i++ {
c := newTestClient(ln)
c.MaxPendingRequests = s.Concurrency
c.MaxBatchDelay = batchDelay
c.CompressType = compressType
if isTLS {
c.TLSConfig = &tls.Config{
InsecureSkipVerify: true,
}
}
cc = append(cc, c)
}
var clientIdx uint32
deadline := time.Now().Add(time.Hour)
b.SetParallelism(parallelism)
b.SetBytes(int64(len(expectedBody)))
b.RunParallel(func(pb *testing.PB) {
n := atomic.AddUint32(&clientIdx, 1)
c := cc[int(n)%len(cc)]
req := fasthttp.AcquireRequest()
resp := fasthttp.AcquireResponse()
for pb.Next() {
req.Header.SetHost("foobar")
req.SetRequestURI("/foo/bar")
if err := c.DoDeadline(req, resp, deadline); err != nil {
b.Fatalf("unexpected error: %s", err)
}
statusCode := resp.StatusCode()
if statusCode != fasthttp.StatusOK {
b.Fatalf("unexpected status code: %d. Expecting %d", statusCode, fasthttp.StatusOK)
}
body := resp.Body()
if string(body) != expectedBody {
b.Fatalf("unexpected body: %q. Expecting %q", body, expectedBody)
}
}
fasthttp.ReleaseResponse(resp)
fasthttp.ReleaseRequest(req)
})
if err := serverStop(); err != nil {
b.Fatalf("cannot shutdown server: %s", err)
}
}