Documentation
¶
Index ¶
- Constants
- Variables
- func CreateOptions(opts ...Option) *options
- type BasicConcLimiter
- type BasicLimiter
- type BasicRateLimiter
- type Cancelable
- type Canceler
- type ConcLimitOption
- type ConcLimiter
- type ConcurrencyTracker
- func (me *ConcurrencyTracker) Add()
- func (me *ConcurrencyTracker) Current() int32
- func (me *ConcurrencyTracker) Elapsed() time.Duration
- func (me *ConcurrencyTracker) Max() int32
- func (me *ConcurrencyTracker) Rate() float64
- func (me *ConcurrencyTracker) Start()
- func (me *ConcurrencyTracker) Stop()
- func (me *ConcurrencyTracker) Subtract()
- func (me *ConcurrencyTracker) Total() int32
- type Limiter
- type NoLimitRateLimiter
- type Option
- type RateLimitOption
- type RateLimiter
- type Slot
- type TestableRateLimiter
Constants ¶
const DEFAULT_CONCURRENCY = 1
const DEFAULT_RATE = 1.0
Variables ¶
var DeadlineExceeded = errors.New("Timeout Exceeded")
var LimiterStopped = errors.New("Limiter has been stopped")
var OutStream io.Writer
If Limiter.Execute() panicks the stack trace will be sent down OutStream The default value is os.Stdout
Functions ¶
func CreateOptions ¶
func CreateOptions(opts ...Option) *options
Creates an instance of options out of a slice of Options
Types ¶
type BasicConcLimiter ¶
type BasicConcLimiter struct {
// contains filtered or unexported fields
}
func NewConcLimiter ¶
func NewConcLimiter(size int) *BasicConcLimiter
Creates a new concurrency limiter if size is <= 1, a default of 1 will be used
func (*BasicConcLimiter) Acquire ¶
func (me *BasicConcLimiter) Acquire(ctx context.Context) (Slot, error)
func (*BasicConcLimiter) Cancel ¶
func (me *BasicConcLimiter) Cancel()
func (*BasicConcLimiter) Concurrency ¶
func (me *BasicConcLimiter) Concurrency() int
func (*BasicConcLimiter) Wait ¶
func (me *BasicConcLimiter) Wait()
type BasicLimiter ¶
type BasicLimiter struct {
// contains filtered or unexported fields
}
A limiter that supports limiting by concurrency and rate
func DefaultLimiter ¶
func DefaultLimiter(rate float64, concurrency int) *BasicLimiter
func NewLimiter ¶
func NewLimiter(opts ...Option) *BasicLimiter
func (*BasicLimiter) Execute ¶
Once available time or concurrency becomes available execute function fn in a go routine DeadlineExceeded is returned if the timeout elapses before rate and concurrency slots can be acquired
func (*BasicLimiter) Wait ¶
func (me *BasicLimiter) Wait()
Waits for all executions to complete before returning
type BasicRateLimiter ¶
type BasicRateLimiter struct {
// contains filtered or unexported fields
}
func (*BasicRateLimiter) Cancel ¶
func (me *BasicRateLimiter) Cancel()
func (*BasicRateLimiter) Rate ¶
func (me *BasicRateLimiter) Rate() float64
func (*BasicRateLimiter) XXX_TEST_Wait ¶
func (me *BasicRateLimiter) XXX_TEST_Wait(tokens int64, ctx context.Context) error
This allows us to force a timeout in testing by setting the number of desired tokens to a high value
type Cancelable ¶
TODO: This interface may just be a waste, it's not being used right now
type Canceler ¶
type Canceler struct {
// contains filtered or unexported fields
}
func NewCanceler ¶
func NewCanceler() *Canceler
func (*Canceler) IsCanceled ¶
type ConcLimitOption ¶
type ConcLimitOption struct {
Limiter ConcLimiter
}
option for controlling concurrency
type ConcLimiter ¶
type ConcLimiter interface {
// Wait for a slot to become available
// only DeadlineExceeded and LimiterStopped errors can be returned
Acquire(ctx context.Context) (Slot, error)
// Put the slot back into the pool
// Release()
// Cancels processing outstanding acquisition requests
Cancel()
// The configured concurrency
Concurrency() int
// Wait for all Slots to be returned
Wait()
}
Provides a thread-safe mechanism for acquiring and releasing slots Calling Stop() will unblock Acquire() if it's waiting on a slot
type ConcurrencyTracker ¶
type ConcurrencyTracker struct {
// contains filtered or unexported fields
}
func (*ConcurrencyTracker) Add ¶
func (me *ConcurrencyTracker) Add()
func (*ConcurrencyTracker) Current ¶
func (me *ConcurrencyTracker) Current() int32
func (*ConcurrencyTracker) Elapsed ¶
func (me *ConcurrencyTracker) Elapsed() time.Duration
func (*ConcurrencyTracker) Max ¶
func (me *ConcurrencyTracker) Max() int32
func (*ConcurrencyTracker) Rate ¶
func (me *ConcurrencyTracker) Rate() float64
func (*ConcurrencyTracker) Start ¶
func (me *ConcurrencyTracker) Start()
func (*ConcurrencyTracker) Stop ¶
func (me *ConcurrencyTracker) Stop()
func (*ConcurrencyTracker) Subtract ¶
func (me *ConcurrencyTracker) Subtract()
func (*ConcurrencyTracker) Total ¶
func (me *ConcurrencyTracker) Total() int32
type Limiter ¶
type Limiter interface {
// Stops the limiter
Stop()
// Waits for all executions to complete before returning
Wait()
// Once available time or concurrency becomes available
// execute function fn in a go routine
// DeadlineExceeded is returned if the timeout elapses before rate and concurrency slots can be acquired
// fn's implementer can choose whether to adhere to the Context parameter's Doneness
Execute(ctx context.Context, fn func(context.Context)) error
}
type NoLimitRateLimiter ¶
type NoLimitRateLimiter struct{}
A Null implementation of RateLimiter
func (*NoLimitRateLimiter) Cancel ¶
func (me *NoLimitRateLimiter) Cancel()
func (*NoLimitRateLimiter) Rate ¶
func (me *NoLimitRateLimiter) Rate() float64
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Base interface for all options
type RateLimitOption ¶
type RateLimitOption struct {
Limiter RateLimiter
}
option for controlling rate limiting
type RateLimiter ¶
type RateLimiter interface {
// Wait until there are resources available
// only DeadlineExceeded and LimiterStopped errors can be returned
Wait(ctx context.Context) error
// The configured rate
Rate() float64
// Cancels Wait()ing
Cancel()
}
func NewRateLimiter ¶
func NewRateLimiter(rate float64) RateLimiter
Returns a *BasicRateLimiter if rate > 0; otherwise a *NoLimitRateLimiter
type TestableRateLimiter ¶
type TestableRateLimiter interface {
RateLimiter
XXX_TEST_Wait(tokens int64, ctx context.Context) error
}