Add a random offset to the poll interval with each poll

Change-type: patch
Closes: #1242
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2020-05-15 10:32:17 +01:00
parent a03e89caf8
commit 58c6a69e5a
2 changed files with 8 additions and 3 deletions

View File

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

View File

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