blob: 24d943f5185ba0844d1000820d70ebaa8b29cbc6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#include "utils.h"
#include <util/random/random.h>
TDuration NRetryPrivate::AddRandomDelta(TDuration maxDelta) {
if (maxDelta == TDuration::Zero()) {
return TDuration::Zero();
}
const TDuration delta = TDuration::MicroSeconds(RandomNumber(2 * maxDelta.MicroSeconds()));
return delta - maxDelta;
}
TDuration NRetryPrivate::AddIncrement(ui32 attempt, TDuration increment) {
return TDuration::MicroSeconds(attempt * increment.MicroSeconds());
}
TDuration NRetryPrivate::AddExponentialMultiplier(ui32 attempt, TDuration exponentialMultiplier) {
return TDuration::MicroSeconds((1ull << Min(63u, attempt)) * exponentialMultiplier.MicroSeconds());
}
|