You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: boomer.go
+47-22
Original file line number
Diff line number
Diff line change
@@ -5,25 +5,66 @@ import (
5
5
"log"
6
6
"os"
7
7
"os/signal"
8
-
"runtime"
9
8
"strings"
10
9
"syscall"
10
+
"sync"
11
+
"sync/atomic"
12
+
"runtime"
11
13
)
12
14
13
-
// Run accepts a slice of Task and connects
14
-
// to a locust master.
15
-
funcRun(tasks...*Task) {
15
+
varrunTasksstring
16
+
varmaxRPSint64
17
+
varmaxRPSThresholdint64
18
+
varmaxRPSEnabled=false
19
+
varmaxRPSControlChannel=make(chanbool)
20
+
21
+
varinitteduint32
22
+
varinitMutex= sync.Mutex{}
23
+
24
+
// Init boomer
25
+
funcinitBoomer() {
16
26
17
27
// support go version below 1.5
18
28
runtime.GOMAXPROCS(runtime.NumCPU())
19
29
30
+
flag.Int64Var(&maxRPS, "max-rps", 0, "Max RPS that boomer can generate.")
31
+
flag.StringVar(&runTasks, "run-tasks", "", "Run tasks without connecting to the master, multiply tasks is separated by comma. Usually, it's for debug purpose.")
32
+
flag.StringVar(&masterHost, "master-host", "127.0.0.1", "Host or IP address of locust master for distributed load testing. Defaults to 127.0.0.1.")
33
+
flag.IntVar(&masterPort,"master-port", 5557, "The port to connect to that is used by the locust master for distributed load testing. Defaults to 5557.")
34
+
flag.StringVar(&rpc,"rpc", "zeromq", "Choose zeromq or tcp socket to communicate with master, don't mix them up.")
35
+
20
36
if!flag.Parsed() {
21
37
flag.Parse()
22
38
}
23
39
24
-
if*runTasks!="" {
40
+
ifmaxRPS>0 {
41
+
log.Println("Max RPS that boomer may generate is limited to", maxRPS)
42
+
maxRPSEnabled=true
43
+
}
44
+
45
+
initEvents()
46
+
initStats()
47
+
48
+
// done
49
+
atomic.StoreUint32(&initted, 1)
50
+
}
51
+
52
+
// Run accepts a slice of Task and connects
53
+
// to a locust master.
54
+
funcRun(tasks...*Task) {
55
+
56
+
ifatomic.LoadUint32(&initted) ==1 {
57
+
panic("Don't call boomer.Run() more than once.")
58
+
}
59
+
60
+
// init boomer
61
+
initMutex.Lock()
62
+
initBoomer()
63
+
initMutex.Unlock()
64
+
65
+
ifrunTasks!="" {
25
66
// Run tasks without connecting to the master.
26
-
taskNames:=strings.Split(*runTasks, ",")
67
+
taskNames:=strings.Split(runTasks, ",")
27
68
for_, task:=rangetasks {
28
69
iftask.Name=="" {
29
70
continue
@@ -39,11 +80,6 @@ func Run(tasks ...*Task) {
39
80
return
40
81
}
41
82
42
-
ifmaxRPS>0 {
43
-
log.Println("Max RPS that boomer may generate is limited to", maxRPS)
44
-
maxRPSEnabled=true
45
-
}
46
-
47
83
varr*runner
48
84
client:=newClient()
49
85
r=&runner{
@@ -67,14 +103,3 @@ func Run(tasks ...*Task) {
67
103
log.Println("shut down")
68
104
69
105
}
70
-
71
-
varrunTasks*string
72
-
varmaxRPSint64
73
-
varmaxRPSThresholdint64
74
-
varmaxRPSEnabled=false
75
-
varmaxRPSControlChannel=make(chanbool)
76
-
77
-
funcinit() {
78
-
runTasks=flag.String("run-tasks", "", "Run tasks without connecting to the master, multiply tasks is separated by comma. Usually, it's for debug purpose.")
79
-
flag.Int64Var(&maxRPS, "max-rps", 0, "Max RPS that boomer can generate.")
0 commit comments