Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateL ¶
Get the appropriate number of levels to achieve the target collision probability:
params: ------- B - Buckets per level. M - Expected "bad" client flows that'll need throttling. p - Probability of an innocent flow colliding with a bad one. Likely a small value.
The formula we are solving with: p = (1 - (1 - (1/B))^M)^L Comes from the following paper: https://rtcl.eecs.umich.edu/rtclweb/assets/publications/2001/feng2001fair.pdf
CalculateL computes the number of levels required to achieve the target collision probability. Most users should call GenerateTunedStructureConfig instead of invoking this directly.
Types ¶
type FairnessTrackerConfig ¶
type FairnessTrackerConfig struct {
// Size of the row at each level
M uint32
// Number of levels in the structure
L uint32
// The delta P to add to a bucket's probability when there's an error
Pi float64
// The delta P to subtract from a bucket's probability when there's a success
Pd float64
// The exponential decay rate for the probabilities
Lambda float64
// The frequency of rotation
RotationFrequency time.Duration
// Include result stats. Useful for debugging but may slightly affect performance.
IncludeStats bool
// The function to choose the final probability from all the bucket probabilities
FinalProbabilityFunction FinalProbabilityFunction
}
FairnessTrackerConfig defines the parameters for the underlying data structure used by the fairness tracker. Most users will rely on GenerateTunedStructureConfig to populate this struct.
func DefaultFairnessTrackerConfig ¶
func DefaultFairnessTrackerConfig() *FairnessTrackerConfig
DefaultFairnessTrackerConfig returns a configuration that should work well for most applications without any additional tuning.
func GenerateTunedStructureConfig ¶
func GenerateTunedStructureConfig(expectedClientFlows, bucketsPerLevel, tolerableBadRequestsPerBadFlow uint32) *FairnessTrackerConfig
Generates a "good enough" config to use for a structure underneath the throttler which requires minimal tuning and should be able to get decent results in most cases. If more tuning is desired, the clients can directly provide their own config object when initializing FairWorkloadTracker.
params: ------- expectedClientFlows - Number of concurrent clients you expect to your app bucketsPerLevel - Number of buckets per level in the core structure tolerableBadRequestsPerBadFlow - Number of requests we can tolerate before we fully shut down a flow GenerateTunedStructureConfig creates a configuration tuned for the expected scale of your application.
Parameters:
- expectedClientFlows: number of concurrent clients you expect.
- bucketsPerLevel: number of buckets per level in the data structure.
- tolerableBadRequestsPerBadFlow: number of failed requests tolerated before a flow is fully blocked.
type FinalProbabilityFunction ¶
FinalProbabilityFunction chooses a final probability from a slice of bucket probabilities.
var ( // MinFinalProbabilityFunction returns the smallest probability in the // slice. It is the default implementation used by the tracker. MinFinalProbabilityFunction FinalProbabilityFunction = func(buckets []float64) float64 { if len(buckets) == 0 { log.Fatalf("Cannot compute final probability with empty buckets slice") } var min float64 = 1. for _, b := range buckets { min = math.Min(min, b) } return min } // MeanFinalProbabilityFunction returns the mean of all bucket // probabilities and can be used in scenarios where the minimum value is // too strict. MeanFinalProbabilityFunction FinalProbabilityFunction = func(buckets []float64) float64 { if len(buckets) == 0 { log.Fatalf("Cannot compute final probability with empty buckets slice") } var total float64 for _, b := range buckets { total += b } return total / float64(len(buckets)) } )