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.
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.