Skip to content

Conversation

ShaneHarvey
Copy link
Member

@ShaneHarvey ShaneHarvey commented Aug 21, 2025

PYTHON-5506 Prototype adaptive token bucket retry

Description:
Add adaptive token bucket based retry policy.
Successfully completed commands deposit 0.1 token.
Failed retry attempts consume 1 token.
A retry is only permitted if there is an available token.
For simplicity, this POC adds a retry bucket per MongoClient. In the future we will consider adding a retry bucket per server.

Patch with perf benchmarks: https://spruce.mongodb.com/version/68a7b69b74baee000728de31/tasks

@ShaneHarvey ShaneHarvey marked this pull request as ready for review August 21, 2025 20:10
@ShaneHarvey ShaneHarvey requested a review from a team as a code owner August 21, 2025 20:10

async def should_retry(self, attempt: int) -> bool:
"""Return if we have budget to retry and how long to backoff."""
# TODO: Check CSOT deadline here.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for a follow up PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented it now.

@ShaneHarvey ShaneHarvey requested a review from blink1073 August 22, 2025 16:37
Copy link
Member

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ShaneHarvey ShaneHarvey merged commit 875c564 into mongodb:backpressure Aug 22, 2025
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants