-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
162 lines (141 loc) · 4.16 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package main
import (
"encoding/csv"
"log"
"math/rand"
"os"
"strconv"
"sync/atomic"
"time"
cassowary "github.com/msaf1980/cassowary/pkg/client"
flag "github.com/spf13/pflag"
)
type URLIterator struct {
pos uint64
data [][]string
duration int64 // duration beetween from/until (s)
}
func (it *URLIterator) Next() *cassowary.Query {
for {
pos := atomic.AddUint64(&it.pos, 1)
if pos > uint64(len(it.data)) {
if !atomic.CompareAndSwapUint64(&it.pos, pos, 0) {
// retry
continue
}
pos = 0
} else {
pos--
}
until := rand.Int63n(86399) // random in day range
from := until + it.duration
url := "/render/?format=protobuf" + it.data[pos][0] + "&from=" + "now-" + strconv.FormatInt(from, 10) + "s&until=" + "now-" + strconv.FormatInt(until, 10) + "s"
return &cassowary.Query{Method: "GET", URL: url}
}
}
func NewURLIterator(duration int64, data [][]string) *URLIterator {
if len(data) == 0 {
return nil
}
return &URLIterator{data: data, duration: duration, pos: 0}
}
func main() {
targetsFile := flag.String("targets", "test.csv", "CSV file, at this time with one field - target")
baseURL := flag.String("base", "http://127.0.0.1:8889", "Base URL")
statFile := flag.String("status_file", "", "Statistic file for individual queries")
jsonFile := flag.String("json_file", "", "JSON file for aggregated statistic")
delay := flag.Duration("delay", 100*time.Millisecond, "Delay between requests")
duration := flag.Duration("duration", time.Minute, "Duration")
render_1_hour := flag.Int("render_1h", 8, "Users for 1 hour render queries")
render_1_day := flag.Int("render_1d", 2, "Users for 1 day render queries")
render_5_day := flag.Int("render_5d", 2, "Users for 5 days render queries")
render_30_day := flag.Int("render_30d", 0, "Users for 30 days render queries")
render_90_day := flag.Int("render_90d", 0, "Users for 90 days render queries")
render_365_day := flag.Int("render_365d", 0, "Users for 365 days render queries")
flag.Parse()
file, err := os.Open(*targetsFile)
if err != nil {
panic(err)
}
defer file.Close()
reader := csv.NewReader(file)
reader.FieldsPerRecord = 1
reader.Comment = '#'
targets, err := reader.ReadAll()
if err != nil {
log.Fatal(err)
}
targets = targets[1:]
it_render_1_hour := NewURLIterator(3600, targets)
it_render_1_day := NewURLIterator(86400, targets)
it_render_5_day := NewURLIterator(518400, targets)
it_render_30_day := NewURLIterator(2592000, targets)
it_render_90_day := NewURLIterator(7776000, targets)
it_render_365_day := NewURLIterator(31536000, targets)
cass := &cassowary.Cassowary{
BaseURL: *baseURL,
Duration: *duration,
Groups: []cassowary.QueryGroup{
{
Name: "Render 1 Hour",
ConcurrencyLevel: *render_1_hour,
Delay: *delay,
FileMode: true,
URLIterator: it_render_1_hour,
},
{
Name: "Render 1 Day",
ConcurrencyLevel: *render_1_day,
Delay: *delay,
FileMode: true,
URLIterator: it_render_1_day,
},
{
Name: "Render 6 Day",
ConcurrencyLevel: *render_5_day,
Delay: *delay,
FileMode: true,
URLIterator: it_render_5_day,
},
{
Name: "Render 30 Day",
ConcurrencyLevel: *render_30_day,
Delay: *delay,
FileMode: true,
URLIterator: it_render_30_day,
},
{
Name: "Render 90 Day",
ConcurrencyLevel: *render_90_day,
Delay: *delay,
FileMode: true,
URLIterator: it_render_90_day,
},
{
Name: "Render 365 Day",
ConcurrencyLevel: *render_365_day,
Delay: *delay,
FileMode: true,
URLIterator: it_render_365_day,
},
},
DisableTerminalOutput: false,
StatFile: *statFile,
}
metrics, metricsGroup, err := cass.Coordinate()
if err != nil {
panic(err)
}
for _, g := range cass.Groups {
if m, ok := metricsGroup[g.Name]; ok {
cassowary.OutPutResults(m)
}
}
cassowary.OutPutResults(metrics)
if *jsonFile != "" {
err = cassowary.OutPutJSON(*jsonFile, metrics, metricsGroup)
if err != nil {
log.Fatal(err)
}
}
}