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
a9ed90f2
Unverified
Commit
a9ed90f2
authored
Jan 19, 2018
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Saturation() from rate limiter interface
parent
40b0c551
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
64 deletions
+16
-64
rate_limited_queue.go
pkg/controller/nodelifecycle/scheduler/rate_limited_queue.go
+9
-14
BUILD
pkg/util/metrics/BUILD
+0
-1
util.go
pkg/util/metrics/util.go
+7
-6
throttle.go
staging/src/k8s.io/client-go/util/flowcontrol/throttle.go
+0
-19
throttle_test.go
...ng/src/k8s.io/client-go/util/flowcontrol/throttle_test.go
+0
-24
No files found.
pkg/controller/nodelifecycle/scheduler/rate_limited_queue.go
View file @
a9ed90f2
...
@@ -293,20 +293,15 @@ func (q *RateLimitedTimedQueue) SwapLimiter(newQPS float32) {
...
@@ -293,20 +293,15 @@ func (q *RateLimitedTimedQueue) SwapLimiter(newQPS float32) {
newLimiter
=
flowcontrol
.
NewFakeNeverRateLimiter
()
newLimiter
=
flowcontrol
.
NewFakeNeverRateLimiter
()
}
else
{
}
else
{
newLimiter
=
flowcontrol
.
NewTokenBucketRateLimiter
(
newQPS
,
EvictionRateLimiterBurst
)
newLimiter
=
flowcontrol
.
NewTokenBucketRateLimiter
(
newQPS
,
EvictionRateLimiterBurst
)
}
// If we're currently waiting on limiter, we drain the new one - this is a good approach when Burst value is 1
// If we're currently waiting on limiter, we drain the new one - this is a good approach when Burst value is 1
// TODO: figure out if we need to support higher Burst values and decide on the drain logic, should we keep:
// TODO: figure out if we need to support higher Burst values and decide on the drain logic, should we keep:
// - saturation (percentage of used tokens)
// - saturation (percentage of used tokens)
// - number of used tokens
// - number of used tokens
// - number of available tokens
// - number of available tokens
// - something else
// - something else
for
q
.
limiter
.
Saturation
()
>
newLimiter
.
Saturation
()
{
if
q
.
limiter
.
TryAccept
()
==
false
{
// Check if we're not using fake limiter
newLimiter
.
TryAccept
()
previousSaturation
:=
newLimiter
.
Saturation
()
newLimiter
.
TryAccept
()
// It's a fake limiter
if
newLimiter
.
Saturation
()
==
previousSaturation
{
break
}
}
}
}
q
.
limiter
.
Stop
()
q
.
limiter
.
Stop
()
...
...
pkg/util/metrics/BUILD
View file @
a9ed90f2
...
@@ -13,7 +13,6 @@ go_library(
...
@@ -13,7 +13,6 @@ go_library(
deps = [
deps = [
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/client-go/util/flowcontrol:go_default_library",
"//vendor/k8s.io/client-go/util/flowcontrol:go_default_library",
],
],
)
)
...
...
pkg/util/metrics/util.go
View file @
a9ed90f2
...
@@ -21,7 +21,6 @@ import (
...
@@ -21,7 +21,6 @@ import (
"sync"
"sync"
"time"
"time"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/flowcontrol"
"k8s.io/client-go/util/flowcontrol"
"github.com/golang/glog"
"github.com/golang/glog"
...
@@ -71,11 +70,13 @@ func RegisterMetricAndTrackRateLimiterUsage(ownerName string, rateLimiter flowco
...
@@ -71,11 +70,13 @@ func RegisterMetricAndTrackRateLimiterUsage(ownerName string, rateLimiter flowco
if
err
:=
registerRateLimiterMetric
(
ownerName
);
err
!=
nil
{
if
err
:=
registerRateLimiterMetric
(
ownerName
);
err
!=
nil
{
return
err
return
err
}
}
go
wait
.
Until
(
func
()
{
// TODO: determine how to track rate limiter saturation
metricsLock
.
Lock
()
// See discussion at https://go-review.googlesource.com/c/time/+/29958#message-4caffc11669cadd90e2da4c05122cfec50ea6a22
defer
metricsLock
.
Unlock
()
// go wait.Until(func() {
rateLimiterMetrics
[
ownerName
]
.
metric
.
Set
(
rateLimiter
.
Saturation
())
// metricsLock.Lock()
},
updatePeriod
,
rateLimiterMetrics
[
ownerName
]
.
stopCh
)
// defer metricsLock.Unlock()
// rateLimiterMetrics[ownerName].metric.Set()
// }, updatePeriod, rateLimiterMetrics[ownerName].stopCh)
return
nil
return
nil
}
}
...
...
staging/src/k8s.io/client-go/util/flowcontrol/throttle.go
View file @
a9ed90f2
...
@@ -30,11 +30,6 @@ type RateLimiter interface {
...
@@ -30,11 +30,6 @@ type RateLimiter interface {
Accept
()
Accept
()
// Stop stops the rate limiter, subsequent calls to CanAccept will return false
// Stop stops the rate limiter, subsequent calls to CanAccept will return false
Stop
()
Stop
()
// Saturation returns a percentage number which describes how saturated
// this rate limiter is.
// Usually we use token bucket rate limiter. In that case,
// 1.0 means no tokens are available; 0.0 means we have a full bucket of tokens to use.
Saturation
()
float64
// QPS returns QPS of this rate limiter
// QPS returns QPS of this rate limiter
QPS
()
float32
QPS
()
float32
}
}
...
@@ -77,12 +72,6 @@ func (t *tokenBucketRateLimiter) TryAccept() bool {
...
@@ -77,12 +72,6 @@ func (t *tokenBucketRateLimiter) TryAccept() bool {
return
t
.
limiter
.
TakeAvailable
(
1
)
==
1
return
t
.
limiter
.
TakeAvailable
(
1
)
==
1
}
}
func
(
t
*
tokenBucketRateLimiter
)
Saturation
()
float64
{
capacity
:=
t
.
limiter
.
Capacity
()
avail
:=
t
.
limiter
.
Available
()
return
float64
(
capacity
-
avail
)
/
float64
(
capacity
)
}
// Accept will block until a token becomes available
// Accept will block until a token becomes available
func
(
t
*
tokenBucketRateLimiter
)
Accept
()
{
func
(
t
*
tokenBucketRateLimiter
)
Accept
()
{
t
.
limiter
.
Wait
(
1
)
t
.
limiter
.
Wait
(
1
)
...
@@ -105,10 +94,6 @@ func (t *fakeAlwaysRateLimiter) TryAccept() bool {
...
@@ -105,10 +94,6 @@ func (t *fakeAlwaysRateLimiter) TryAccept() bool {
return
true
return
true
}
}
func
(
t
*
fakeAlwaysRateLimiter
)
Saturation
()
float64
{
return
0
}
func
(
t
*
fakeAlwaysRateLimiter
)
Stop
()
{}
func
(
t
*
fakeAlwaysRateLimiter
)
Stop
()
{}
func
(
t
*
fakeAlwaysRateLimiter
)
Accept
()
{}
func
(
t
*
fakeAlwaysRateLimiter
)
Accept
()
{}
...
@@ -131,10 +116,6 @@ func (t *fakeNeverRateLimiter) TryAccept() bool {
...
@@ -131,10 +116,6 @@ func (t *fakeNeverRateLimiter) TryAccept() bool {
return
false
return
false
}
}
func
(
t
*
fakeNeverRateLimiter
)
Saturation
()
float64
{
return
1
}
func
(
t
*
fakeNeverRateLimiter
)
Stop
()
{
func
(
t
*
fakeNeverRateLimiter
)
Stop
()
{
t
.
wg
.
Done
()
t
.
wg
.
Done
()
}
}
...
...
staging/src/k8s.io/client-go/util/flowcontrol/throttle_test.go
View file @
a9ed90f2
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
flowcontrol
package
flowcontrol
import
(
import
(
"math"
"sync"
"sync"
"testing"
"testing"
"time"
"time"
...
@@ -116,29 +115,6 @@ func TestThrottle(t *testing.T) {
...
@@ -116,29 +115,6 @@ func TestThrottle(t *testing.T) {
}
}
}
}
func
TestRateLimiterSaturation
(
t
*
testing
.
T
)
{
const
e
=
0.000001
tests
:=
[]
struct
{
capacity
int
take
int
expectedSaturation
float64
}{
{
1
,
1
,
1
},
{
10
,
3
,
0.3
},
}
for
i
,
tt
:=
range
tests
{
rl
:=
NewTokenBucketRateLimiter
(
1
,
tt
.
capacity
)
for
i
:=
0
;
i
<
tt
.
take
;
i
++
{
rl
.
Accept
()
}
if
math
.
Abs
(
rl
.
Saturation
()
-
tt
.
expectedSaturation
)
>
e
{
t
.
Fatalf
(
"#%d: Saturation rate difference isn't within tolerable range
\n
want=%f, get=%f"
,
i
,
tt
.
expectedSaturation
,
rl
.
Saturation
())
}
}
}
func
TestAlwaysFake
(
t
*
testing
.
T
)
{
func
TestAlwaysFake
(
t
*
testing
.
T
)
{
rl
:=
NewFakeAlwaysRateLimiter
()
rl
:=
NewFakeAlwaysRateLimiter
()
if
!
rl
.
TryAccept
()
{
if
!
rl
.
TryAccept
()
{
...
...
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