Jitter Worth The Name

A node holding 40,000 WebSocket clients is restarted. Every client runs this reconnect loop, and the surviving nodes still fall over.

let attempt = 0;

function connect() {
  const ws = new WebSocket(URL);
  ws.onopen = () => { attempt = 0; };
  ws.onclose = () => {
    const delay = Math.min(30000, 250 * 2 ** attempt);
    attempt += 1;
    setTimeout(connect, delay + Math.random() * 100);
  };
}

Which change actually spreads the redial load?

A

Multiply the existing random term by 10, giving 0 to 1,000 ms of jitter

B

Draw the whole delay at random: const delay = Math.random() * Math.min(30000, 250 * 2 ** attempt); and pass that to setTimeout with no additive term

C

Raise the cap from 30,000 ms to 120,000 ms

D

Reset attempt only after the socket has stayed open for 30 seconds, not in onopen