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
13d152a8
Commit
13d152a8
authored
Nov 23, 2015
by
Hongchao Deng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RateLimiter: change CanAccept() to TryAccept()
parent
367f0e03
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
15 additions
and
14 deletions
+15
-14
handlers_test.go
pkg/apiserver/handlers_test.go
+1
-1
rate_limited_queue.go
pkg/controller/node/rate_limited_queue.go
+1
-1
docker.go
pkg/kubelet/dockertools/docker.go
+1
-1
throttle.go
pkg/util/throttle.go
+5
-4
throttle_test.go
pkg/util/throttle_test.go
+5
-5
scheduler_test.go
plugin/pkg/scheduler/scheduler_test.go
+2
-2
No files found.
pkg/apiserver/handlers_test.go
View file @
13d152a8
...
...
@@ -35,7 +35,7 @@ import (
type
fakeRL
bool
func
(
fakeRL
)
Stop
()
{}
func
(
f
fakeRL
)
Can
Accept
()
bool
{
return
bool
(
f
)
}
func
(
f
fakeRL
)
Try
Accept
()
bool
{
return
bool
(
f
)
}
func
(
f
fakeRL
)
Accept
()
{}
func
expectHTTP
(
url
string
,
code
int
,
t
*
testing
.
T
)
{
...
...
pkg/controller/node/rate_limited_queue.go
View file @
13d152a8
...
...
@@ -163,7 +163,7 @@ func (q *RateLimitedTimedQueue) Try(fn ActionFunc) {
val
,
ok
:=
q
.
queue
.
Head
()
for
ok
{
// rate limit the queue checking
if
!
q
.
limiter
.
Can
Accept
()
{
if
!
q
.
limiter
.
Try
Accept
()
{
glog
.
V
(
10
)
.
Info
(
"Try rate limitted..."
)
// Try again later
break
...
...
pkg/kubelet/dockertools/docker.go
View file @
13d152a8
...
...
@@ -197,7 +197,7 @@ func (p dockerPuller) Pull(image string, secrets []api.Secret) error {
}
func
(
p
throttledDockerPuller
)
Pull
(
image
string
,
secrets
[]
api
.
Secret
)
error
{
if
p
.
limiter
.
Can
Accept
()
{
if
p
.
limiter
.
Try
Accept
()
{
return
p
.
puller
.
Pull
(
image
,
secrets
)
}
return
fmt
.
Errorf
(
"pull QPS exceeded."
)
...
...
pkg/util/throttle.go
View file @
13d152a8
...
...
@@ -19,8 +19,9 @@ package util
import
"github.com/juju/ratelimit"
type
RateLimiter
interface
{
// CanAccept returns true if the rate is below the limit, false otherwise
CanAccept
()
bool
// TryAccept returns true if a token is taken immediately. Otherwise,
// it returns false.
TryAccept
()
bool
// Accept returns once a token becomes available.
Accept
()
// Stop stops the rate limiter, subsequent calls to CanAccept will return false
...
...
@@ -47,7 +48,7 @@ func NewFakeRateLimiter() RateLimiter {
return
&
fakeRateLimiter
{}
}
func
(
t
*
tickRateLimiter
)
Can
Accept
()
bool
{
func
(
t
*
tickRateLimiter
)
Try
Accept
()
bool
{
return
t
.
limiter
.
TakeAvailable
(
1
)
==
1
}
...
...
@@ -59,7 +60,7 @@ func (t *tickRateLimiter) Accept() {
func
(
t
*
tickRateLimiter
)
Stop
()
{
}
func
(
t
*
fakeRateLimiter
)
Can
Accept
()
bool
{
func
(
t
*
fakeRateLimiter
)
Try
Accept
()
bool
{
return
true
}
...
...
pkg/util/throttle_test.go
View file @
13d152a8
...
...
@@ -24,28 +24,28 @@ import (
func
TestBasicThrottle
(
t
*
testing
.
T
)
{
r
:=
NewTokenBucketRateLimiter
(
1
,
3
)
for
i
:=
0
;
i
<
3
;
i
++
{
if
!
r
.
Can
Accept
()
{
if
!
r
.
Try
Accept
()
{
t
.
Error
(
"unexpected false accept"
)
}
}
if
r
.
Can
Accept
()
{
if
r
.
Try
Accept
()
{
t
.
Error
(
"unexpected true accept"
)
}
}
func
TestIncrementThrottle
(
t
*
testing
.
T
)
{
r
:=
NewTokenBucketRateLimiter
(
1
,
1
)
if
!
r
.
Can
Accept
()
{
if
!
r
.
Try
Accept
()
{
t
.
Error
(
"unexpected false accept"
)
}
if
r
.
Can
Accept
()
{
if
r
.
Try
Accept
()
{
t
.
Error
(
"unexpected true accept"
)
}
// Allow to refill
time
.
Sleep
(
2
*
time
.
Second
)
if
!
r
.
Can
Accept
()
{
if
!
r
.
Try
Accept
()
{
t
.
Error
(
"unexpected false accept"
)
}
}
...
...
plugin/pkg/scheduler/scheduler_test.go
View file @
13d152a8
...
...
@@ -302,14 +302,14 @@ type FakeRateLimiter struct {
acceptValues
[]
bool
}
func
(
fr
*
FakeRateLimiter
)
Can
Accept
()
bool
{
func
(
fr
*
FakeRateLimiter
)
Try
Accept
()
bool
{
return
true
}
func
(
fr
*
FakeRateLimiter
)
Stop
()
{}
func
(
fr
*
FakeRateLimiter
)
Accept
()
{
fr
.
acceptValues
=
append
(
fr
.
acceptValues
,
fr
.
r
.
Can
Accept
())
fr
.
acceptValues
=
append
(
fr
.
acceptValues
,
fr
.
r
.
Try
Accept
())
}
func
TestSchedulerRateLimitsBinding
(
t
*
testing
.
T
)
{
...
...
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