Remove Saturation() from rate limiter interface

Kubernetes-commit: a9ed90f227f07fab2da75541d57a5366ddb38f66
This commit is contained in:
Jordan Liggitt
2018-01-19 01:59:33 -05:00
committed by Kubernetes Publisher
parent 847d15469a
commit 7392f7f78f
2 changed files with 0 additions and 43 deletions

View File

@@ -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 {
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 {
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 {
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()
} }

View File

@@ -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) {
} }
} }
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() {