Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
0b8aeaf5
Commit
0b8aeaf5
authored
Sep 05, 2016
by
gmarek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make ExponentialFailureRateLimiter slightly slower and cap the backoff
parent
008fc22d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
15 deletions
+15
-15
default_rate_limiters.go
pkg/util/workqueue/default_rate_limiters.go
+3
-3
default_rate_limiters_test.go
pkg/util/workqueue/default_rate_limiters_test.go
+10
-10
rate_limitting_queue_test.go
pkg/util/workqueue/rate_limitting_queue_test.go
+2
-2
No files found.
pkg/util/workqueue/default_rate_limiters.go
View file @
0b8aeaf5
...
@@ -38,7 +38,7 @@ type RateLimiter interface {
...
@@ -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
...
@@ -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
...
@@ -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
.
Pow
10
(
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
}
}
...
...
pkg/util/workqueue/default_rate_limiters_test.go
View file @
0b8aeaf5
...
@@ -27,16 +27,16 @@ func TestItemExponentialFailureRateLimiter(t *testing.T) {
...
@@ -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
.
S
econd
,
limiter
.
When
(
"one"
);
e
!=
a
{
if
e
,
a
:=
8
*
time
.
Millis
econd
,
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
.
S
econd
,
limiter
.
When
(
"one"
);
e
!=
a
{
if
e
,
a
:=
1
6
*
time
.
Millis
econd
,
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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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
{
...
...
pkg/util/workqueue/rate_limitting_queue_test.go
View file @
0b8aeaf5
...
@@ -44,7 +44,7 @@ func TestRateLimitingQueue(t *testing.T) {
...
@@ -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) {
...
@@ -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
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment