From 58c6a69e5a6045e898ce5748089f4dcad7d12bc3 Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Fri, 15 May 2020 10:32:17 +0100 Subject: [PATCH] Add a random offset to the poll interval with each poll Change-type: patch Closes: #1242 Signed-off-by: Cameron Diver --- src/api-binder.ts | 7 ++++--- src/lib/constants.ts | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/api-binder.ts b/src/api-binder.ts index 3d0ecfe6..0720e4b8 100644 --- a/src/api-binder.ts +++ b/src/api-binder.ts @@ -608,9 +608,10 @@ export class APIBinder { instantUpdates, } = await this.config.getMany(['appUpdatePollInterval', 'instantUpdates']); - // We add jitter to the poll interval so that it's between 0.5 and 1.5 times - // the configured interval - let pollInterval = (0.5 + Math.random()) * appUpdatePollInterval; + // We add a random jitter up to `maxApiJitterDelay` to + // space out poll requests + let pollInterval = + Math.random() * constants.maxApiJitterDelay + appUpdatePollInterval; if (instantUpdates || !isInitialCall) { try { diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 406f8f2d..9f5ac28e 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -58,6 +58,10 @@ const constants = { supervisorNetworkGateway: '10.114.104.1', // How often can we report our state to the server in ms maxReportFrequency: 10 * 1000, + // How much of a jitter we can add to our api polling + // (this number is used as an upper bound when generating + // a random jitter) + maxApiJitterDelay: 60 * 1000, }; if (process.env.DOCKER_HOST == null) {