client-go: k8s.io/client-go/util/flowcontrol Index | Files

package flowcontrol

import "k8s.io/client-go/util/flowcontrol"

Index

Package Files

backoff.go throttle.go

type Backoff Uses

type Backoff struct {
    sync.Mutex
    Clock clock.Clock
    // contains filtered or unexported fields
}

func NewBackOff Uses

func NewBackOff(initial, max time.Duration) *Backoff

func NewFakeBackOff Uses

func NewFakeBackOff(initial, max time.Duration, tc *clock.FakeClock) *Backoff

func (*Backoff) DeleteEntry Uses

func (p *Backoff) DeleteEntry(id string)

func (*Backoff) GC Uses

func (p *Backoff) GC()

Garbage collect records that have aged past maxDuration. Backoff users are expected to invoke this periodically.

func (*Backoff) Get Uses

func (p *Backoff) Get(id string) time.Duration

Get the current backoff Duration

func (*Backoff) IsInBackOffSince Uses

func (p *Backoff) IsInBackOffSince(id string, eventTime time.Time) bool

Returns True if the elapsed time since eventTime is smaller than the current backoff window

func (*Backoff) IsInBackOffSinceUpdate Uses

func (p *Backoff) IsInBackOffSinceUpdate(id string, eventTime time.Time) bool

Returns True if time since lastupdate is less than the current backoff window.

func (*Backoff) Next Uses

func (p *Backoff) Next(id string, eventTime time.Time)

move backoff to the next mark, capping at maxDuration

func (*Backoff) Reset Uses

func (p *Backoff) Reset(id string)

Reset forces clearing of all backoff data for a given key.

type Clock Uses

type Clock interface {
    Now() time.Time
    Sleep(time.Duration)
}

An injectable, mockable clock interface.

type RateLimiter Uses

type RateLimiter interface {
    // 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
    Stop()
    // QPS returns QPS of this rate limiter
    QPS() float32
}

func NewFakeAlwaysRateLimiter Uses

func NewFakeAlwaysRateLimiter() RateLimiter

func NewFakeNeverRateLimiter Uses

func NewFakeNeverRateLimiter() RateLimiter

func NewTokenBucketRateLimiter Uses

func NewTokenBucketRateLimiter(qps float32, burst int) RateLimiter

NewTokenBucketRateLimiter creates a rate limiter which implements a token bucket approach. The rate limiter allows bursts of up to 'burst' to exceed the QPS, while still maintaining a smoothed qps rate of 'qps'. The bucket is initially filled with 'burst' tokens, and refills at a rate of 'qps'. The maximum number of tokens in the bucket is capped at 'burst'.

func NewTokenBucketRateLimiterWithClock Uses

func NewTokenBucketRateLimiterWithClock(qps float32, burst int, c Clock) RateLimiter

NewTokenBucketRateLimiterWithClock is identical to NewTokenBucketRateLimiter but allows an injectable clock, for testing.

Package flowcontrol imports 5 packages (graph) and is imported by 490 packages. Updated 2018-07-05. Refresh now. Tools for package owners.