Documentation ¶
Index ¶
- type Backoff
- func (p *Backoff) DeleteEntry(id string)
- func (p *Backoff) GC()
- func (p *Backoff) Get(id string) time.Duration
- func (p *Backoff) IsInBackOffSince(id string, eventTime time.Time) bool
- func (p *Backoff) IsInBackOffSinceUpdate(id string, eventTime time.Time) bool
- func (p *Backoff) Next(id string, eventTime time.Time)
- func (p *Backoff) Reset(id string)
- type Clock
- type RateLimiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
func NewBackOff ¶
func (*Backoff) DeleteEntry ¶
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) IsInBackOffSince ¶
Returns True if the elapsed time since eventTime is smaller than the current backoff window
func (*Backoff) IsInBackOffSinceUpdate ¶
Returns True if time since lastupdate is less than the current backoff window.
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() // QPS returns QPS of this rate limiter QPS() float32 // Wait returns nil if a token is taken before the Context is done. Wait(ctx context.Context) error }
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, c Clock) RateLimiter
NewTokenBucketRateLimiterWithClock is identical to NewTokenBucketRateLimiter but allows an injectable clock, for testing.