Skip to content

Commit

Permalink
Merge pull request tsenart#41 from tsenart/50p
Browse files Browse the repository at this point in the history
Add 50th latency percentile to Metrics
  • Loading branch information
tsenart committed Jan 21, 2014
2 parents 29e801e + e5f2204 commit f4c067d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion attack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"testing"
"time"
"os"
)

func init() {
Expand Down
4 changes: 3 additions & 1 deletion lib/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type Metrics struct {
Latencies struct {
Mean time.Duration `json:"mean"`
P50 time.Duration `json:"50th"` // P50 is the 50th percentile upper value
P95 time.Duration `json:"95th"` // P95 is the 95th percentile upper value
P99 time.Duration `json:"99th"` // P99 is the 99th percentile upper value
Max time.Duration `json:"max"`
Expand Down Expand Up @@ -41,7 +42,7 @@ func NewMetrics(results []Result) *Metrics {
StatusCodes: map[string]int{},
}
errorSet := map[string]struct{}{}
quants := quantile.NewTargeted(0.95, 0.99)
quants := quantile.NewTargeted(0.50, 0.95, 0.99)
totalSuccess, totalLatencies := 0, time.Duration(0)

for _, result := range results {
Expand All @@ -63,6 +64,7 @@ func NewMetrics(results []Result) *Metrics {

m.Duration = results[len(results)-1].Timestamp.Sub(results[0].Timestamp)
m.Latencies.Mean = time.Duration(float64(totalLatencies) / float64(m.Requests))
m.Latencies.P50 = time.Duration(quants.Query(0.50))
m.Latencies.P95 = time.Duration(quants.Query(0.95))
m.Latencies.P99 = time.Duration(quants.Query(0.99))
m.BytesIn.Mean = float64(m.BytesIn.Total) / float64(m.Requests)
Expand Down
1 change: 1 addition & 0 deletions lib/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestNewMetrics(t *testing.T) {
for field, values := range map[string][]time.Duration{
"Latencies.Max": []time.Duration{m.Latencies.Max, 100 * time.Millisecond},
"Latencies.Mean": []time.Duration{m.Latencies.Mean, 50 * time.Millisecond},
"Latencies.P50": []time.Duration{m.Latencies.P50, 20 * time.Millisecond},
"Latencies.P95": []time.Duration{m.Latencies.P95, 30 * time.Millisecond},
"Latencies.P99": []time.Duration{m.Latencies.P99, 30 * time.Millisecond},
"Duration": []time.Duration{m.Duration, 2 * time.Second},
Expand Down
4 changes: 2 additions & 2 deletions lib/reporters.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func ReportText(results []Result) ([]byte, error) {
w := tabwriter.NewWriter(out, 0, 8, 2, '\t', tabwriter.StripEscape)
fmt.Fprintf(w, "Requests\t[total]\t%d\n", m.Requests)
fmt.Fprintf(w, "Duration\t[total]\t%s\n", m.Duration)
fmt.Fprintf(w, "Latencies\t[mean, 95, 99, max]\t%s, %s, %s, %s\n",
m.Latencies.Mean, m.Latencies.P95, m.Latencies.P99, m.Latencies.Max)
fmt.Fprintf(w, "Latencies\t[mean, 50, 95, 99, max]\t%s, %s, %s, %s, %s\n",
m.Latencies.Mean, m.Latencies.P50, 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 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)
Expand Down

0 comments on commit f4c067d

Please sign in to comment.