Skip to content

Implement incremental backoff and jitter #370

@deanna-lad

Description

@deanna-lad

Please see the example implementation in js here ably/ably-js#997

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improved functionality.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions