Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DynamicRateLimiter ¶ added in v0.7.0
type DynamicRateLimiter struct {
// contains filtered or unexported fields
}
DynamicRateLimiter implements a dynamic config wrapper around the rate limiter
func NewDynamicRateLimiter ¶ added in v0.7.0
func NewDynamicRateLimiter(rps RPSFunc) *DynamicRateLimiter
NewDynamicRateLimiter returns a rate limiter which handles dynamic config
func (*DynamicRateLimiter) Allow ¶ added in v0.7.0
func (d *DynamicRateLimiter) Allow() bool
Allow immediately returns with true or false indicating if a rate limit token is available or not
func (*DynamicRateLimiter) Reserve ¶ added in v0.7.0
func (d *DynamicRateLimiter) Reserve() *rate.Reservation
Reserve reserves a rate limit token
type Info ¶ added in v0.7.0
type Info struct {
Namespace string
}
Info corresponds to information required to determine rate limits
type Limiter ¶ added in v0.7.0
type Limiter interface { // Allow attempts to allow a request to go through. The method returns // immediately with a true or false indicating if the request can make // progress Allow() bool // Wait waits till the deadline for a rate limit token to allow the request // to go through. Wait(ctx context.Context) error }
Limiter corresponds to basic rate limiting functionality.
type MultiStageRateLimiter ¶ added in v0.7.0
MultiStageRateLimiter indicates a namespace specific rate limit policy
func NewMultiStageRateLimiter ¶ added in v0.7.0
func NewMultiStageRateLimiter(rps RPSFunc, namespaceRps RPSKeyFunc) *MultiStageRateLimiter
NewMultiStageRateLimiter returns a new namespace quota rate limiter. This is about an order of magnitude slower than
func (*MultiStageRateLimiter) Allow ¶ added in v0.7.0
func (d *MultiStageRateLimiter) Allow(info Info) bool
Allow attempts to allow a request to go through. The method returns immediately with a true or false indicating if the request can make progress
type Policy ¶
type Policy interface { // Allow attempts to allow a request to go through. The method returns // immediately with a true or false indicating if the request can make // progress Allow(info Info) bool }
Policy corresponds to a quota policy. A policy allows implementing layered and more complex rate limiting functionality.
type RPSKeyFunc ¶ added in v0.7.0
RPSKeyFunc returns a float64 as the RPS for the given key
type RateLimiter ¶ added in v0.7.0
RateLimiter is a wrapper around the golang rate limiter handling dynamic configuration updates of the max dispatch per second. This has comparable performance to the token bucket rate limiter. BenchmarkSimpleRateLimiter-4 10000000 114 ns/op (tokenbucket) BenchmarkRateLimiter-4 10000000 148 ns/op (this)
func NewRateLimiter ¶ added in v0.7.0
func NewRateLimiter(maxDispatchPerSecond *float64, ttl time.Duration, minBurst int) *RateLimiter
NewRateLimiter returns a new rate limiter that can handle dynamic configuration updates
func NewSimpleRateLimiter ¶
func NewSimpleRateLimiter(rps int) *RateLimiter
NewSimpleRateLimiter returns a new rate limiter backed by the golang rate limiter
func (*RateLimiter) Allow ¶ added in v0.7.0
func (rl *RateLimiter) Allow() bool
Allow immediately returns with true or false indicating if a rate limit token is available or not
func (*RateLimiter) Limit ¶ added in v0.7.0
func (rl *RateLimiter) Limit() float64
Limit returns the current rate per second limit for this ratelimiter
func (*RateLimiter) Reserve ¶ added in v0.7.0
func (rl *RateLimiter) Reserve() *rate.Reservation
Reserve reserves a rate limit token
func (*RateLimiter) UpdateMaxDispatch ¶ added in v0.7.0
func (rl *RateLimiter) UpdateMaxDispatch(maxDispatchPerSecond *float64)
UpdateMaxDispatch updates the max dispatch rate of the rate limiter