-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1176 from ably/fix/1156-incremental-backoff-jitter
Add incremental backoff and jitter
- Loading branch information
Showing
10 changed files
with
280 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
|
||
namespace IO.Ably.Shared.Utils | ||
{ | ||
// RTB1 | ||
internal class ReconnectionStrategy | ||
{ | ||
private static readonly Random Random = new Random(); | ||
|
||
public static double GetBackoffCoefficient(int count) | ||
{ | ||
return Math.Min((count + 2) / 3d, 2d); | ||
} | ||
|
||
public static double GetJitterCoefficient() | ||
{ | ||
return 1 - (Random.NextDouble() * 0.2); | ||
} | ||
|
||
// Generates retryTimeout value for given timeout and retryAttempt. | ||
// If x is the value generated then | ||
// Upper bound = min((retryAttempt + 2) / 3, 2) * initialTimeout | ||
// Lower bound = 0.8 * Upper bound | ||
// Lower bound < x < Upper bound | ||
public static double GetRetryTime(double initialTimeout, int retryAttempt) | ||
{ | ||
return initialTimeout * GetBackoffCoefficient(retryAttempt) * GetJitterCoefficient(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.