limit

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2019 License: Apache-2.0 Imports: 2 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AIMDConfig

type AIMDConfig struct {
	// MinimumLimit is the mimimum limit the algorithm will decrease. It also will start with this limit.
	MinimumLimit int
	// This is like TCP algorithms `ssthresh`. It will start increasing the limit by one
	// and when reached to this threshold it will change the mode and increase slowly.
	// If set to 0 then slow start will be disabled.
	SlowStartThreshold int
	// RTTTimeout is the rtt is greater than this value it will be measured as a failure.
	RTTTimeout time.Duration
	// BackoffRatio is the ratio used to decrease the limit when a failure occurs.
	// this will be the way is used: new limit = current limit * backoffRatio.
	BackoffRatio float64
	// LimitIncrementInflightFactor will increment the limit only if inflight * LimitIncrementInflightFactor > limit
	LimitIncrementInflightFactor int
}

AIMDConfig is the configuration of the algorithm used for the AIMD adaptive limit.

type Limiter

type Limiter interface {
	// MeasureSample will measure the sample of an execution. This data will be used
	// by the algorithm to know what should be the limit.
	// It also returns the current limit after measuring the samples.
	MeasureSample(startTime time.Time, inflight int, result Result) int

	// Gets the current limit.
	GetLimit() int
}

Limiter knows what should be the concurrency limit based on the measured results. These are based on TCP congestion control algorithms.

func NewAIMD

func NewAIMD(cfg AIMDConfig) Limiter

NewAIMD returns a new aimd adaptive Limiter algorithm, based on the TCP congestion algorithm with the same name. It increases the limit at a constant rate and when congestion occurs it will decrease by a configured factor. More information about this algorithm in: https://en.wikipedia.org/wiki/Additive_increase/multiplicative_decrease

func NewStatic

func NewStatic(limit int) Limiter

NewStatic returns a new Static algorithm that is used ofr testing purposes, isn't adaptive it will have a static limit.

type Result

type Result string

Result is the result kind to be measured by the Limiter algorithm. These results are the ones the algorithm will be taken into account to calculate the dynamic limits.

const (
	// ResultSuccess will be treated like a success by the algorithm.
	ResultSuccess Result = "success"
	// ResultFailure will be treated like a Failure by the algorithm.
	ResultFailure Result = "failure"
	// ResultIgnore will be ignored by the algorithm.
	ResultIgnore Result = "ignore"
)

Jump to

Keyboard shortcuts

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