flowcontrol

package
v4.0.0-beta.0+incompat... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2017 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

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

func NewBackOff

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

func NewFakeBackOff

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

func (*Backoff) DeleteEntry

func (p *Backoff) DeleteEntry(id string)

func (*Backoff) GC

func (p *Backoff) GC()

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

func (*Backoff) Get

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

Get the current backoff Duration

func (*Backoff) IsInBackOffSince

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

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

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

move backoff to the next mark, capping at maxDuration

func (*Backoff) Reset

func (p *Backoff) Reset(id string)

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

type Clock

type Clock interface {
	ratelimit.Clock
}

An injectable, mockable clock interface.

type RateLimiter

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()
	// 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() float32
}

func NewFakeAlwaysRateLimiter

func NewFakeAlwaysRateLimiter() RateLimiter

func NewFakeNeverRateLimiter

func NewFakeNeverRateLimiter() RateLimiter

func NewTokenBucketRateLimiter

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

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL