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) {