Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
simple-backoff
Advanced tools
Calculates the delay values for various backoff mechanisms. Like backoff, except it doesn't wrap everything up in an arbitrary API. Like backo/backo2, except it provides three choices of algorithm.
var LinearBackoff = require('simple-backoff').LinearBackoff;
var backoff = new LinearBackoff({
min: 10,
step: 50
});
console.log(backoff.next());
console.log(backoff.next());
backoff.reset();
console.log(backoff.next());
Outputs:
10
60
10
Four constructors are exported: LinearBackoff
, ExponentialBackoff
, FibonacciBackoff
, and FixedBackoff
. They each have slightly different options, but the first three accept a basic set of core options, passed as an options bag:
new LinearBackoff({
min: 10,
max: 10000,
step: 50,
jitter: 0
});
new ExponentialBackoff({
min: 10,
max: 10000,
factor: 2,
jitter: 0
});
new FibonacciBackoff({
min: 10,
max: 10000,
jitter: 0
});
The values shown above are the defaults.
FixedBackoff
is a bit different, and accepts an array of integers >= 0. min
and max
are invalid since the sequence is explicit. Jitter is accepted, however.
new FixedBackoff({
sequence: [100, 300, 5000, ...],
jitter: 0
});
Returns the next value in the sequence, with jitter applied (if any). Will not exceed the value of max
, except by some amount of jitter.
backoff.next()
will always return an integer >= 0
.
Resets the sequence to its initial state.
Specifies the starting/minimum value of the sequence.
Specifies the maximum value of the sequence. Calls to next
will not increase the sequence above this value.
Used only for LinearBackoff
. This value is added to the previous value to arrive at the next value in the sequence.
Used only for ExponentialBackoff
. This value is multiplied by the previous value to arrive at the next value in the sequence.
Used only for FixedBackoff
. Must be an array of one or more integers >= 0. It need not be monotonically increasing. Specifies the values to produce in sequence.
A number between 0 and 1, inclusive. The jitter
value specifies a percentage of the difference between the current and next values, centered on the current value. Jitter is cumulative.
Example:
In a linear sequence, if the current value is 100
, the step is 50
, and the jitter is 0.5
, the result of backoff.next()
will be a random value between 87.5
and 112.5
:
100
and 150
is 50
50
multiplied by the jitter value is 25
25
centered around 100
is 87.5
-112.5
The range of values used for jitter varies slightly depending on the backoff strategy:
The point of the jitter
option is to vary values such as reconnect times from clients when a server restarts to avoid everything trying to reconnect at the same time.
FAQs
Simple backoff calculation with multiple strategies
The npm package simple-backoff receives a total of 606 weekly downloads. As such, simple-backoff popularity was classified as not popular.
We found that simple-backoff demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.