HTTP load generator, ApacheBench (ab) replacement
Go
Add simple histogram.
mdakin7fc452f581f0
diff --git a/commands/print.go b/commands/print.goindex 3b6c327..eab382f 100644--- a/commands/print.go+++ b/commands/print.go@@ -17,6 +17,7 @@ package commandsimport ("fmt""sort"+ "strings""time")@@ -51,6 +52,8 @@ func (b *Boom) Print() {fmt.Printf(" Average:\t%4.4f secs.\n", avgTotal/float64(b.N))fmt.Printf(" Requests/sec:\t%4.4f\n", rps)fmt.Printf(" Speed index:\t%v\n", speedIndex(rps))+ sort.Float64s(latencies)+ b.printHistogram()b.printLatencies()b.printStatusCodes()return@@ -62,7 +65,6 @@ func (b *Boom) Print() {func (b *Boom) printLatencies() {pctls := []int{10, 25, 50, 75, 90, 95, 99}// Sort the array- sort.Float64s(latencies)data := make([]float64, len(pctls))j := 0for i := 0; i < len(latencies) && j < len(pctls); i++ {@@ -80,6 +82,47 @@ func (b *Boom) printLatencies() {}}+func (b *Boom) printHistogram() {+ bc := 10+ buckets := make([]float64, bc+1)+ counts := make([]int, bc+1)+ fastest := latencies[0]+ slowest := latencies[len(latencies)-1]+ // TODO: Intead of slowest, 95th percentile etc.+ bs := (slowest - fastest) / float64(bc)+ for i := 0; i < bc; i++ {+ buckets[i] = fastest + bs * float64(i)+ }+ buckets[bc] = slowest+ var bi int+ var max int+ for i := 0; i < len(latencies); {+ if latencies[i] <= buckets[bi] {+ i+++ counts[bi]+++ if max < counts[bi] {+ max = counts[bi]+ }+ } else if bi < len(buckets) - 1 {+ bi+++ }+ }+ fmt.Printf("\nResponse time histogram:\n")+ for i := 0; i < len(buckets); i++ {+ // Normalize bar lengths.+ var barLen int+ if max > 0 {+ barLen = counts[i] * 40 / max+ }+ var bar string = ""+ if barLen > 0 {+ bar = strings.Repeat("#", barLen)+ }+ fmt.Printf(" %4.3f [%v]\t|%v\n", buckets[i], counts[i], bar)+ }++}+// Prints status code distribution.func (b *Boom) printStatusCodes() {fmt.Printf("\nStatus code distribution:\n")