mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
Make ExponentialFailureRateLimiter slightly slower and cap the backoff
This commit is contained in:
parent
008fc22d31
commit
0b8aeaf500
@ -38,7 +38,7 @@ type RateLimiter interface {
|
|||||||
// both overall and per-item rate limitting. The overall is a token bucket and the per-item is exponential
|
// both overall and per-item rate limitting. The overall is a token bucket and the per-item is exponential
|
||||||
func DefaultControllerRateLimiter() RateLimiter {
|
func DefaultControllerRateLimiter() RateLimiter {
|
||||||
return NewMaxOfRateLimiter(
|
return NewMaxOfRateLimiter(
|
||||||
DefaultItemBasedRateLimiter(),
|
NewItemExponentialFailureRateLimiter(5*time.Millisecond, 1000*time.Second),
|
||||||
// 10 qps, 100 bucket size. This is only for retry speed and its only the overall factor (not per item)
|
// 10 qps, 100 bucket size. This is only for retry speed and its only the overall factor (not per item)
|
||||||
&BucketRateLimiter{Bucket: ratelimit.NewBucketWithRate(float64(10), int64(100))},
|
&BucketRateLimiter{Bucket: ratelimit.NewBucketWithRate(float64(10), int64(100))},
|
||||||
)
|
)
|
||||||
@ -83,7 +83,7 @@ func NewItemExponentialFailureRateLimiter(baseDelay time.Duration, maxDelay time
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DefaultItemBasedRateLimiter() RateLimiter {
|
func DefaultItemBasedRateLimiter() RateLimiter {
|
||||||
return NewItemExponentialFailureRateLimiter(1*time.Millisecond, 1000*time.Second)
|
return NewItemExponentialFailureRateLimiter(time.Millisecond, 1000*time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ItemExponentialFailureRateLimiter) When(item interface{}) time.Duration {
|
func (r *ItemExponentialFailureRateLimiter) When(item interface{}) time.Duration {
|
||||||
@ -94,7 +94,7 @@ func (r *ItemExponentialFailureRateLimiter) When(item interface{}) time.Duration
|
|||||||
r.failures[item] = r.failures[item] + 1
|
r.failures[item] = r.failures[item] + 1
|
||||||
|
|
||||||
// The backoff is capped such that 'calculated' value never overflows.
|
// The backoff is capped such that 'calculated' value never overflows.
|
||||||
backoff := float64(r.baseDelay.Nanoseconds()) * math.Pow10(exp)
|
backoff := float64(r.baseDelay.Nanoseconds()) * math.Pow(2, float64(exp))
|
||||||
if backoff > math.MaxInt64 {
|
if backoff > math.MaxInt64 {
|
||||||
return r.maxDelay
|
return r.maxDelay
|
||||||
}
|
}
|
||||||
|
@ -27,16 +27,16 @@ func TestItemExponentialFailureRateLimiter(t *testing.T) {
|
|||||||
if e, a := 1*time.Millisecond, limiter.When("one"); e != a {
|
if e, a := 1*time.Millisecond, limiter.When("one"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := 10*time.Millisecond, limiter.When("one"); e != a {
|
if e, a := 2*time.Millisecond, limiter.When("one"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := 100*time.Millisecond, limiter.When("one"); e != a {
|
if e, a := 4*time.Millisecond, limiter.When("one"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := 1*time.Second, limiter.When("one"); e != a {
|
if e, a := 8*time.Millisecond, limiter.When("one"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := 1*time.Second, limiter.When("one"); e != a {
|
if e, a := 16*time.Millisecond, limiter.When("one"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := 5, limiter.NumRequeues("one"); e != a {
|
if e, a := 5, limiter.NumRequeues("one"); e != a {
|
||||||
@ -46,7 +46,7 @@ func TestItemExponentialFailureRateLimiter(t *testing.T) {
|
|||||||
if e, a := 1*time.Millisecond, limiter.When("two"); e != a {
|
if e, a := 1*time.Millisecond, limiter.When("two"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := 10*time.Millisecond, limiter.When("two"); e != a {
|
if e, a := 2*time.Millisecond, limiter.When("two"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := 2, limiter.NumRequeues("two"); e != a {
|
if e, a := 2, limiter.NumRequeues("two"); e != a {
|
||||||
@ -68,7 +68,7 @@ func TestItemExponentialFailureRateLimiterOverFlow(t *testing.T) {
|
|||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
limiter.When("one")
|
limiter.When("one")
|
||||||
}
|
}
|
||||||
if e, a := 100000*time.Millisecond, limiter.When("one"); e != a {
|
if e, a := 32*time.Millisecond, limiter.When("one"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ func TestItemExponentialFailureRateLimiterOverFlow(t *testing.T) {
|
|||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
limiter.When("two")
|
limiter.When("two")
|
||||||
}
|
}
|
||||||
if e, a := 100*time.Minute, limiter.When("two"); e != a {
|
if e, a := 4*time.Minute, limiter.When("two"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,10 +147,10 @@ func TestMaxOfRateLimiter(t *testing.T) {
|
|||||||
if e, a := 5*time.Millisecond, limiter.When("one"); e != a {
|
if e, a := 5*time.Millisecond, limiter.When("one"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := 10*time.Millisecond, limiter.When("one"); e != a {
|
if e, a := 5*time.Millisecond, limiter.When("one"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := 100*time.Millisecond, limiter.When("one"); e != a {
|
if e, a := 5*time.Millisecond, limiter.When("one"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := 3*time.Second, limiter.When("one"); e != a {
|
if e, a := 3*time.Second, limiter.When("one"); e != a {
|
||||||
@ -166,7 +166,7 @@ func TestMaxOfRateLimiter(t *testing.T) {
|
|||||||
if e, a := 5*time.Millisecond, limiter.When("two"); e != a {
|
if e, a := 5*time.Millisecond, limiter.When("two"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := 10*time.Millisecond, limiter.When("two"); e != a {
|
if e, a := 5*time.Millisecond, limiter.When("two"); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := 2, limiter.NumRequeues("two"); e != a {
|
if e, a := 2, limiter.NumRequeues("two"); e != a {
|
||||||
|
@ -44,7 +44,7 @@ func TestRateLimitingQueue(t *testing.T) {
|
|||||||
}
|
}
|
||||||
queue.AddRateLimited("one")
|
queue.AddRateLimited("one")
|
||||||
waitEntry = <-delayingQueue.waitingForAddCh
|
waitEntry = <-delayingQueue.waitingForAddCh
|
||||||
if e, a := 10*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a {
|
if e, a := 2*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
if e, a := 2, queue.NumRequeues("one"); e != a {
|
if e, a := 2, queue.NumRequeues("one"); e != a {
|
||||||
@ -58,7 +58,7 @@ func TestRateLimitingQueue(t *testing.T) {
|
|||||||
}
|
}
|
||||||
queue.AddRateLimited("two")
|
queue.AddRateLimited("two")
|
||||||
waitEntry = <-delayingQueue.waitingForAddCh
|
waitEntry = <-delayingQueue.waitingForAddCh
|
||||||
if e, a := 10*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a {
|
if e, a := 2*time.Millisecond, waitEntry.readyAt.Sub(fakeClock.Now()); e != a {
|
||||||
t.Errorf("expected %v, got %v", e, a)
|
t.Errorf("expected %v, got %v", e, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user