utils.cpp 680 B

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