Skip to content

armgit / hey

Public Imported from GitHub
0

HTTP load generator, ApacheBench (ab) replacement

Go

Do not print statistics if the site does not provide the Content Length

Vasilis Keramidas607dbd15f888
diff --git a/commands/print.go b/commands/print.go
index 39f1b46..212b451 100644
--- a/commands/print.go
+++ b/commands/print.go
@@ -62,7 +62,9 @@ func (r *report) finalize(total time.Duration) {
r.lats = append(r.lats, res.duration.Seconds())
r.avgTotal += res.duration.Seconds()
r.statusCodeDist[res.statusCode]++
- r.sizeTotal += res.ContentLength
+ if res.ContentLength > 0 {
+ r.sizeTotal += res.ContentLength
+ }
}
default:
r.total = total
@@ -91,7 +93,10 @@ func (r *report) print() {
fmt.Printf(" Fastest:\t%4.4f secs.\n", r.fastest)
fmt.Printf(" Average:\t%4.4f secs.\n", r.average)
fmt.Printf(" Requests/sec:\t%4.4f\n", r.rps)
- fmt.Printf(" Total Data Transferred:\t%d bytes.\n", r.sizeTotal)
+ if r.sizeTotal > 0 {
+ fmt.Printf(" Total Data Recieved:\t%d bytes\n", r.sizeTotal)
+ fmt.Printf(" Response Size per request:\t%d bytes\n", r.sizeTotal/int64(len(r.lats)))
+ }
r.printStatusCodes()
r.printHistogram()
r.printLatencies()
diff --git a/commands/run.go b/commands/run.go
index 210ef6f..5a05183 100644
--- a/commands/run.go
+++ b/commands/run.go
@@ -41,10 +41,12 @@ func (b *Boom) worker(ch chan *http.Request) {
s := time.Now()
resp, err := client.Do(req)
code := 0
- var size int64 = 0
+ var size int64 = -1
if resp != nil {
code = resp.StatusCode
- size = resp.ContentLength
+ if resp.ContentLength > 0 {
+ size = resp.ContentLength
+ }
// cleanup body, so the socket can be reusable
resp.Body.Close()
}