Skip to content

Commit

Permalink
address zero wait time
Browse files Browse the repository at this point in the history
  • Loading branch information
shijiesheng committed Jan 10, 2025
1 parent 14a3af2 commit e2a7c2c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions internal/worker/concurrency_auto_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,14 @@ func (c *ConcurrencyAutoScaler) updatePollerPermit() {
return
}
currentQuota := c.concurrency.PollerPermit.Quota()
// smoothing the scaling through log2
newQuota := int(math.Round(float64(currentQuota) * targetPollerWaitTimeInMsLog2 / math.Log2(
1+float64(c.pollerWaitTime.Average()/time.Millisecond))))
// smoothing the scaling through log2 with edge case of zero value
var newQuota int
if waitTime := c.pollerWaitTime.Average(); waitTime == 0 {
newQuota = currentQuota * 2
} else {
newQuota = int(math.Round(
float64(currentQuota) * targetPollerWaitTimeInMsLog2 / math.Log2(1+float64(waitTime/time.Millisecond))))
}
if newQuota < c.pollerMinCount {
newQuota = c.pollerMinCount
}
Expand Down

0 comments on commit e2a7c2c

Please sign in to comment.