Documentation
¶
Index ¶
- type DimensionConfig
- type Limiter
- func (l *Limiter) Allow(label string) bool
- func (l *Limiter) ConcurrencyUnlimit(label string)
- func (l *Limiter) GetConcurrencyLimiterStatus(label string) (limit uint64, current uint64)
- func (l *Limiter) GetQPSLimiterStatus(label string) (limit rate.Limit, burst int)
- func (l *Limiter) IsInAllowList(label string) bool
- func (l *Limiter) QPSUnlimit(label string)
- func (l *Limiter) Release(label string)
- func (l *Limiter) Update(label string, opts ...Option) UpdateStatus
- type Option
- type RateLimiter
- func (l *RateLimiter) Allow() bool
- func (l *RateLimiter) AllowN(n int) bool
- func (l *RateLimiter) Available(n int) bool
- func (l *RateLimiter) Burst() int
- func (l *RateLimiter) Limit() rate.Limit
- func (l *RateLimiter) SetBurst(burst int)
- func (l *RateLimiter) SetLimit(limit rate.Limit)
- func (l *RateLimiter) WaitN(ctx context.Context, n int) error
- type UpdateStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DimensionConfig ¶
type DimensionConfig struct { // qps conifg QPS float64 QPSBurst int // concurrency config ConcurrencyLimit uint64 }
DimensionConfig is the limit dimension config of one label
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter is a controller for the request rate.
func NewLimiter ¶
func NewLimiter() *Limiter
NewLimiter returns a global limiter which can be updated in the later.
func (*Limiter) ConcurrencyUnlimit ¶
ConcurrencyUnlimit deletes concurrency limiter of the given label
func (*Limiter) GetConcurrencyLimiterStatus ¶
GetConcurrencyLimiterStatus returns the status of a given label's concurrency limiter.
func (*Limiter) GetQPSLimiterStatus ¶
GetQPSLimiterStatus returns the status of a given label's QPS limiter.
func (*Limiter) IsInAllowList ¶
IsInAllowList returns whether this label is in allow list. If returns true, the given label won't be limited
func (*Limiter) QPSUnlimit ¶
QPSUnlimit deletes QPS limiter of the given label
type Option ¶
type Option func(string, *Limiter) UpdateStatus
Option is used to create a limiter with the optional settings. these setting is used to add a kind of limiter for a service
func AddLabelAllowList ¶
func AddLabelAllowList() Option
AddLabelAllowList adds a label into allow list. It means the given label will not be limited
func UpdateConcurrencyLimiter ¶
UpdateConcurrencyLimiter creates a concurrency limiter for a given label if it doesn't exist.
func UpdateDimensionConfig ¶
func UpdateDimensionConfig(cfg *DimensionConfig) Option
UpdateDimensionConfig creates QPS limiter and concurrency limiter for a given label by config if it doesn't exist.
func UpdateQPSLimiter ¶
UpdateQPSLimiter creates a QPS limiter for a given label if it doesn't exist.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter is a rate limiter based on `golang.org/x/time/rate`. It implements `Available` function which is not included in `golang.org/x/time/rate`. Note: AvailableN will increase the wait time of WaitN.
func NewRateLimiter ¶
func NewRateLimiter(r float64, b int) *RateLimiter
NewRateLimiter returns a new Limiter that allows events up to rate r (it means limiter refill r token per second) and permits bursts of at most b tokens.
func (*RateLimiter) Allow ¶
func (l *RateLimiter) Allow() bool
Allow is same as `rate.Limiter.Allow`.
func (*RateLimiter) AllowN ¶
func (l *RateLimiter) AllowN(n int) bool
AllowN is same as `rate.Limiter.AllowN`.
func (*RateLimiter) Available ¶
func (l *RateLimiter) Available(n int) bool
Available returns whether limiter has enough tokens. Note: Available will increase the wait time of WaitN.
func (*RateLimiter) Burst ¶
func (l *RateLimiter) Burst() int
Burst returns the maximum burst size. Burst is the maximum number of tokens that can be consumed in a single call to Allow, Reserve, or Wait, so higher Burst values allow more events to happen at once. A zero Burst allows no events, unless limit == Inf.
func (*RateLimiter) Limit ¶
func (l *RateLimiter) Limit() rate.Limit
Limit returns the maximum overall event rate.
func (*RateLimiter) SetBurst ¶
func (l *RateLimiter) SetBurst(burst int)
SetBurst is shorthand for SetBurstAt(time.Now(), newBurst).
func (*RateLimiter) SetLimit ¶
func (l *RateLimiter) SetLimit(limit rate.Limit)
SetLimit is shorthand for SetLimitAt(time.Now(), newLimit).
func (*RateLimiter) WaitN ¶
func (l *RateLimiter) WaitN(ctx context.Context, n int) error
WaitN blocks until lim permits n events to happen. It returns an error if n exceeds the Limiter's burst size, the Context is canceled, or the expected wait time exceeds the Context's Deadline. The burst limit is ignored if the rate limit is Inf.
type UpdateStatus ¶
type UpdateStatus uint32
UpdateStatus is flags for updating limiter config.
const ( // QPSNoChange shows that limiter's config isn't changed. QPSNoChange UpdateStatus = 1 << iota // QPSChanged shows that limiter's config is changed and not deleted. QPSChanged // QPSDeleted shows that limiter's config is deleted. QPSDeleted // ConcurrencyNoChange shows that limiter's config isn't changed. ConcurrencyNoChange // ConcurrencyChanged shows that limiter's config is changed and not deleted. ConcurrencyChanged // ConcurrencyDeleted shows that limiter's config is deleted. ConcurrencyDeleted // InAllowList shows that limiter's config isn't changed because it is in in allow list. InAllowList )
Flags for limiter.