backo icon indicating copy to clipboard operation
backo copied to clipboard

Jitter should be relative to the current delay

Open mokesmokes opened this issue 10 years ago • 2 comments
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
}

mokesmokes avatar Nov 22 '14 18:11 mokesmokes

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.

travisjeffery avatar Nov 22 '14 19:11 travisjeffery

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)

mokesmokes avatar Nov 22 '14 20:11 mokesmokes