Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLimiterWrapper ¶
func NewLimiterWrapper(conLimit ConcurrencyLimiter, qpsLimit RateLimiter) limit.Updater
NewLimiterWrapper wraps the given ConcurrencyLimiter and RateLimiter into a limit.Updater.
Types ¶
type ConcurrencyLimiter ¶
type ConcurrencyLimiter interface { // Acquire reports if next access to the protected resource is allowed. Acquire() bool // Release claims a previous taken access has released the resource. Release() // Status returns the total quota and occupied. Status() (limit, occupied int) }
ConcurrencyLimiter limits the number of concurrent access towards the protected resource. The implementation of ConcurrencyLimiter should be concurrent safe.
func NewConcurrencyLimiter ¶
func NewConcurrencyLimiter(lim int) ConcurrencyLimiter
NewConcurrencyLimiter returns a new ConcurrencyLimiter with the given limit.
type DummyConcurrencyLimiter ¶
type DummyConcurrencyLimiter struct{}
DummyConcurrencyLimiter implements ConcurrencyLimiter but without actual limitation.
func (*DummyConcurrencyLimiter) Acquire ¶
func (dcl *DummyConcurrencyLimiter) Acquire() bool
Acquire .
func (*DummyConcurrencyLimiter) Status ¶
func (dcl *DummyConcurrencyLimiter) Status() (limit, occupied int)
Status .
type DummyRateLimiter ¶
type DummyRateLimiter struct{}
DummyRateLimiter implements RateLimiter but without actual limitation.
type LimitReporter ¶
type LimitReporter interface { ConnOverloadReport() QPSOverloadReport() }
LimitReporter is the interface define to report(metric or print log) when limit happen
type RateLimiter ¶
type RateLimiter interface { // Acquire reports if next access to the protected resource is allowed. Acquire() bool // Status returns the rate limit. Status() (max, current int, interval time.Duration) }
RateLimiter limits the access rate towards the protected resource.
func NewQPSLimiter ¶
func NewQPSLimiter(interval time.Duration, limit int) RateLimiter
NewQPSLimiter creates qpsLimiter.