calculationstrategy

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2019 License: Apache-2.0 Imports: 0 Imported by: 0

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