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 EvictFunc ¶ added in v0.7.0
type EvictFunc func()
EvictFunc is a type denoting a function used to evict an element from a QueueBlockingLimiter backlog
type FifoBlockingLimiter ¶ added in v0.5.0
type FifoBlockingLimiter struct {
*QueueBlockingLimiter
}
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. Deprecated in favor of QueueBlockingLimiter
func NewFifoBlockingLimiter ¶ added in v0.5.0
func NewFifoBlockingLimiter( delegate core.Limiter, maxBacklogSize int, maxBacklogTimeout time.Duration, ) *FifoBlockingLimiter
NewFifoBlockingLimiter will create a new FifoBlockingLimiter Deprecated, use NewQueueBlockingLimiterFromConfig instead
func NewFifoBlockingLimiterWithDefaults ¶ added in v0.5.0
func NewFifoBlockingLimiterWithDefaults( delegate core.Limiter, ) *FifoBlockingLimiter
NewFifoBlockingLimiterWithDefaults will create a new FifoBlockingLimiter with default values. Deprecated, use NewQueueBlockingLimiterWithDefaults instead
type LifoBlockingLimiter ¶
type LifoBlockingLimiter struct {
*QueueBlockingLimiter
}
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. Deprecated in favor of QueueBlockingLimiter
func NewLifoBlockingLimiter ¶
func NewLifoBlockingLimiter( delegate core.Limiter, maxBacklogSize int, maxBacklogTimeout time.Duration, registry core.MetricRegistry, tags ...string, ) *LifoBlockingLimiter
NewLifoBlockingLimiter will create a new LifoBlockingLimiter Deprecated, use NewQueueBlockingLimiterFromConfig instead
func NewLifoBlockingLimiterWithDefaults ¶
func NewLifoBlockingLimiterWithDefaults( delegate core.Limiter, ) *LifoBlockingLimiter
NewLifoBlockingLimiterWithDefaults will create a new LifoBlockingLimiter with default values. Deprecated, use NewQueueBlockingLimiterFromConfig
type QueueBlockingLimiter ¶ added in v0.7.0
type QueueBlockingLimiter struct {
// contains filtered or unexported fields
}
QueueBlockingLimiter 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 NewQueueBlockingLimiterFromConfig ¶ added in v0.7.0
func NewQueueBlockingLimiterFromConfig( delegate core.Limiter, config QueueLimiterConfig, ) *QueueBlockingLimiter
NewQueueBlockingLimiterFromConfig will create a new QueueBlockingLimiter
func NewQueueBlockingLimiterWithDefaults ¶ added in v0.7.0
func NewQueueBlockingLimiterWithDefaults( delegate core.Limiter, ) *QueueBlockingLimiter
NewQueueBlockingLimiterWithDefaults will create a new QueueBlockingLimiter with default values.
func (*QueueBlockingLimiter) Acquire ¶ added in v0.7.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.
ctx Context for the request. The context is used by advanced strategies such as LookupPartitionStrategy and early queue eviction on context cancellation.
func (*QueueBlockingLimiter) String ¶ added in v0.7.0
func (l *QueueBlockingLimiter) String() string
type QueueBlockingListener ¶ added in v0.7.0
type QueueBlockingListener struct {
// contains filtered or unexported fields
}
QueueBlockingListener implements a blocking listener for the QueueBlockingLimiter
func (*QueueBlockingListener) OnDropped ¶ added in v0.7.0
func (l *QueueBlockingListener) 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 (*QueueBlockingListener) OnIgnore ¶ added in v0.7.0
func (l *QueueBlockingListener) 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 (*QueueBlockingListener) OnSuccess ¶ added in v0.7.0
func (l *QueueBlockingListener) OnSuccess()
OnSuccess is called as a notification that the operation succeeded and internally measured latency should be used as an RTT sample.
type QueueLimiterConfig ¶ added in v0.7.0
type QueueLimiterConfig struct { Ordering QueueOrdering `yaml:"ordering,omitempty" json:"ordering,omitempty"` MaxBacklogSize int `yaml:"maxBacklogSize,omitempty" json:"maxBacklogSize,omitempty"` MaxBacklogTimeout time.Duration `yaml:"maxBacklogTimeout,omitempty" json:"maxBacklogTimeout,omitempty"` BacklogEvictDoneCtx bool `yaml:"backlogEvictDoneCtx,omitempty" json:"backlogEvictDoneCtx,omitempty"` MetricRegistry core.MetricRegistry Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"` }
QueueLimiterConfig is a struct used to encapsulate the constructor arguments needed for creating a QueueBlockingLimiter instance
func (*QueueLimiterConfig) ApplyDefaults ¶ added in v0.7.0
func (c *QueueLimiterConfig) ApplyDefaults()
ApplyDefaults is used by QueueBlockingLimiter constructors to set defaults for optional limiter configuration arguments
type QueueOrdering ¶ added in v0.7.0
type QueueOrdering string
QueueOrdering is an enum used for configuring the order in which elements in a QueueBlockingLimiter backlog are consumed
const ( // OrderingFIFO is an enum constant used to represent // a first-in first-out ordering for queue elements. // This means that the oldest elements in a queue are // the first to be consumed OrderingFIFO QueueOrdering = "fifo" // OrderingLIFO is an enum constant used to represent // a last-in first-out ordering for queue elements. // This means that the newest elements in a queue are // the first to be consumed OrderingLIFO QueueOrdering = "lifo" )