ably-ruby icon indicating copy to clipboard operation
ably-ruby copied to clipboard

Implement incremental backoff and jitter

Open deanna-lad opened this issue 2 years ago • 3 comments

Please see the example implementation in js here https://github.com/ably/ably-js/issues/997

Incremental backoff and jitter was added to the features spec in https://github.com/ably/docs/pull/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

deanna-lad avatar Jun 09 '22 13:06 deanna-lad

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

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

if x is a generated retryTimeout from getRetryTime, then

lower < x < upper

sacOO7 avatar Jun 14 '23 12:06 sacOO7

Reference test file -> https://github.com/ably/ably-dotnet/blob/ab1142594d3a689069f15ef137bfa3ba06891da3/src/IO.Ably.Tests.Shared/Utils/ReconnectionStrategyTest.cs

sacOO7 avatar Jun 14 '23 12:06 sacOO7

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/ECO-4061

sync-by-unito[bot] avatar Feb 17 '24 18:02 sync-by-unito[bot]