Change percentiles field names as they were misleading

Also removes the total latencies field from Metrics as it is not useful.
This commit is contained in:
Tomás Senart
2013-10-05 23:14:36 +02:00
parent c932c651d2
commit 4ba3b431a8
4 changed files with 19 additions and 22 deletions

View File

@@ -118,7 +118,7 @@ Specifies the kind of report to be generated. It defaults to text.
##### text ##### text
``` ```
Requests [total] 1200 Requests [total] 1200
Latencies [mean, max, 95, 99] 223.340085ms, 7.788103259s, 326.913687ms, 416.537743ms Latencies [mean, 95, 99, max] 223.340085ms, 326.913687ms, 416.537743ms, 7.788103259s
Bytes In [total, mean] 3714690, 3095.57 Bytes In [total, mean] 3714690, 3095.57
Bytes Out [total, mean] 0, 0.00 Bytes Out [total, mean] 0, 0.00
Success [ratio] 55.42% Success [ratio] 55.42%
@@ -136,11 +136,10 @@ Get http://localhost:6060: http: can't write HTTP request on broken connection
```json ```json
{ {
"latencies": { "latencies": {
"total": 10912384376645,
"max": 12604629125,
"mean": 9093653647, "mean": 9093653647,
"mean_95": 12553709381, "95th": 12553709381,
"mean_99": 12604629125 "99th": 12604629125,
"max": 12604629125
}, },
"bytes_in": { "bytes_in": {
"total": 782040, "total": 782040,

View File

@@ -11,11 +11,10 @@ import (
// that is used for some of the Reporters // that is used for some of the Reporters
type Metrics struct { type Metrics struct {
Latencies struct { Latencies struct {
Total time.Duration `json:"total"` Mean time.Duration `json:"mean"`
Max time.Duration `json:"max"` P95 time.Duration `json:"95th"` // P95 is the 95th percentile upper value
Mean time.Duration `json:"mean"` P99 time.Duration `json:"99th"` // P99 is the 99th percentile upper value
Mean95 time.Duration `json:"mean_95"` Max time.Duration `json:"max"`
Mean99 time.Duration `json:"mean_99"`
} `json:"latencies"` } `json:"latencies"`
BytesIn struct { BytesIn struct {
@@ -42,12 +41,12 @@ func NewMetrics(results []Result) *Metrics {
} }
errorSet := map[string]struct{}{} errorSet := map[string]struct{}{}
quants := quantile.NewTargeted(0.95, 0.99) quants := quantile.NewTargeted(0.95, 0.99)
totalSuccess := 0 totalSuccess, totalLatencies := 0, time.Duration(0)
for _, result := range results { for _, result := range results {
quants.Insert(float64(result.Latency)) quants.Insert(float64(result.Latency))
m.StatusCodes[strconv.Itoa(int(result.Code))]++ m.StatusCodes[strconv.Itoa(int(result.Code))]++
m.Latencies.Total += result.Latency totalLatencies += result.Latency
m.BytesOut.Total += result.BytesOut m.BytesOut.Total += result.BytesOut
m.BytesIn.Total += result.BytesIn m.BytesIn.Total += result.BytesIn
if result.Latency > m.Latencies.Max { if result.Latency > m.Latencies.Max {
@@ -61,9 +60,9 @@ func NewMetrics(results []Result) *Metrics {
} }
} }
m.Latencies.Mean = time.Duration(float64(m.Latencies.Total) / float64(m.Requests)) m.Latencies.Mean = time.Duration(float64(totalLatencies) / float64(m.Requests))
m.Latencies.Mean95 = time.Duration(quants.Query(0.95)) m.Latencies.P95 = time.Duration(quants.Query(0.95))
m.Latencies.Mean99 = time.Duration(quants.Query(0.99)) m.Latencies.P99 = time.Duration(quants.Query(0.99))
m.BytesIn.Mean = float64(m.BytesIn.Total) / float64(m.Requests) m.BytesIn.Mean = float64(m.BytesIn.Total) / float64(m.Requests)
m.BytesOut.Mean = float64(m.BytesOut.Total) / float64(m.Requests) m.BytesOut.Mean = float64(m.BytesOut.Total) / float64(m.Requests)
m.Success = float64(totalSuccess) / float64(m.Requests) m.Success = float64(totalSuccess) / float64(m.Requests)

View File

@@ -23,11 +23,10 @@ func TestNewMetrics(t *testing.T) {
} }
for field, values := range map[string][]time.Duration{ for field, values := range map[string][]time.Duration{
"Latencies.Total": []time.Duration{m.Latencies.Total, 150 * time.Millisecond}, "Latencies.Max": []time.Duration{m.Latencies.Max, 100 * time.Millisecond},
"Latencies.Mean": []time.Duration{m.Latencies.Mean, 50 * time.Millisecond}, "Latencies.Mean": []time.Duration{m.Latencies.Mean, 50 * time.Millisecond},
"Latencies.Mean95": []time.Duration{m.Latencies.Mean95, 30 * time.Millisecond}, "Latencies.P95": []time.Duration{m.Latencies.P95, 30 * time.Millisecond},
"Latencies.Mean99": []time.Duration{m.Latencies.Mean99, 30 * time.Millisecond}, "Latencies.P99": []time.Duration{m.Latencies.P99, 30 * time.Millisecond},
"Latencies.Max": []time.Duration{m.Latencies.Max, 100 * time.Millisecond},
} { } {
if values[0] != values[1] { if values[0] != values[1] {
t.Errorf("%s: want: %s, got: %s", field, values[1], values[0]) t.Errorf("%s: want: %s, got: %s", field, values[1], values[0])

View File

@@ -19,8 +19,8 @@ func ReportText(results []Result) ([]byte, error) {
w := tabwriter.NewWriter(out, 0, 8, 2, '\t', tabwriter.StripEscape) w := tabwriter.NewWriter(out, 0, 8, 2, '\t', tabwriter.StripEscape)
fmt.Fprintf(w, "Requests\t[total]\t%d\n", m.Requests) fmt.Fprintf(w, "Requests\t[total]\t%d\n", m.Requests)
fmt.Fprintf(w, "Latencies\t[mean, max, 95, 99]\t%s, %s, %s, %s\n", fmt.Fprintf(w, "Latencies\t[mean, 95, 99, max]\t%s, %s, %s, %s\n",
m.Latencies.Mean, m.Latencies.Max, m.Latencies.Mean95, m.Latencies.Mean99) m.Latencies.Mean, m.Latencies.P95, m.Latencies.P99, m.Latencies.Max)
fmt.Fprintf(w, "Bytes In\t[total, mean]\t%d, %.2f\n", m.BytesIn.Total, m.BytesIn.Mean) fmt.Fprintf(w, "Bytes In\t[total, mean]\t%d, %.2f\n", m.BytesIn.Total, m.BytesIn.Mean)
fmt.Fprintf(w, "Bytes Out\t[total, mean]\t%d, %.2f\n", m.BytesOut.Total, m.BytesOut.Mean) fmt.Fprintf(w, "Bytes Out\t[total, mean]\t%d, %.2f\n", m.BytesOut.Total, m.BytesOut.Mean)
fmt.Fprintf(w, "Success\t[ratio]\t%.2f%%\n", m.Success*100) fmt.Fprintf(w, "Success\t[ratio]\t%.2f%%\n", m.Success*100)