Documentation ¶
Index ¶
- type BasicTokenBucket
- func (btb *BasicTokenBucket) GetFillRate() float64
- func (btb *BasicTokenBucket) PassThrough() bool
- func (btb *BasicTokenBucket) PreprocessRequest(now time.Time, rContext Request) bool
- func (btb *BasicTokenBucket) Return(tokens float64)
- func (btb *BasicTokenBucket) SetFillRate(now time.Time, fillRate float64)
- func (btb *BasicTokenBucket) SetPassThrough(passThrough bool)
- func (btb *BasicTokenBucket) Take(now time.Time, tokens float64) (time.Duration, bool)
- func (btb *BasicTokenBucket) TakeIfAvailable(now time.Time, tokens float64) bool
- type Request
- type Scheduler
- type TokenBucketLoadMultiplier
- func (tbls *TokenBucketLoadMultiplier) LoadMultiplier() float64
- func (tbls *TokenBucketLoadMultiplier) PassThrough() bool
- func (tbls *TokenBucketLoadMultiplier) PreprocessRequest(now time.Time, rContext Request) bool
- func (tbls *TokenBucketLoadMultiplier) Return(tokens float64)
- func (tbls *TokenBucketLoadMultiplier) SetContinuousTracking(continuousTracking bool)
- func (tbls *TokenBucketLoadMultiplier) SetLoadMultiplier(now time.Time, lm float64)
- func (tbls *TokenBucketLoadMultiplier) SetPassThrough(passThrough bool)
- func (tbls *TokenBucketLoadMultiplier) Take(now time.Time, tokens float64) (time.Duration, bool)
- func (tbls *TokenBucketLoadMultiplier) TakeIfAvailable(now time.Time, tokens float64) bool
- type TokenBucketLoadMultiplierMetrics
- type TokenBucketMetrics
- type TokenManager
- type WFQMetrics
- type WFQScheduler
- type WindowedCounter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BasicTokenBucket ¶
type BasicTokenBucket struct {
// contains filtered or unexported fields
}
BasicTokenBucket is a basic token bucket implementation.
func NewBasicTokenBucket ¶
func NewBasicTokenBucket(now time.Time, fillRate float64, metrics *TokenBucketMetrics) *BasicTokenBucket
NewBasicTokenBucket creates a new BasicTokenBucket with adjusted fill rate.
func (*BasicTokenBucket) GetFillRate ¶
func (btb *BasicTokenBucket) GetFillRate() float64
GetFillRate returns the fill rate of the BasicTokenBucket.
func (*BasicTokenBucket) PassThrough ¶
func (btb *BasicTokenBucket) PassThrough() bool
PassThrough returns the passThrough flag of the BasicTokenBucket.
func (*BasicTokenBucket) PreprocessRequest ¶
func (btb *BasicTokenBucket) PreprocessRequest(now time.Time, rContext Request) bool
PreprocessRequest is a no-op for BasicTokenBucket and by default, it rejects the request.
func (*BasicTokenBucket) Return ¶
func (btb *BasicTokenBucket) Return(tokens float64)
Return returns tokens to the basic token bucket.
func (*BasicTokenBucket) SetFillRate ¶
func (btb *BasicTokenBucket) SetFillRate(now time.Time, fillRate float64)
SetFillRate adjusts the fill rate of the BasicTokenBucket.
func (*BasicTokenBucket) SetPassThrough ¶
func (btb *BasicTokenBucket) SetPassThrough(passThrough bool)
SetPassThrough sets the passThrough flag of the BasicTokenBucket.
func (*BasicTokenBucket) Take ¶
Take takes tokens from the basic token bucket even if available tokens are less than asked. If tokens are not available at the moment, it will return amount of wait time and checks whether the operation was successful or not.
func (*BasicTokenBucket) TakeIfAvailable ¶
func (btb *BasicTokenBucket) TakeIfAvailable(now time.Time, tokens float64) bool
TakeIfAvailable takes tokens from the basic token bucket if available, otherwise return false.
type Request ¶
type Request struct { FairnessLabel string // for enforcing fairness Tokens uint64 // tokens (e.g. expected latency or complexity) for this request Priority uint8 // larger values represent higher priority }
Request is metadata for request in a flow that is to be allowed or dropped based on controlled delay and queue limits.
type Scheduler ¶
type Scheduler interface { // Schedule sends RequestContext to the underlying scheduler and returns a boolean value, // where true means accept and false means reject. Schedule(ctx context.Context, request Request) bool }
Scheduler : Interface for schedulers.
func NewWFQScheduler ¶
func NewWFQScheduler(tokenManger TokenManager, clk clockwork.Clock, metrics *WFQMetrics) Scheduler
NewWFQScheduler creates a new weighted fair queue scheduler.
type TokenBucketLoadMultiplier ¶
type TokenBucketLoadMultiplier struct {
// contains filtered or unexported fields
}
TokenBucketLoadMultiplier is a token bucket with load multiplier.
func NewTokenBucketLoadMultiplier ¶
func NewTokenBucketLoadMultiplier(now time.Time, slotCount uint8, slotDuration time.Duration, metrics *TokenBucketLoadMultiplierMetrics, ) *TokenBucketLoadMultiplier
NewTokenBucketLoadMultiplier creates a new TokenBucketLoadMultiplier.
func (*TokenBucketLoadMultiplier) LoadMultiplier ¶
func (tbls *TokenBucketLoadMultiplier) LoadMultiplier() float64
LoadMultiplier returns the current load multiplier.
func (*TokenBucketLoadMultiplier) PassThrough ¶
func (tbls *TokenBucketLoadMultiplier) PassThrough() bool
PassThrough gets value of PassThrough flag.
func (*TokenBucketLoadMultiplier) PreprocessRequest ¶
func (tbls *TokenBucketLoadMultiplier) PreprocessRequest(now time.Time, rContext Request) bool
PreprocessRequest preprocesses a request and makes decision whether to accept or reject the request.
func (*TokenBucketLoadMultiplier) Return ¶
func (tbls *TokenBucketLoadMultiplier) Return(tokens float64)
Return returns tokens to the token bucket.
func (*TokenBucketLoadMultiplier) SetContinuousTracking ¶
func (tbls *TokenBucketLoadMultiplier) SetContinuousTracking(continuousTracking bool)
SetContinuousTracking sets whether to continuously track the token rate and adjust the fill rate based on load multiplier.
func (*TokenBucketLoadMultiplier) SetLoadMultiplier ¶
func (tbls *TokenBucketLoadMultiplier) SetLoadMultiplier(now time.Time, lm float64)
SetLoadMultiplier sets the load multiplier number --> 0 = no load accepted, 1 = accept up to 100% of current load, 2 = accept up to 200% of current load.
func (*TokenBucketLoadMultiplier) SetPassThrough ¶
func (tbls *TokenBucketLoadMultiplier) SetPassThrough(passThrough bool)
SetPassThrough sets PassThrough flag which decides whether to pass through requests.
func (*TokenBucketLoadMultiplier) Take ¶
Take takes tokens from the token bucket even if available tokens are less than asked. If tokens are not available at the moment, it will return amount of wait time and checks whether the operation was successful or not.
func (*TokenBucketLoadMultiplier) TakeIfAvailable ¶
func (tbls *TokenBucketLoadMultiplier) TakeIfAvailable(now time.Time, tokens float64) bool
TakeIfAvailable takes tokens from the token bucket if available, otherwise return false.
type TokenBucketLoadMultiplierMetrics ¶
type TokenBucketLoadMultiplierMetrics struct { LMGauge prometheus.Gauge TokenBucketMetrics *TokenBucketMetrics }
TokenBucketLoadMultiplierMetrics holds metrics related to internals of TokenBucketLoadMultiplier.
type TokenBucketMetrics ¶
type TokenBucketMetrics struct { FillRateGauge prometheus.Gauge BucketCapacityGauge prometheus.Gauge AvailableTokensGauge prometheus.Gauge }
TokenBucketMetrics holds metrics related to internals of TokenBucket.
type TokenManager ¶
type TokenManager interface { // Take tokens if available, otherwise return false TakeIfAvailable(now time.Time, tokens float64) bool // Take tokens even if available tokens are less than asked - returns wait time if tokens are not available immediately. The other return value conveys whether the operation was successful or not. Take(now time.Time, tokens float64) (time.Duration, bool) // Return tokens, useful when requests choose to drop themselves on timeout or cancellation Return(tokens float64) // Provides TokenManager the request that the scheduler processing -- some TokenManager implementations use this level of visibility for their algorithms. Return value decides whether the request has to be accepted right away in case TokenManger is not yet ready or configured to accept all traffic (short circuit). PreprocessRequest(now time.Time, request Request) bool }
TokenManager : Interface for token managers.
type WFQMetrics ¶
type WFQMetrics struct { FlowsGauge prometheus.Gauge HeapRequestsGauge prometheus.Gauge }
WFQMetrics holds metrics related to internal workings of WFQScheduler.
type WFQScheduler ¶
type WFQScheduler struct {
// contains filtered or unexported fields
}
WFQScheduler : Weighted Fair Queue Scheduler.
func (*WFQScheduler) GetPendingFlows ¶
func (sched *WFQScheduler) GetPendingFlows() int
GetPendingFlows returns the number of flows in the scheduler.
func (*WFQScheduler) GetPendingRequests ¶
func (sched *WFQScheduler) GetPendingRequests() int
GetPendingRequests returns the number of requests in the scheduler.
type WindowedCounter ¶
type WindowedCounter struct {
// contains filtered or unexported fields
}
WindowedCounter is a token bucket with a windowed counter.
func NewWindowedCounter ¶
func NewWindowedCounter(now time.Time, totalSlots uint8, slotDuration time.Duration) *WindowedCounter
NewWindowedCounter creates a new WindowedCounter with extra slot for the current window.
func (*WindowedCounter) AddTokens ¶
func (counter *WindowedCounter) AddTokens(now time.Time, tokens uint64) bool
AddTokens to the counter. Return value is true when counter shifted slots and the all the slots in the counter is valid.
func (*WindowedCounter) CalculateTokenRate ¶
func (counter *WindowedCounter) CalculateTokenRate() float64
CalculateTokenRate returns the calculated token rate in the current window.
func (*WindowedCounter) IsBootstrapping ¶
func (counter *WindowedCounter) IsBootstrapping() bool
IsBootstrapping checks whether the counter is in bootstrapping mode.