Documentation
¶
Overview ¶
Package limiter provides common limiter implementations that are useful.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockingLimiter ¶
type BlockingLimiter struct {
// contains filtered or unexported fields
}
BlockingLimiter implements a Limiter that blocks the caller when the limit has been reached. The caller is blocked until the limiter has been released. This limiter is commonly used in batch clients that use the limiter as a back-pressure mechanism.
func NewBlockingLimiter ¶
func NewBlockingLimiter( delegate core.Limiter, timeout time.Duration, logger limit.Logger, ) *BlockingLimiter
NewBlockingLimiter will create a new blocking limiter
func (*BlockingLimiter) Acquire ¶
Acquire a token from the limiter. Returns `nil, false` if the limit has been exceeded. If acquired the caller must call one of the Listener methods when the operation has been completed to release the count.
context Context for the request. The context is used by advanced strategies such as LookupPartitionStrategy.
func (BlockingLimiter) String ¶
func (l BlockingLimiter) String() string
type DeadlineLimiter ¶ added in v0.2.0
type DeadlineLimiter struct {
// contains filtered or unexported fields
}
DeadlineLimiter that blocks the caller when the limit has been reached. The caller is blocked until the limiter has been released, or a deadline has been passed.
func NewDeadlineLimiter ¶ added in v0.2.0
func NewDeadlineLimiter( delegate core.Limiter, deadline time.Time, logger limit.Logger, ) *DeadlineLimiter
NewDeadlineLimiter will create a new DeadlineLimiter that will wrap a limiter such that acquire will block until a provided deadline if the limit was reached instead of returning an empty listener immediately.
func (*DeadlineLimiter) Acquire ¶ added in v0.2.0
Acquire a token from the limiter. Returns `nil, false` if the limit has been exceeded. If acquired the caller must call one of the Listener methods when the operation has been completed to release the count.
context Context for the request. The context is used by advanced strategies such as LookupPartitionStrategy.
func (DeadlineLimiter) String ¶ added in v0.2.0
func (l DeadlineLimiter) String() string
String implements Stringer for easy debugging.
type DefaultLimiter ¶
type DefaultLimiter struct {
// contains filtered or unexported fields
}
DefaultLimiter is a Limiter that combines a plugable limit algorithm and enforcement strategy to enforce concurrency limits to a fixed resource.
func NewDefaultLimiter ¶
func NewDefaultLimiter( limit core.Limit, minWindowTime int64, maxWindowTime int64, minRTTThreshold int64, windowSize int, strategy core.Strategy, logger limit.Logger, registry core.MetricRegistry, ) (*DefaultLimiter, error)
NewDefaultLimiter creates a new DefaultLimiter.
func NewDefaultLimiterWithDefaults ¶
func NewDefaultLimiterWithDefaults( name string, strategy core.Strategy, logger limit.Logger, registry core.MetricRegistry, tags ...string, ) (*DefaultLimiter, error)
NewDefaultLimiterWithDefaults will create a DefaultLimit Limiter with the provided minimum config.
func (*DefaultLimiter) Acquire ¶
Acquire a token from the limiter. Returns an Optional.empty() if the limit has been exceeded. If acquired the caller must call one of the Listener methods when the operation has been completed to release the count.
context Context for the request. The context is used by advanced strategies such as LookupPartitionStrategy.
func (*DefaultLimiter) EstimatedLimit ¶
func (l *DefaultLimiter) EstimatedLimit() int
EstimatedLimit will return the current estimated limit.
func (*DefaultLimiter) String ¶
func (l *DefaultLimiter) String() string
type DefaultListener ¶
type DefaultListener struct {
// contains filtered or unexported fields
}
DefaultListener for
func (*DefaultListener) OnDropped ¶
func (l *DefaultListener) OnDropped()
OnDropped is called to indicate the request failed and was dropped due to being rejected by an external limit or hitting a timeout. Loss based Limit implementations will likely do an aggressive reducing in limit when this happens.
func (*DefaultListener) OnIgnore ¶
func (l *DefaultListener) OnIgnore()
OnIgnore is called to indicate the operation failed before any meaningful RTT measurement could be made and should be ignored to not introduce an artificially low RTT.
func (*DefaultListener) OnSuccess ¶
func (l *DefaultListener) OnSuccess()
OnSuccess is called as a notification that the operation succeeded and internally measured latency should be used as an RTT sample.
type DelegateListener ¶ added in v0.2.0
type DelegateListener struct {
// contains filtered or unexported fields
}
DelegateListener wraps the wrapped Limiter's Listener to simply delegate as a wrapper.
func NewDelegateListener ¶ added in v0.2.0
func NewDelegateListener(delegateListener core.Listener) *DelegateListener
NewDelegateListener creates a new wrapped listener.
func (*DelegateListener) OnDropped ¶ added in v0.2.0
func (l *DelegateListener) OnDropped()
OnDropped is called to indicate the request failed and was dropped due to being rejected by an external limit or hitting a timeout. Loss based Limit implementations will likely do an aggressive reducing in limit when this happens.
func (*DelegateListener) OnIgnore ¶ added in v0.2.0
func (l *DelegateListener) OnIgnore()
OnIgnore is called to indicate the operation failed before any meaningful RTT measurement could be made and should be ignored to not introduce an artificially low RTT.
func (*DelegateListener) OnSuccess ¶ added in v0.2.0
func (l *DelegateListener) OnSuccess()
OnSuccess is called as a notification that the operation succeeded and internally measured latency should be used as an RTT sample.
type FifoBlockingLimiter ¶ added in v0.5.0
type FifoBlockingLimiter struct {
// contains filtered or unexported fields
}
FifoBlockingLimiter implements a Limiter that blocks the caller when the limit has been reached. This strategy ensures the resource is properly protected but favors availability over latency by not fast failing requests when the limit has been reached. To help keep success latencies low and minimize timeouts any blocked requests are processed in last in/first out order.
Use this limiter only when the concurrency model allows the limiter to be blocked.
func NewFifoBlockingLimiter ¶ added in v0.5.0
func NewFifoBlockingLimiter( delegate core.Limiter, maxBacklogSize int, maxBacklogTimeout time.Duration, ) *FifoBlockingLimiter
NewFifoBlockingLimiter will create a new FifoBlockingLimiter
func NewFifoBlockingLimiterWithDefaults ¶ added in v0.5.0
func NewFifoBlockingLimiterWithDefaults( delegate core.Limiter, ) *FifoBlockingLimiter
NewFifoBlockingLimiterWithDefaults will create a new FifoBlockingLimiter with default values.
func (*FifoBlockingLimiter) Acquire ¶ added in v0.5.0
Acquire a token from the limiter. Returns an Optional.empty() if the limit has been exceeded. If acquired the caller must call one of the Listener methods when the operation has been completed to release the count.
context Context for the request. The context is used by advanced strategies such as LookupPartitionStrategy.
func (*FifoBlockingLimiter) String ¶ added in v0.5.0
func (l *FifoBlockingLimiter) String() string
type FifoBlockingListener ¶ added in v0.5.0
type FifoBlockingListener struct {
// contains filtered or unexported fields
}
FifoBlockingListener implements a blocking listener for the FifoBlockingListener
func (*FifoBlockingListener) OnDropped ¶ added in v0.5.0
func (l *FifoBlockingListener) OnDropped()
OnDropped is called to indicate the request failed and was dropped due to being rejected by an external limit or hitting a timeout. Loss based Limit implementations will likely do an aggressive reducing in limit when this happens.
func (*FifoBlockingListener) OnIgnore ¶ added in v0.5.0
func (l *FifoBlockingListener) OnIgnore()
OnIgnore is called to indicate the operation failed before any meaningful RTT measurement could be made and should be ignored to not introduce an artificially low RTT.
func (*FifoBlockingListener) OnSuccess ¶ added in v0.5.0
func (l *FifoBlockingListener) OnSuccess()
OnSuccess is called as a notification that the operation succeeded and internally measured latency should be used as an RTT sample.
type LifoBlockingLimiter ¶
type LifoBlockingLimiter struct {
// contains filtered or unexported fields
}
LifoBlockingLimiter implements a Limiter that blocks the caller when the limit has been reached. This strategy ensures the resource is properly protected but favors availability over latency by not fast failing requests when the limit has been reached. To help keep success latencies low and minimize timeouts any blocked requests are processed in last in/first out order.
Use this limiter only when the concurrency model allows the limiter to be blocked.
func NewLifoBlockingLimiter ¶
func NewLifoBlockingLimiter( delegate core.Limiter, maxBacklogSize int, maxBacklogTimeout time.Duration, ) *LifoBlockingLimiter
NewLifoBlockingLimiter will create a new LifoBlockingLimiter
func NewLifoBlockingLimiterWithDefaults ¶
func NewLifoBlockingLimiterWithDefaults( delegate core.Limiter, ) *LifoBlockingLimiter
NewLifoBlockingLimiterWithDefaults will create a new LifoBlockingLimiter with default values.
func (*LifoBlockingLimiter) Acquire ¶
Acquire a token from the limiter. Returns an Optional.empty() if the limit has been exceeded. If acquired the caller must call one of the Listener methods when the operation has been completed to release the count.
context Context for the request. The context is used by advanced strategies such as LookupPartitionStrategy.
func (*LifoBlockingLimiter) String ¶
func (l *LifoBlockingLimiter) String() string
type LifoBlockingListener ¶
type LifoBlockingListener struct {
// contains filtered or unexported fields
}
LifoBlockingListener implements a blocking listener for the LifoBlockingListener
func (*LifoBlockingListener) OnDropped ¶
func (l *LifoBlockingListener) OnDropped()
OnDropped is called to indicate the request failed and was dropped due to being rejected by an external limit or hitting a timeout. Loss based Limit implementations will likely do an aggressive reducing in limit when this happens.
func (*LifoBlockingListener) OnIgnore ¶
func (l *LifoBlockingListener) OnIgnore()
OnIgnore is called to indicate the operation failed before any meaningful RTT measurement could be made and should be ignored to not introduce an artificially low RTT.
func (*LifoBlockingListener) OnSuccess ¶
func (l *LifoBlockingListener) OnSuccess()
OnSuccess is called as a notification that the operation succeeded and internally measured latency should be used as an RTT sample.