-
Notifications
You must be signed in to change notification settings - Fork 48
/
report_save_upload.go
331 lines (296 loc) · 10 KB
/
report_save_upload.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
// Copyright 2017 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package dbtester
import (
"fmt"
"math"
"path/filepath"
"strings"
"time"
"github.com/etcd-io/dbtester/dbtesterpb"
"github.com/etcd-io/dbtester/pkg/remotestorage"
"github.com/coreos/etcd/pkg/report"
humanize "github.com/dustin/go-humanize"
"github.com/gyuho/dataframe"
)
// DiskSpaceUsageSummaryColumns defines summary columns.
var DiskSpaceUsageSummaryColumns = []string{
"INDEX",
"DATABASE-ENDPOINT",
"DISK-SPACE-USAGE",
"DISK-SPACE-USAGE-BYTES-NUM",
}
// SaveDiskSpaceUsageSummary saves data size summary.
func (cfg *Config) SaveDiskSpaceUsageSummary(databaseID string, idxToResponse map[int]dbtesterpb.Response) error {
gcfg, ok := cfg.DatabaseIDToConfigClientMachineAgentControl[databaseID]
if !ok {
return fmt.Errorf("%q does not exist", databaseID)
}
c1 := dataframe.NewColumn(DiskSpaceUsageSummaryColumns[0])
c2 := dataframe.NewColumn(DiskSpaceUsageSummaryColumns[1])
c3 := dataframe.NewColumn(DiskSpaceUsageSummaryColumns[2])
c4 := dataframe.NewColumn(DiskSpaceUsageSummaryColumns[3])
for i := range gcfg.DatabaseEndpoints {
c1.PushBack(dataframe.NewStringValue(i))
c2.PushBack(dataframe.NewStringValue(gcfg.DatabaseEndpoints[i]))
c3.PushBack(dataframe.NewStringValue(humanize.Bytes(uint64(idxToResponse[i].DiskSpaceUsageBytes))))
c4.PushBack(dataframe.NewStringValue(idxToResponse[i].DiskSpaceUsageBytes))
}
fr := dataframe.New()
if err := fr.AddColumn(c1); err != nil {
return err
}
if err := fr.AddColumn(c2); err != nil {
return err
}
if err := fr.AddColumn(c3); err != nil {
return err
}
if err := fr.AddColumn(c4); err != nil {
return err
}
return fr.CSV(cfg.ConfigClientMachineInitial.ServerDiskSpaceUsageSummaryPath)
}
func (cfg *Config) saveDataLatencyDistributionSummary(st report.Stats) {
fr := dataframe.New()
c1 := dataframe.NewColumn("TOTAL-SECONDS")
c1.PushBack(dataframe.NewStringValue(fmt.Sprintf("%4.4f", st.Total.Seconds())))
if err := fr.AddColumn(c1); err != nil {
panic(err)
}
c2 := dataframe.NewColumn("REQUESTS-PER-SECOND")
c2.PushBack(dataframe.NewStringValue(fmt.Sprintf("%4.4f", st.RPS)))
if err := fr.AddColumn(c2); err != nil {
panic(err)
}
c3 := dataframe.NewColumn("SLOWEST-LATENCY-MS")
c3.PushBack(dataframe.NewStringValue(fmt.Sprintf("%4.4f", 1000*st.Slowest)))
if err := fr.AddColumn(c3); err != nil {
panic(err)
}
c4 := dataframe.NewColumn("FASTEST-LATENCY-MS")
c4.PushBack(dataframe.NewStringValue(fmt.Sprintf("%4.4f", 1000*st.Fastest)))
if err := fr.AddColumn(c4); err != nil {
panic(err)
}
c5 := dataframe.NewColumn("AVERAGE-LATENCY-MS")
c5.PushBack(dataframe.NewStringValue(fmt.Sprintf("%4.4f", 1000*st.Average)))
if err := fr.AddColumn(c5); err != nil {
panic(err)
}
c6 := dataframe.NewColumn("STDDEV-LATENCY-MS")
c6.PushBack(dataframe.NewStringValue(fmt.Sprintf("%4.4f", 1000*st.Stddev)))
if err := fr.AddColumn(c6); err != nil {
panic(err)
}
if len(st.ErrorDist) > 0 {
for errName, errN := range st.ErrorDist {
errcol := dataframe.NewColumn(fmt.Sprintf("ERROR: %q", errName))
errcol.PushBack(dataframe.NewStringValue(errN))
if err := fr.AddColumn(errcol); err != nil {
panic(err)
}
}
} else {
errcol := dataframe.NewColumn("ERROR")
errcol.PushBack(dataframe.NewStringValue("0"))
if err := fr.AddColumn(errcol); err != nil {
panic(err)
}
}
if err := fr.CSVHorizontal(cfg.ConfigClientMachineInitial.ClientLatencyDistributionSummaryPath); err != nil {
panic(err)
}
}
func (cfg *Config) saveDataLatencyDistributionPercentile(st report.Stats) {
pctls, seconds := report.Percentiles(st.Lats)
c1 := dataframe.NewColumn("LATENCY-PERCENTILE")
c2 := dataframe.NewColumn("LATENCY-MS")
for i := range pctls {
pct := fmt.Sprintf("p%.1f", pctls[i])
if strings.HasSuffix(pct, ".0") {
pct = strings.Replace(pct, ".0", "", -1)
}
c1.PushBack(dataframe.NewStringValue(pct))
c2.PushBack(dataframe.NewStringValue(fmt.Sprintf("%f", 1000*seconds[i])))
}
fr := dataframe.New()
if err := fr.AddColumn(c1); err != nil {
panic(err)
}
if err := fr.AddColumn(c2); err != nil {
panic(err)
}
if err := fr.CSV(cfg.ConfigClientMachineInitial.ClientLatencyDistributionPercentilePath); err != nil {
panic(err)
}
}
func (cfg *Config) saveDataLatencyDistributionAll(st report.Stats) {
min := int64(math.MaxInt64)
max := int64(-100000)
rm := make(map[int64]int64)
for _, lt := range st.Lats {
// convert second(float64) to millisecond
ms := lt * 1000
// truncate all digits below 10ms
// (e.g. 125.11ms becomes 120ms)
v := int64(math.Trunc(ms/10) * 10)
if _, ok := rm[v]; !ok {
rm[v] = 1
} else {
rm[v]++
}
if min > v {
min = v
}
if max < v {
max = v
}
}
c1 := dataframe.NewColumn("LATENCY-MS")
c2 := dataframe.NewColumn("COUNT")
cur := min
for {
c1.PushBack(dataframe.NewStringValue(fmt.Sprintf("%d", int64(cur))))
v, ok := rm[cur]
if ok {
c2.PushBack(dataframe.NewStringValue(fmt.Sprintf("%d", v)))
} else {
c2.PushBack(dataframe.NewStringValue("0"))
}
cur += 10
if cur-10 == max { // was last point
break
}
}
fr := dataframe.New()
if err := fr.AddColumn(c1); err != nil {
panic(err)
}
if err := fr.AddColumn(c2); err != nil {
panic(err)
}
if err := fr.CSV(cfg.ConfigClientMachineInitial.ClientLatencyDistributionAllPath); err != nil {
panic(err)
}
}
func (cfg *Config) saveDataLatencyThroughputTimeseries(gcfg dbtesterpb.ConfigClientMachineAgentControl, st report.Stats, clientNs []int64) {
if len(clientNs) == 0 && len(gcfg.ConfigClientMachineBenchmarkOptions.ConnectionClientNumbers) == 0 {
clientNs = make([]int64, len(st.TimeSeries))
for i := range clientNs {
clientNs[i] = gcfg.ConfigClientMachineBenchmarkOptions.ClientNumber
}
}
c1 := dataframe.NewColumn("UNIX-SECOND")
c2 := dataframe.NewColumn("CONTROL-CLIENT-NUM")
c3 := dataframe.NewColumn("MIN-LATENCY-MS")
c4 := dataframe.NewColumn("AVG-LATENCY-MS")
c5 := dataframe.NewColumn("MAX-LATENCY-MS")
c6 := dataframe.NewColumn("AVG-THROUGHPUT")
for i := range st.TimeSeries {
// this Timestamp is unix seconds
c1.PushBack(dataframe.NewStringValue(fmt.Sprintf("%d", st.TimeSeries[i].Timestamp)))
c2.PushBack(dataframe.NewStringValue(fmt.Sprintf("%d", clientNs[i])))
c3.PushBack(dataframe.NewStringValue(fmt.Sprintf("%f", toMillisecond(st.TimeSeries[i].MinLatency))))
c4.PushBack(dataframe.NewStringValue(fmt.Sprintf("%f", toMillisecond(st.TimeSeries[i].AvgLatency))))
c5.PushBack(dataframe.NewStringValue(fmt.Sprintf("%f", toMillisecond(st.TimeSeries[i].MaxLatency))))
c6.PushBack(dataframe.NewStringValue(fmt.Sprintf("%d", st.TimeSeries[i].ThroughPut)))
}
fr := dataframe.New()
if err := fr.AddColumn(c1); err != nil {
panic(err)
}
if err := fr.AddColumn(c2); err != nil {
panic(err)
}
if err := fr.AddColumn(c3); err != nil {
panic(err)
}
if err := fr.AddColumn(c4); err != nil {
panic(err)
}
if err := fr.AddColumn(c5); err != nil {
panic(err)
}
if err := fr.AddColumn(c6); err != nil {
panic(err)
}
if err := fr.CSV(cfg.ConfigClientMachineInitial.ClientLatencyThroughputTimeseriesPath); err != nil {
panic(err)
}
// aggregate latency by the number of keys
tss := FindRangesLatency(st.TimeSeries, 1000, gcfg.ConfigClientMachineBenchmarkOptions.RequestNumber)
ctt1 := dataframe.NewColumn("KEYS")
ctt2 := dataframe.NewColumn("MIN-LATENCY-MS")
ctt3 := dataframe.NewColumn("AVG-LATENCY-MS")
ctt4 := dataframe.NewColumn("MAX-LATENCY-MS")
for i := range tss {
ctt1.PushBack(dataframe.NewStringValue(tss[i].CumulativeKeyNum))
ctt2.PushBack(dataframe.NewStringValue(fmt.Sprintf("%f", toMillisecond(tss[i].MinLatency))))
ctt3.PushBack(dataframe.NewStringValue(fmt.Sprintf("%f", toMillisecond(tss[i].AvgLatency))))
ctt4.PushBack(dataframe.NewStringValue(fmt.Sprintf("%f", toMillisecond(tss[i].MaxLatency))))
}
frr := dataframe.New()
if err := frr.AddColumn(ctt1); err != nil {
panic(err)
}
if err := frr.AddColumn(ctt2); err != nil {
panic(err)
}
if err := frr.AddColumn(ctt3); err != nil {
panic(err)
}
if err := frr.AddColumn(ctt4); err != nil {
panic(err)
}
if err := frr.CSV(cfg.ConfigClientMachineInitial.ClientLatencyByKeyNumberPath); err != nil {
panic(err)
}
}
func (cfg *Config) saveAllStats(gcfg dbtesterpb.ConfigClientMachineAgentControl, stats report.Stats, clientNs []int64) {
cfg.saveDataLatencyDistributionSummary(stats)
cfg.saveDataLatencyDistributionPercentile(stats)
cfg.saveDataLatencyDistributionAll(stats)
cfg.saveDataLatencyThroughputTimeseries(gcfg, stats, clientNs)
}
// UploadToGoogle uploads target file to Google Cloud Storage.
func (cfg *Config) UploadToGoogle(databaseID string, targetPath string) error {
gcfg, ok := cfg.DatabaseIDToConfigClientMachineAgentControl[databaseID]
if !ok {
return fmt.Errorf("%q does not exist", databaseID)
}
if !exist(targetPath) {
return fmt.Errorf("%q does not exist", targetPath)
}
u, err := remotestorage.NewGoogleCloudStorage(cfg.lg, []byte(cfg.ConfigClientMachineInitial.GoogleCloudStorageKey), cfg.ConfigClientMachineInitial.GoogleCloudProjectName)
if err != nil {
return err
}
srcPath := targetPath
dstPath := filepath.Base(targetPath)
if !strings.HasPrefix(dstPath, gcfg.DatabaseTag) {
dstPath = fmt.Sprintf("%s-%s", gcfg.DatabaseTag, dstPath)
}
dstPath = filepath.Join(cfg.ConfigClientMachineInitial.GoogleCloudStorageSubDirectory, dstPath)
var uerr error
for k := 0; k < 30; k++ {
if uerr = u.UploadFile(cfg.ConfigClientMachineInitial.GoogleCloudStorageBucketName, srcPath, dstPath); uerr != nil {
cfg.lg.Sugar().Infof("#%d: error %v while uploading %q", k, uerr, targetPath)
time.Sleep(2 * time.Second)
continue
}
break
}
return uerr
}