Documentation ¶
Index ¶
- Constants
- Variables
- func CopyDefaultLimitConfig() iface.ConfigValueItem
- func NewLimiterWrapper(conLimit ConcurrencyLimiter, qpsLimit RateLimiter) limit.Updater
- type ConcurrencyLimiter
- type DummyConcurrencyLimiter
- type DummyRateLimiter
- type LimitReporter
- type LimiterConfig
- type RateLimiter
- type Updatable
Constants ¶
const TypeLimiter iface.ItemType = "limiter_config"
TypeLimiter serves as itemKey in ConfigValueImpl
Variables ¶
var NewLimiterConfig = util.JsonInitializer(func() iface.ConfigValueItem { return &LimiterConfig{} })
NewLimiterConfig decodes json bytes into a newly allocated LimiterConfig object
Functions ¶
func CopyDefaultLimitConfig ¶
func CopyDefaultLimitConfig() iface.ConfigValueItem
CopyDefaultLimitConfig copies the default limiter configuration and returns a new instance of it
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(ctx context.Context) bool // Release claims a previous taken access has released the resource. Release(ctx context.Context) // Status returns the total quota and occupied. Status(ctx context.Context) (limit, occupied int) }
ConcurrencyLimiter limits the number of concurrent access towards the protected resource. The implementation of ConcurrencyLimiter should be concurrent safe.
func NewConcurrencyLimiter
deprecated
func NewConcurrencyLimiter(lim int) ConcurrencyLimiter
Deprecated: Use NewConnectionLimiter instead.
func NewConnectionLimiter ¶
func NewConnectionLimiter(lim int) ConcurrencyLimiter
NewConnectionLimiter returns a new ConnectionLimiter with the given limit.
type DummyConcurrencyLimiter ¶
type DummyConcurrencyLimiter struct{}
DummyConcurrencyLimiter implements ConcurrencyLimiter but without actual limitation.
func (*DummyConcurrencyLimiter) Acquire ¶
func (dcl *DummyConcurrencyLimiter) Acquire(ctx context.Context) bool
Acquire .
func (*DummyConcurrencyLimiter) Release ¶
func (dcl *DummyConcurrencyLimiter) Release(ctx context.Context)
Release .
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 LimiterConfig ¶
type LimiterConfig struct { ConnectionLimit int64 `json:"connection_limit"` QPSLimit int64 `json:"qps_limit"` }
LimiterConfig represents the configuration for kitex server limiter zero value means no limit.
func (*LimiterConfig) DeepCopy ¶
func (l *LimiterConfig) DeepCopy() iface.ConfigValueItem
DeepCopy makes a deep copy of LimiterConfig struct and returns a new instance of iface.ConfigValueItem
func (*LimiterConfig) EqualsTo ¶
func (l *LimiterConfig) EqualsTo(item iface.ConfigValueItem) bool
EqualsTo determines if the LimiterConfig is equal to the given ConfigValueItem.
type RateLimiter ¶
type RateLimiter interface { // Acquire reports if next access to the protected resource is allowed. Acquire(ctx context.Context) bool // Status returns the rate limit. Status(ctx context.Context) (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.