forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmark_test.go
66 lines (54 loc) · 1.16 KB
/
benchmark_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
package http
import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"net/http"
_ "net/http/pprof"
"testing"
"time"
)
const NProbers = 500
const NProbes = 120
var empty = struct{}{}
var reusableReq *http.Request
func createRequestObject() *http.Request {
req, _ := NewRequestForHTTPGetAction(&v1.HTTPGetAction{
Path: "/",
Port: intstr.IntOrString{IntVal: 5000},
Host: "",
Scheme: "http",
HTTPHeaders: nil,
}, &v1.Container{
Name: "test",
Image: "nginx",
Command: []string{"nginx"},
Args: []string{"--restart=Never"},
}, "127.0.0.1", "bench-marker")
return req
}
func worker(waiter chan struct{}, reuse bool) {
var req *http.Request
prober := New(false)
if reuse {
prober.SetRequestObj(createRequestObject())
}
for i := 0; i < NProbes; i++ {
if reuse {
req = nil
} else {
req = createRequestObject()
}
_, _, _ = prober.Probe(req, time.Second)
time.Sleep(time.Second)
}
waiter <- empty
}
func TestBench(t *testing.T) {
waiter := make(chan struct{}, NProbers)
for i := 0; i < NProbers; i++ {
go worker(waiter, false)
}
for i := 0; i < NProbers; i++ {
<-waiter
}
}