backo
backo copied to clipboard
Jitter should be relative to the current delay
trafficstars
E.g. in https://github.com/segmentio/backo/blob/master/index.js#L38 perhaps try something like:
if (this.jitter) {
var rand = Math.random();
var deviation = rand * this.jitter * ms; // 0 <= jitter <= 1
ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation; // so jitter is uniformly distributed on both sides
}
so you want to randomly subtract sometimes rather than add?
with the old api jitter will almost certainly not between 0 and 1. we usually use something like 200.
The intent is a distribution based around the mean delay value, as a percentage of the delay value. 200ms, for example, may in some cases be long, and in others short. Thus it should grow as the delay grows. See the PR I just submitted (not yet tested.... will be later today or tomorrow... but for the discussion pushed it)