tsenart / vegeta

HTTP load testing tool and library. It's over 9000!
http://godoc.org/github.com/tsenart/vegeta/lib
MIT License
23.5k stars 1.36k forks source link

Invalid results with Attack parameters Rate = 1 and Duration = 1 #193

Closed stefanKnott closed 8 years ago

stefanKnott commented 8 years ago

If attacker.Attack(...) is ran with a rate of 1 and duration of 1 invalid results are returned as when m.Duration is calculated in lib/metrics.go it is set to equal 0 as m.Earliest and m.Latest will have the same value due to only one result being added to the metrics object. This causes an error when calculating the rate because of a divide by 0.

Perhaps to find correct rate for this use case -- would checking if m.Latest.Equal(m.Earliest) (they will only equal each other if rate=1 and dur=1) in metrics.Close() and if so set m.Latest to m.Latest.Add(m.Latencies.Total) be correct? This finds how long the one hit takes and can be used to then find a correct metrics.Rate.

tsenart commented 8 years ago

What's the use case? AFAIU this is equivalent to issuing a single HTTP request which can't have any statistical significance and would be better handled without Vegeta.

However, I recognize the metrics code should handle this case for the sake of correctness.

stefanKnott commented 8 years ago

The use case is testing the speed of a single http request -- we are using the library for a speedtest program. The only reason the issue was brought up was because a user accidentally entered this request.

I made the change myself locally to what I outlined above -- but if this use case doesnt fit your package then feel free to close this issue

piazzamp commented 8 years ago

@stefanKnott you may also want to check out go 1.7's new httptrace