-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (58 loc) · 1.25 KB
/
main.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"
"fmt"
"os"
"os/signal"
"time"
)
const defaultNumClients = 500
const defaultBackend = "bin"
const defaultRate = 10
func setupInterruptHandler(r *Reactor) {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
go func() {
var lastTime time.Time
for {
select {
case <-c:
now := time.Now()
if now.Sub(lastTime) < 500*time.Millisecond {
os.Exit(1)
}
lastTime = now
fmt.Printf("\r")
if backendSummary, ok := r.Backend.(BackendSummary); ok {
backendSummary.Status()
}
}
}
}()
}
func main() {
backend := flag.String("backend", defaultBackend, "queue backend: bin, noop, random")
numClients := flag.Int("clients", defaultNumClients, "number of clients")
rate := flag.Int("rate", defaultRate, "queue exit rate")
flag.Parse()
clients := make([]*Client, *numClients)
for i := 0; i < *numClients; i++ {
clients[i] = NewClient()
}
var backendImpl Backend
switch *backend {
case "bin":
backendImpl = NewBinBackend(uint(*rate))
case "random":
backendImpl = NewRandomBackend(uint(*rate))
case "noop":
backendImpl = &NoopBackend{}
}
reactor := &Reactor{
Clients: clients,
Backend: backendImpl,
}
setupInterruptHandler(reactor)
reactor.Run()
reactor.Summary()
}