Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement incremental backoff and jitter #997

Closed
owenpearson opened this issue Jun 9, 2022 · 1 comment · Fixed by #1008
Closed

Implement incremental backoff and jitter #997

owenpearson opened this issue Jun 9, 2022 · 1 comment · Fixed by #1008
Assignees
Labels
enhancement New feature or improved functionality.

Comments

@owenpearson
Copy link
Member

owenpearson commented Jun 9, 2022

Incremental backoff and jitter was added to the features spec in ably/docs#1445

To implement this we need to change the retry behaviour for:

  • When the client connection is in the DISCONNECTED state
  • When a RealtimeChannel is in the SUSPENDED state

The new retry behaviour is specified in RTB1 of the features spec.

RTB1a

The backoff coefficient described in RTB1a can be calculated in javascript like so:

function getBackoffCoefficient(n) {
  return Math.min((n + 2) / 3, 2);
}

RTB1b

The jitter coefficient described in RTB1b can be calculated in javascript like so:

function getJitterCoefficient() {
  return 1 - Math.random() * 0.2;
}

RTB1

The overall retry time calculation should look like:

function getRetryTime(initValue, n) {
  return initValue * getBackoffCoefficient(n) * getJitterCoefficient();
}

The following code can be used to test it:

[1, 2, 3, 4, 5].forEach((n) => {
  console.log(getRetryTime(initValue, n));
});

Which, with an initValue of 15 (seconds) should print something like:

13.917470451245713
18.415226855678757
20.444851032898747
26.650729887092275
27.803382948778786

┆Issue is synchronized with this Jira Story by Unito

@sacOO7
Copy link
Collaborator

sacOO7 commented Jun 14, 2023

Expression to calculate upper and lower bounds for generated values using getRetryTime

upper = min((retryCount + 2) / 3, 2) *initialTimeout
lower = 0.8 * upper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improved functionality.
Development

Successfully merging a pull request may close this issue.

3 participants