-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (63 loc) · 1.57 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
72
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
"runtime"
"time"
)
var (
n = flag.Int("n", 1, "number of workers")
i = flag.Int("i", 10, "number of query executions")
t = flag.Int("t", 10000, "client timeout (in ms)")
f = flag.String("f", "obs-queries.csv", "queries will be read from this file")
serverURL = flag.String("url", "http://localhost:9201", "Promscale server URL")
cpus = flag.Int("cpus", runtime.NumCPU(), "number of CPUs to use for go runtime")
)
func main() {
ctx := context.Background()
flag.Parse()
fmt.Println("psb - benchmarking Promscale")
queries, err := PrepareQueries(*f)
if err != nil {
log.Printf("could not build queries. err: %+v\n", err)
os.Exit(1)
}
fmt.Printf("Found %d queries in input file: %s\n", len(queries), *f)
w := Work{
numWorkers: *n,
numIterations: *i,
cpus: *cpus,
serverURL: *serverURL,
clientTimeout: *t,
}
w.PrintConf()
if res := w.Health(ctx); res.isError {
log.Println("could not confirm health of given Promscale server, is it running?")
log.Println("quitting")
os.Exit(1)
}
log.Println("Promscale health OK, moving to benchmark")
// handle CtrlC
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
log.Println("Ctrl-C handler registerd")
<-c
log.Println("stopping now")
w.Stop()
}()
time.Sleep(1 * time.Second)
log.Println("ready to benchmark")
for i, q := range queries {
if !w.stopRequested {
fmt.Println("#", i, "query:", q.queryStr)
w.Init(q)
w.Run(ctx)
w.PrintReport()
}
}
}