/
listoverload.go
106 lines (91 loc) · 2.52 KB
/
listoverload.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
package main
import (
"fmt"
"log"
"net/http"
"os"
"path"
"strings"
"time"
"github.com/metcalf/loadsim"
)
func listOverload() {
var keys []string
if envKeys := os.Getenv("STRIPE_KEYS"); envKeys != "" {
keys = strings.Split(envKeys, ",")
} else {
keys = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"}
}
start := time.Now()
workerCnt := 15
cfg := WorkerConfig{
Duration: 60 * time.Second,
Workers: workerCnt,
CPUs: 2,
Hosts: 2,
Backlog: 200,
Timeout: 40 * time.Second,
WallClockBurst: time.Duration(5*workerCnt) * time.Second,
WallClockRate: time.Duration(workerCnt) * time.Second,
ResourceMapper: func(req *http.Request) []loadsim.ResourceNeed {
if req.Method == "GET" {
return []loadsim.ResourceNeed{
{"time", 500},
{"CPU", 2000},
}
}
return []loadsim.ResourceNeed{
{"time", 1200},
{"CPU", 400},
}
},
}
prefix := "data"
simClock := loadsim.NewSimClock()
runners := []struct {
Name string
Run func(WorkerConfig, []loadsim.Agent, loadsim.Clock) []loadsim.Result
Clock loadsim.Clock
}{
{"sim", simRun, simClock},
//{"http", httpRun, &loadsim.WallClock{}},
}
listreq, err := http.NewRequest("GET", "https://qa-api.stripe.com/v1/charges?limit=100", nil)
if err != nil {
log.Fatal(err)
}
listreq.SetBasicAuth(keys[0], "")
for _, listAgents := range []int{1, 10, 60} {
for _, createInterval := range []time.Duration{0, 3 * time.Second} {
var rep string
if createInterval == 0 {
rep = "repeat"
} else {
rep = createInterval.String()
}
for _, runner := range runners {
var agents []loadsim.Agent
for i := 0; i < listAgents; i++ {
id := fmt.Sprintf("%s %s", listreq.Method, listreq.URL.Path)
delay := 20*time.Second + time.Millisecond*time.Duration(i*300)
agents = append(agents, &loadsim.DelayLimitAgent{
Agent: buildAgent(runner.Clock, id, listreq, nil, 0),
Delay: delay,
Limit: 60 * time.Second,
Clock: runner.Clock,
})
}
for i := 0; i < 6; i++ {
req, body := chargeCreate(keys[i+1])
id := fmt.Sprintf("%s %s", req.Method, req.URL.Path)
agents = append(agents, buildAgent(runner.Clock, id, req, body, createInterval))
}
results := runner.Run(cfg, agents, runner.Clock)
path := path.Join(prefix, fmt.Sprintf("%d_%s_%dlist@%s.tsv", start.Unix(), runner.Name, listAgents, rep))
if err := writeResults(results, path); err != nil {
log.Fatal(err)
}
}
}
}
}