Commit ae7b85a7 authored by Nick Stenning's avatar Nick Stenning

Tune the websocket autoreconnect to minimise thundering herd effect

The client websocket code will automatically attempt to reconnect on
error or disconnection. This commit:

- Randomises the delay before reconnection
- Wait two seconds before attempting to reconnect (meaning the real
  delay will be between 2 and 4 seconds) -- this is an attempt to spread
  out reconnections over a longer period.
- Makes it stop retrying after 10 attempts (i.e. roughly 30 minutes)
parent d6aeb4b9
......@@ -34,7 +34,14 @@ function Socket(url) {
function reconnect() {
var didConnect = false;
var connectOperation = retry.operation();
var connectOperation = retry.operation({
// Wait 2s before attempting to reconnect
minTimeout: 2000,
// Don't retry forever
retries: 10,
// Randomize retry times to minimise the thundering herd effect
randomize: true
});
connectOperation.attempt(function (currentAttempt) {
socket = new WebSocket(url);
socket.onopen = function (event) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment