limiter

package
v1.3.0-rc.1.0...-65594da Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter is a multi-tenant local rate limiter based on golang.org/x/time/rate. It requires a custom strategy in input, which is used to get the limit and burst settings for each tenant.

func NewRateLimiter

func NewRateLimiter(strategy RateLimiterStrategy, recheckPeriod time.Duration) *RateLimiter

NewRateLimiter makes a new multi-tenant rate limiter. Each per-tenant limiter is configured using the input strategy and its limit/burst is rechecked (and reconfigured if changed) every recheckPeriod.

func (*RateLimiter) AllowN

func (l *RateLimiter) AllowN(now time.Time, tenantID string, n int) bool

AllowN reports whether n tokens may be consumed happen at time now.

func (*RateLimiter) Burst

func (l *RateLimiter) Burst(now time.Time, tenantID string) int

Burst returns the currently configured maximum burst size.

func (*RateLimiter) Limit

func (l *RateLimiter) Limit(now time.Time, tenantID string) float64

Limit returns the currently configured maximum overall tokens rate.

type RateLimiterStrategy

type RateLimiterStrategy interface {
	Limit(tenantID string) float64
	Burst(tenantID string) int
}

RateLimiterStrategy defines the interface which a pluggable strategy should implement. The returned limit and burst can change over the time, and the local rate limiter will apply them every recheckPeriod.

Jump to

Keyboard shortcuts

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