Documentation ¶
Overview ¶
Tokenbucket based request rate limiter
Index ¶
Constants ¶
View Source
const DefaultCapacity = 65536
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TokenBucket ¶
type TokenBucket struct {
// contains filtered or unexported fields
}
Implements token bucket rate limiting algorithm (http://en.wikipedia.org/wiki/Token_bucket) and is used by rate limiters to implement various rate limiting strategies
func NewTokenBucket ¶
func NewTokenBucket(rate Rate, maxTokens int64, timeProvider timetools.TimeProvider) (*TokenBucket, error)
func (*TokenBucket) Consume ¶
func (tb *TokenBucket) Consume(tokens int64) (time.Duration, error)
In case if there's enough tokens, consumes tokens and returns 0, nil In case if tokens to consume is larger than max burst returns -1, error In case if there's not enough tokens, returns time to wait till refill
type TokenLimiter ¶
type TokenLimiter struct {
// contains filtered or unexported fields
}
func NewTokenLimiter ¶
func NewTokenLimiter(mapper limit.MapperFn, rate Rate) (*TokenLimiter, error)
func (*TokenLimiter) GetBurst ¶
func (tl *TokenLimiter) GetBurst() int64
func (*TokenLimiter) GetCapacity ¶
func (tl *TokenLimiter) GetCapacity() int
func (*TokenLimiter) GetRate ¶
func (tl *TokenLimiter) GetRate() Rate
func (*TokenLimiter) ProcessRequest ¶
func (*TokenLimiter) ProcessResponse ¶
func (tl *TokenLimiter) ProcessResponse(r request.Request, a request.Attempt)
Click to show internal directories.
Click to hide internal directories.