-
Notifications
You must be signed in to change notification settings - Fork 243
DRIVERS-3535 - Client Backpressure with retryAfterMS #1953
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
9b52910
5af946f
90e37d9
d57a0a4
1dfcedb
07581aa
c662156
e4abae5
63426b9
6d6a071
2ad0956
132c52b
540e477
3618b6b
81e9c1b
45e90e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,12 +129,18 @@ rules: | |
| - To retry `runCommand`, both [retryWrites](../retryable-writes/retryable-writes.md#retrywrites) and | ||
| [retryReads](../retryable-reads/retryable-reads.md#retryreads) MUST be enabled. See | ||
| [Why must both `retryWrites` and `retryReads` be enabled to retry runCommand?](client-backpressure.md#why-must-both-retrywrites-and-retryreads-be-enabled-to-retry-runcommand) | ||
| 3. If the request is eligible for retry (as outlined in step 2 above), the client MUST apply exponential backoff | ||
| according to the following formula: `backoff = jitter * min(MAX_BACKOFF, BASE_BACKOFF * 2^(attempt - 1))` | ||
| - `jitter` is a random jitter value between 0 and 1. | ||
| - `BASE_BACKOFF` is constant 100ms. | ||
| - `MAX_BACKOFF` is 10000ms. | ||
| - This results in delays of 100ms and 200ms before accounting for jitter. | ||
| 3. If the request is eligible for retry (as outlined in step 2 above), the client MUST apply backoff according to the | ||
| following rules: | ||
| 1. If `retryAfterMS` is present on the error and has a positive value, apply backoff according to the following | ||
| formula: `backoff = retryAfterMS.value + (jitter * retryAfterMS.value)` | ||
| - `jitter` is a random jitter value between -0.5 and 0.5. | ||
|
tadjik1 marked this conversation as resolved.
Outdated
|
||
| - `retryAfterMS.value` is the value of the error's `retryAfterMS` field. | ||
| 2. Otherwise, apply exponential backoff according to the following formula: | ||
| `backoff = jitter * min(MAX_BACKOFF, BASE_BACKOFF * 2^(attempt - 1))` | ||
| - `jitter` is a random jitter value between 0 and 1. | ||
| - `BASE_BACKOFF` is constant 100ms. | ||
| - `MAX_BACKOFF` is 10000ms. | ||
| - This results in delays of 100ms and 200ms before accounting for jitter. | ||
| 4. If the request is eligible for retry (as outlined in step 2 above) and `enableOverloadRetargeting` is enabled, the | ||
| client MUST add the previously used server's address to the list of deprioritized server addresses for | ||
| [server selection](../server-selection/server-selection.md). Drivers MUST expose `enableOverloadRetargeting` as a | ||
|
|
@@ -213,9 +219,16 @@ def execute_command_retryable(command, ...): | |
| deprioritized_servers.append(server.address) | ||
|
|
||
| if is_overload: | ||
| jitter = random.random() # Random float between [0.0, 1.0). | ||
| backoff = jitter * min(MAX_BACKOFF, BASE_BACKOFF * 2 ** (attempt - 1)) | ||
|
|
||
| # If present on the error, retryAfterMS sets the backoff | ||
| retry_after_ms = exc.retry_after_ms | ||
| if retry_after_ms: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the retry_after should be set as BASE_BACKOFF, then set to the new value if retry_after_ms is given, then use a single line to set the backoff
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙏 even more concise, thanks! |
||
| retry_after = retry_after / 1000 # Convert from milliseconds to seconds | ||
| jitter = random.uniform(-0.5, 0.5) # Random float between [-0.5, 0.5]. | ||
| backoff = (jitter * retry_after) + retry_after | ||
| # Otherwise fall back to exponential | ||
| else: | ||
| jitter = random.random() # Random float between [0.0, 1.0). | ||
| backoff = jitter * min(MAX_BACKOFF, BASE_BACKOFF * 2 ** (attempt - 1)) | ||
| # If the delay exceeds the deadline, bail early. | ||
| if _csot.get_timeout(): | ||
| if time.monotonic() + backoff > _csot.get_deadline(): | ||
|
|
@@ -433,6 +446,8 @@ to understand and configure. | |
|
|
||
| ## Changelog | ||
|
|
||
| - 2026-06-16: Add support for retryAfterMS backoff calculation. | ||
|
|
||
| - 2026-04-14: Clarify correct retry behavior when a mix of overload and non-overload errors are encountered. | ||
|
|
||
| - 2026-03-30: Introduce phase 1 support without token buckets. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.