calculationstrategy

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2019 License: Apache-2.0 Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CalculateFunc

type CalculateFunc func(targetQPS, curQPS, prevProbability float64) (newProbability float64)

CalculateFunc wraps a function of appropriate signature and makes a ProbabilityCalculator from it.

func (CalculateFunc) Calculate

func (c CalculateFunc) Calculate(targetQPS, curQPS, prevProbability float64) float64

Calculate implements Calculator interface.

type PercentageIncreaseCappedCalculator

type PercentageIncreaseCappedCalculator struct {
	// contains filtered or unexported fields
}

PercentageIncreaseCappedCalculator is a probability calculator that caps the probability increase to a certain percentage of the previous probability.

Given prevProb = 0.1, newProb = 0.5, and cap = 0.5: (0.5 - 0.1)/0.1 = 400% increase. Given that our cap is 50%, the probability can only increase to 0.15.

Given prevProb = 0.4, newProb = 0.5, and cap = 0.5: (0.5 - 0.4)/0.4 = 25% increase. Given that this is below our cap of 50%, the probability can increase to 0.5.

func NewPercentageIncreaseCappedCalculator

func NewPercentageIncreaseCappedCalculator(percentageIncreaseCap float64) PercentageIncreaseCappedCalculator

NewPercentageIncreaseCappedCalculator returns a new percentage increase capped calculator.

func (PercentageIncreaseCappedCalculator) Calculate

func (c PercentageIncreaseCappedCalculator) Calculate(targetQPS, curQPS, prevProbability float64) float64

Calculate calculates the new probability.

type ProbabilityCalculator

type ProbabilityCalculator interface {
	Calculate(targetQPS, curQPS, prevProbability float64) (newProbability float64)
}

ProbabilityCalculator calculates the new probability given the current and target QPS

Jump to

Keyboard shortcuts

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