limiter

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2019 License: Apache-2.0 Imports: 9 Imported by: 20

Documentation

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

func (l *BlockingLimiter) Acquire(ctx context.Context) (core.Listener, bool)

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

func (l *DeadlineLimiter) Acquire(ctx context.Context) (listener core.Listener, ok bool)

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

func (l *DefaultLimiter) Acquire(ctx context.Context) (core.Listener, bool)

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 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

func (l *LifoBlockingLimiter) Acquire(ctx context.Context) (core.Listener, bool)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL