Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exponential Backoff ranges are incorrect #11107

Closed
dbolduc opened this issue Mar 25, 2023 · 2 comments · Fixed by #11529
Closed

Exponential Backoff ranges are incorrect #11107

dbolduc opened this issue Mar 25, 2023 · 2 comments · Fixed by #11529
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@dbolduc
Copy link
Member

dbolduc commented Mar 25, 2023

We have a scaling factor, but we multiply the initial range by 2, instead.

current_delay_range_(2 * initial_delay_),

Moreover, we do not check if we have hit the maximum until after generating the first backoff

std::uniform_int_distribution<microseconds::rep> rng_distribution(
current_delay_range_.count() / 2, current_delay_range_.count());
// Randomized sleep period because it is possible that after some time all
// client have same sleep period if we use only exponential backoff policy.
auto delay = microseconds(rng_distribution(*generator_));
current_delay_range_ = microseconds(static_cast<microseconds::rep>(
static_cast<double>(current_delay_range_.count()) * scaling_));
if (current_delay_range_ >= maximum_delay_) {
current_delay_range_ = maximum_delay_;
}
return duration_cast<milliseconds>(delay);

This leads to kooky behavior. Let's say I have an ExponentialBackoffPolicy(10s, 11s, 1.1).

The first range will be: [10s, 20s], which does not respect the maximum.

All subsequent ranges will be: [5.5s, 11s], which does not respect the minimum.

Lol.

@dbolduc dbolduc added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Mar 25, 2023
@alevenberg alevenberg self-assigned this May 8, 2023
@alevenberg
Copy link
Member

To further recap what Darren described:
Current behavior
ExponentialBackoffPolicy(10s, 11s, 1.1)
First call: [10s, 20s]
Second call: [5.5s, 11s]
Third call: [5.5s, 11s]

Intended behavior
ExponentialBackoffPolicy(10s, 11s, 1.1)
First call: [10s, 11s]
Second call: [10s, 11s]
Third call: [10s, 11s]

A more general case:
Current behavior
ExponentialBackoffPolicy(1s, 11s, 2)
First call: [1s, 2s]
Second call: [2s, 4s]
Third call: [8s, 16s]
Fourth call: [5.5s, 11s]
Fifth call: [5.5s, 11s]

Intended behavior
ExponentialBackoffPolicy(1s, 11s, 2)
First call: [1s, 2s]
Second call: [1s, 4s]
Third call: [1s, 8s]
Fourth call: [1s, 11s]
Fifth call: [1s, 11s]

#8755 describes the initial implementation decision conversation. I will move forward with implementing min-jitter.

@dbolduc
Copy link
Member Author

dbolduc commented May 8, 2023

I will move forward with implementing min-jitter.

errrr..... I do not recommend this. I think you should fix one bug at a time, starting with this bug. Yes #8755 is juicier, but you will benefit from starting on a smaller problem.

I would say the intended behavior we want for the "more general case" (as far as this bug is concerned) is the current behavior:

ExponentialBackoffPolicy(1s, 11s, 2) gives...

call # backoff range
1 [1s, 2s]
2 [2s, 4s]
3 [4s, 8s]
4 [5.5s, 11s]
N [5.5s, 11s]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants