Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3 from mxmCherry/patch-1
Browse files Browse the repository at this point in the history
load.RateReporter.Score: fixed division by zero
  • Loading branch information
dim authored Oct 26, 2016
2 parents f8ef375 + 7e6493d commit 8a913b1
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions load/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func NewRateReporter(d time.Duration) *RateReporter {
func (r *RateReporter) Score() int64 {
now := time.Now().UnixNano()
passed := now - atomic.SwapInt64(&r.time, now)
if passed == 0 {
return 0
}
if passed < r.unit {
atomic.AddInt64(&r.time, -passed)
return atomic.LoadInt64(&r.count) * r.unit / passed
Expand Down

0 comments on commit 8a913b1

Please sign in to comment.