| 15 | namespace { |
| 16 | |
| 17 | TDuration SuggestSleepDelay(int iteration) |
| 18 | { |
| 19 | static std::atomic<ui64> Rand; |
| 20 | auto rand = Rand.load(std::memory_order::relaxed); |
| 21 | rand = 0x5deece66dLL * rand + 0xb; // numbers from nrand48() |
| 22 | Rand.store(rand, std::memory_order::relaxed); |
| 23 | |
| 24 | constexpr ui64 MinDelayUs = 128; |
| 25 | |
| 26 | // Double delay every 8 iterations, up to 16x (2ms). |
| 27 | if (iteration > 32) { |
| 28 | iteration = 32; |
| 29 | } |
| 30 | ui64 delayUs = MinDelayUs << (iteration / 8); |
| 31 | |
| 32 | // Randomize in delay..2*delay range, for resulting 128us..4ms range. |
| 33 | delayUs = delayUs | ((delayUs - 1) & rand); |
| 34 | return TDuration::MicroSeconds(delayUs); |
| 35 | } |
| 36 | |
| 37 | } // namespace |
| 38 |
no test coverage detected