-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_result.go
93 lines (79 loc) · 2.76 KB
/
test_result.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
package main
import (
"encoding/json"
"github.com/HdrHistogram/hdrhistogram-go"
"io/ioutil"
"log"
"time"
)
const resultFormatVersion = "0.0.1"
type TestResult struct {
// Test Configs
resultFormatVersion string `json:"ResultFormatVersion"`
Metadata string `json:"Metadata"`
Clients uint `json:"Clients"`
MaxRps uint64 `json:"MaxRps"`
RandomSeed int64 `json:"RandomSeed"`
StartTime int64 `json:"StartTime"`
EndTime int64 `json:"EndTime"`
DurationMillis int64 `json:"DurationMillis"`
// Populated after benchmark
// Benchmark Totals
Totals map[string]float64 `json:"Totals"`
// Overall Rates
OverallCommandRate []float64 `json:"OverallCommandRate"`
OverallCSCHitRate []float64 `json:"OverallCSCHitRate"`
OverallCSCInvalidationRate []float64 `json:"OverallCSCInvalidationRate"`
// Overall Client Quantiles
OverallClientLatencies []map[string]float64 `json:"OverallClientLatencies"`
}
func NewTestResult(metadata string, clients uint, maxRps uint64) *TestResult {
return &TestResult{resultFormatVersion: resultFormatVersion, Metadata: metadata, Clients: clients, MaxRps: maxRps}
}
func (r *TestResult) SetUsedRandomSeed(seed int64) *TestResult {
r.RandomSeed = seed
return r
}
func (r *TestResult) FillDurationInfo(startTime time.Time, endTime time.Time, duration time.Duration) {
r.StartTime = startTime.UTC().UnixNano() / 1000000
r.EndTime = endTime.UTC().UnixNano() / 1000000
r.DurationMillis = duration.Milliseconds()
}
func saveJsonResult(testResult *TestResult, jsonOutputFile string) {
if jsonOutputFile != "" {
file, err := json.MarshalIndent(testResult, "", " ")
if err != nil {
log.Fatal(err)
}
log.Printf("Saving JSON results file to %s\n", jsonOutputFile)
err = ioutil.WriteFile(jsonOutputFile, file, 0644)
if err != nil {
log.Fatal(err)
}
}
}
func calculateRateMetrics(current, prev int64, took time.Duration) (rate float64) {
rate = float64(current-prev) / float64(took.Seconds())
return
}
func generateLatenciesMap(hist *hdrhistogram.Histogram, tick time.Duration) (int64, map[string]float64) {
ops := hist.TotalCount()
percentilesTrack := []float64{0.0, 50.0, 95.0, 99.0, 99.9, 100.0}
q0 := 0.0
q50 := 0.0
q95 := 0.0
q99 := 0.0
q999 := 0.0
q100 := 0.0
if ops > 0 {
percentilesMap := hist.ValueAtPercentiles(percentilesTrack)
q0 = float64(percentilesMap[0.0]) / 10e2
q50 = float64(percentilesMap[50.0]) / 10e2
q95 = float64(percentilesMap[95.0]) / 10e2
q99 = float64(percentilesMap[99.0]) / 10e2
q999 = float64(percentilesMap[99.9]) / 10e2
q100 = float64(percentilesMap[100.0]) / 10e2
}
mp := map[string]float64{"q0": q0, "q50": q50, "q95": q95, "q99": q99, "q999": q999, "q100": q100, "ops/sec": float64(ops) / tick.Seconds()}
return ops, mp
}