-
Notifications
You must be signed in to change notification settings - Fork 79
/
report.go
233 lines (187 loc) · 6.55 KB
/
report.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
package main
import (
"errors"
"fmt"
"sort"
)
const (
ConnectFailedEvent = "ConnectFailed"
SubscribeFailedEvent = "SubscribeFailed"
TimeoutExceededEvent = "TimeoutExceeded"
AbortedEvent = "Aborted"
CompletedEvent = "Completed"
ProgressReportEvent = "ProgressReport"
)
type Summary struct {
Clients int
TotalMessages int
MessagesReceived int
MessagesPublished int
Errors int
ErrorRate float64
Completed int
InProgress int
ConnectFailed int
SubscribeFailed int
TimeoutExceeded int
Aborted int
// ordered results
PublishPerformance []float64
ReceivePerformance []float64
PublishPerformanceMedian float64
ReceivePerformanceMedian float64
PublishPerformanceHistogram map[float64]float64
ReceivePerformanceHistogram map[float64]float64
}
func buildSummary(nClient int, nMessages int, results []Result) (Summary, error) {
if len(results) == 0 {
return Summary{}, errors.New("no results collected")
}
totalMessages := nClient * nMessages
nMessagesPublished := 0
nMessagesReceived := 0
nErrors := 0
nCompleted := 0
nInProgress := 0
nConnectFailed := 0
nSubscribeFailed := 0
nTimeoutExceeded := 0
nAborted := 0
publishPerformance := make([]float64, 0)
receivePerformance := make([]float64, 0)
for _, r := range results {
nMessagesReceived += r.MessagesReceived
nMessagesPublished += r.MessagesPublished
if r.Error {
nErrors++
switch r.Event {
case ConnectFailedEvent:
nConnectFailed++
case SubscribeFailedEvent:
nSubscribeFailed++
case TimeoutExceededEvent:
nTimeoutExceeded++
case AbortedEvent:
nAborted++
}
}
if r.Event == CompletedEvent {
nCompleted++
}
if r.Event == ProgressReportEvent {
nInProgress++
}
if r.Event == CompletedEvent || r.Event == ProgressReportEvent {
publishPerformance = append(publishPerformance, float64(r.MessagesPublished)/r.PublishTime.Seconds())
receivePerformance = append(receivePerformance, float64(r.MessagesReceived)/r.ReceiveTime.Seconds())
}
}
if len(publishPerformance) == 0 {
return Summary{}, errors.New("no feasible results found")
}
sort.Float64s(publishPerformance)
sort.Float64s(receivePerformance)
errorRate := float64(nErrors) / float64(nClient) * 100
return Summary{
Clients: nClient,
TotalMessages: totalMessages,
MessagesReceived: nMessagesReceived,
MessagesPublished: nMessagesPublished,
Errors: nErrors,
ErrorRate: errorRate,
Completed: nCompleted,
InProgress: nInProgress,
ConnectFailed: nConnectFailed,
SubscribeFailed: nSubscribeFailed,
TimeoutExceeded: nTimeoutExceeded,
Aborted: nAborted,
PublishPerformance: publishPerformance,
ReceivePerformance: receivePerformance,
PublishPerformanceMedian: median(publishPerformance),
ReceivePerformanceMedian: median(receivePerformance),
PublishPerformanceHistogram: buildHistogram(publishPerformance, nCompleted+nInProgress),
ReceivePerformanceHistogram: buildHistogram(receivePerformance, nCompleted+nInProgress),
}, nil
}
func printSummary(summary Summary) {
fmt.Println()
fmt.Printf("# Configuration\n")
fmt.Printf("Concurrent Clients: %d\n", summary.Clients)
fmt.Printf("Messages / Client: %d\n", summary.TotalMessages)
fmt.Println()
fmt.Printf("# Results\n")
fmt.Printf("Published Messages: %d (%.0f%%)\n", summary.MessagesPublished, (float64(summary.MessagesPublished) / float64(summary.TotalMessages) * 100))
fmt.Printf("Received Messages: %d (%.0f%%)\n", summary.MessagesReceived, (float64(summary.MessagesReceived) / float64(summary.MessagesPublished) * 100))
fmt.Printf("Completed: %d (%.0f%%)\n", summary.Completed, (float64(summary.Completed) / float64(summary.Clients) * 100))
fmt.Printf("Errors: %d (%.0f%%)\n", summary.Errors, (float64(summary.Errors) / float64(summary.Clients) * 100))
if summary.Errors > 0 {
fmt.Printf("- ConnectFailed: %d (%.0f%%)\n", summary.ConnectFailed, (float64(summary.ConnectFailed) / float64(summary.Errors) * 100))
fmt.Printf("- SubscribeFailed: %d (%.0f%%)\n", summary.SubscribeFailed, (float64(summary.SubscribeFailed) / float64(summary.Errors) * 100))
fmt.Printf("- TimeoutExceeded: %d (%.0f%%)\n", summary.TimeoutExceeded, (float64(summary.TimeoutExceeded) / float64(summary.Errors) * 100))
fmt.Printf("- Aborted: %d (%.0f%%)\n", summary.InProgress, (float64(summary.InProgress) / float64(summary.Clients) * 100))
}
fmt.Println()
fmt.Printf("# Publishing Throughput\n")
fmt.Printf("Fastest: %.0f msg/sec\n", summary.PublishPerformance[len(summary.PublishPerformance)-1])
fmt.Printf("Slowest: %.0f msg/sec\n", summary.PublishPerformance[0])
fmt.Printf("Median: %.0f msg/sec\n", summary.PublishPerformanceMedian)
fmt.Println()
printHistogram(summary.PublishPerformanceHistogram)
fmt.Println()
fmt.Printf("# Receiving Througput\n")
fmt.Printf("Fastest: %.0f msg/sec\n", summary.ReceivePerformance[len(summary.ReceivePerformance)-1])
fmt.Printf("Slowest: %.0f msg/sec\n", summary.ReceivePerformance[0])
fmt.Printf("Median: %.0f msg/sec\n", median(summary.ReceivePerformance))
fmt.Println()
printHistogram(summary.ReceivePerformanceHistogram)
}
func buildHistogram(series []float64, total int) map[float64]float64 {
slowest := series[0]
fastest := series[len(series)-1]
nBuckets := 10
steps := (fastest - slowest) / float64(nBuckets)
bucketCount := make(map[float64]int)
for _, v := range series {
var tmp float64
for i := 0; i <= nBuckets; i++ {
f0 := slowest + steps*float64(i)
f1 := slowest + steps*float64(i+1)
if v >= f0 && v <= f1 {
tmp = f1
}
}
bucketCount[tmp]++
}
keys := make([]float64, 0)
for k := range bucketCount {
keys = append(keys, k)
}
sort.Float64s(keys)
histogram := make(map[float64]float64)
prev := 0.0
for _, k := range keys {
cur := float64(bucketCount[k])/float64(total) + prev
histogram[k] = cur
prev = cur
}
return histogram
}
func printHistogram(histogram map[float64]float64) {
type histEntry struct {
key float64
value float64
}
var res []histEntry
for k, v := range histogram {
res = append(res, histEntry{key: k, value: v})
}
sort.Slice(res, func(i, j int) bool {
return res[i].key < res[j].key
})
for _, r := range res {
fmt.Printf(" < %.0f msg/sec %.0f%%\n", r.key, r.value*100)
}
}
func median(series []float64) float64 {
return (series[(len(series)-1)/2] + series[len(series)/2]) / 2
}