node-backoff-strategies
A genericised set of backoff-suitable algorithms.
Installation
npm install backoff-strategies
General Options
minValue
(default: 0) - the smallest value that may be returnedmaxValue
(default: Infinity) - the largest value that may be returnedmultiplier
(default: 1) - the scaling factor of the return valuerandomisationFactor
(default: 0) - increase the returned value by a random amountzeroMeansZero
(default: true) - overrides all other settings to always return 0 when i=0`i
(default: 0) - the initial i value (when usingstrategy.next()
for generation)
General Methods
get(i)
- returns the computed value for this step according to the strategynext()
- returnsget(i)
for the current i value, then increments ireset()
- resets i to zero
Usage
Linear Strategy
A monotonically increasing strategy, e.g. 0,1,2,3,4,5
const Strategies = ; var linearBackoff = ; console; // 0console; // 1console; // 2 console; // 6
Defined Strategy
A predefined strategy for granular control
const Strategies = ; var definedBackoff = values: 1 5 6 3; console; // 1console; // 5console; // 6console; // 3console; // 3 console; // 3
Fibonnaci Strategy
A strategy increasing according to a Fabonacci sequence (1,1,2,3,5,8,13)
const Strategies = ; var fibonacciBackoff = zeroMeansZero: false; console; // 1console; // 1console; // 2console; // 3 console; // 13
Exponential Strategy
An exponentially increasing strategy: Math.pow(this.factor, i - 1)
This accepts an additional factor
option.
const Strategies = ; var expBackoff = randomisationFactor: 05 multiplier: 10 maxValue: 300; console; // 0console; // 13 - between 10 and 15console; // 26 - between 20 and 30console; // 57 - between 40 and 60 console; // 167 - between 160 and 240
Polynomial Strategy
A polynomially increasing strategy: Math.pow(i, this.factor)
This accepts an additional factor
option.
const Strategies = ; var polyBackoff = factor: 3; console; // 0console; // 1console; // 2 * 2 * 2 =8console; // 3 * 3 * 3 = 27console; // 5 * 5 * 5 = 125