Skip to content

Commit 4f2594b

Browse files
committed
1ms start, 1.25 rate, 500ms max
1 parent 9fa5dbe commit 4f2594b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pymongo/asynchronous/client_session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ def _max_time_expired_error(exc: PyMongoError) -> bool:
473473
# This limit is non-configurable and was chosen to be twice the 60 second
474474
# default value of MongoDB's `transactionLifetimeLimitSeconds` parameter.
475475
_WITH_TRANSACTION_RETRY_TIME_LIMIT = 120
476-
_BACKOFF_MAX = 1
477-
_BACKOFF_INITIAL = 0.050 # 50ms initial backoff
476+
_BACKOFF_MAX = 0.500 # 500ms max backoff
477+
_BACKOFF_INITIAL = 0.001 # 1ms initial backoff
478478

479479

480480
def _within_time_limit(start_time: float) -> bool:
@@ -708,7 +708,7 @@ async def callback(session, custom_arg, custom_kwarg=None):
708708
while True:
709709
if retry: # Implement exponential backoff on retry.
710710
jitter = random.random() # noqa: S311
711-
backoff = jitter * min(_BACKOFF_INITIAL * (2**retry), _BACKOFF_MAX)
711+
backoff = jitter * min(_BACKOFF_INITIAL * (1.25**retry), _BACKOFF_MAX)
712712
await asyncio.sleep(backoff)
713713
retry += 1
714714
await self.start_transaction(

pymongo/synchronous/client_session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ def _max_time_expired_error(exc: PyMongoError) -> bool:
471471
# This limit is non-configurable and was chosen to be twice the 60 second
472472
# default value of MongoDB's `transactionLifetimeLimitSeconds` parameter.
473473
_WITH_TRANSACTION_RETRY_TIME_LIMIT = 120
474-
_BACKOFF_MAX = 1
475-
_BACKOFF_INITIAL = 0.050 # 50ms initial backoff
474+
_BACKOFF_MAX = 0.500 # 500ms max backoff
475+
_BACKOFF_INITIAL = 0.001 # 1ms initial backoff
476476

477477

478478
def _within_time_limit(start_time: float) -> bool:
@@ -706,7 +706,7 @@ def callback(session, custom_arg, custom_kwarg=None):
706706
while True:
707707
if retry: # Implement exponential backoff on retry.
708708
jitter = random.random() # noqa: S311
709-
backoff = jitter * min(_BACKOFF_INITIAL * (2**retry), _BACKOFF_MAX)
709+
backoff = jitter * min(_BACKOFF_INITIAL * (1.25**retry), _BACKOFF_MAX)
710710
time.sleep(backoff)
711711
retry += 1
712712
self.start_transaction(read_concern, write_concern, read_preference, max_commit_time_ms)

0 commit comments

Comments
 (0)