Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
JitterBackoff.cs
1using System;
2
4{
5 public static class JitterBackoff
6 {
7 private static readonly Random Rng = new Random();
8
12 public static TimeSpan DecorrelatedJitter(TimeSpan baseDelay, int attempt, TimeSpan? maxDelay = null)
13 {
14 if (attempt < 1) attempt = 1;
15 double capMs = (maxDelay ?? TimeSpan.FromSeconds(30)).TotalMilliseconds;
16 double sleepMs = Math.Min(capMs, baseDelay.TotalMilliseconds * Math.Pow(2, attempt));
17 double jitter = Rng.NextDouble() * sleepMs;
18 return TimeSpan.FromMilliseconds(jitter);
19 }
20 }
21}
22
static TimeSpan DecorrelatedJitter(TimeSpan baseDelay, int attempt, TimeSpan? maxDelay=null)
Decorrelated jitter backoff ("full jitter") based on attempt number.