-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
97 lines (85 loc) · 2.81 KB
/
main.go
File metadata and controls
97 lines (85 loc) · 2.81 KB
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
package main
import (
"github.com/kpister/go2wrk/https"
"github.com/kpister/go2wrk/node"
"github.com/kpister/go2wrk/structs"
"github.com/kpister/go2wrk/connection"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"
)
var (
tps structs.TPSReport
connections = flag.Int("c", 0, "the max numbers of connections used")
samples = flag.Int("s", 0, "the max numbers of connections used")
testTime = flag.Float64("t", 0.0, "the total runtime of the test calls")
configFile = flag.String("f", "routes.json", "the file to read routes from")
outputDirectory = flag.String("o", "", "the output directory to work with")
certFile = flag.String("cert", "someCertFile", "A PEM eoncoded certificate file.")
keyFile = flag.String("key", "someKeyFile", "A PEM encoded private key file.")
caFile = flag.String("CA", "someCertCAFile", "A PEM eoncoded CA's certificate file.")
disableKeepAlives = flag.Bool("k", true, "if keep-alives are disabled")
insecure = flag.Bool("i", true, "TLS checks are disabled")
help = flag.Bool("h", false, "for usage")
)
func init() {
flag.Parse()
if *help {
flag.PrintDefaults()
os.Exit(1)
}
readConfig(*configFile)
initializeTPS()
}
func initializeTPS() {
if *samples != 0 {
tps.Samples = *samples
}
if *connections != 0 {
tps.Connections = *connections
}
tps.Transport = https.SetTLS(*disableKeepAlives, *insecure, *certFile, *keyFile, *caFile)
}
func readConfig(configFile string) {
configData, err := ioutil.ReadFile(configFile)
if err != nil {
fmt.Println(err)
}
err = json.Unmarshal(configData, &tps)
if err != nil {
fmt.Println(err)
}
}
func main() {
// warmup cache on first route
// TODO: may want to make this more general in case Urls[0] is not always the first one hit
fmt.Println("Warming up cache on route " + tps.Routes[0].Url)
warmupTPS := structs.TPSReport{
Routes: append(make([]structs.Route, 0), tps.Routes[0]),
Connections: 10,
MaxTestTime: 4.0,
Frequency: 4,
Transport: https.SetTLS(false, *insecure, *certFile, *keyFile, *caFile),
}
// Calculate the 99% by storing results := node.Warmup
node.Warmup(warmupTPS)
fmt.Println("Warmup complete")
// Perform some stats on results
// tails, threshold := stats.Perform(results)
// Tails is our bootstrap struct, threshold is the latency to be in the 99th percentile
// Start bootstrapping here on tails
// tails.bootstrap()
// node.Run will now need to add to tails if response latency > threshold
fmt.Println("Starting testing")
connection.Init(tps)
if tps.BreakMe {
for ; tps.Connections < tps.MaxConnections; tps.Connections *= 2 {
node.Run(tps, *outputDirectory, tps.Connections)
tps.Samples *=2
}
} else {
node.Run(tps, *outputDirectory, 0)
}
}