Skip to content

Commit e2a7c2c

Browse files
committed
address zero wait time
1 parent 14a3af2 commit e2a7c2c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

internal/worker/concurrency_auto_scaler.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,14 @@ func (c *ConcurrencyAutoScaler) updatePollerPermit() {
207207
return
208208
}
209209
currentQuota := c.concurrency.PollerPermit.Quota()
210-
// smoothing the scaling through log2
211-
newQuota := int(math.Round(float64(currentQuota) * targetPollerWaitTimeInMsLog2 / math.Log2(
212-
1+float64(c.pollerWaitTime.Average()/time.Millisecond))))
210+
// smoothing the scaling through log2 with edge case of zero value
211+
var newQuota int
212+
if waitTime := c.pollerWaitTime.Average(); waitTime == 0 {
213+
newQuota = currentQuota * 2
214+
} else {
215+
newQuota = int(math.Round(
216+
float64(currentQuota) * targetPollerWaitTimeInMsLog2 / math.Log2(1+float64(waitTime/time.Millisecond))))
217+
}
213218
if newQuota < c.pollerMinCount {
214219
newQuota = c.pollerMinCount
215220
}

0 commit comments

Comments
 (0)