Skip to content

Commit 0e28b77

Browse files
committed
1ms start, 1.25 rate, 500ms max
1 parent a415468 commit 0e28b77

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
@@ -472,8 +472,8 @@ def _max_time_expired_error(exc: PyMongoError) -> bool:
472472
# This limit is non-configurable and was chosen to be twice the 60 second
473473
# default value of MongoDB's `transactionLifetimeLimitSeconds` parameter.
474474
_WITH_TRANSACTION_RETRY_TIME_LIMIT = 120
475-
_BACKOFF_MAX = 1
476-
_BACKOFF_INITIAL = 0.050 # 50ms initial backoff
475+
_BACKOFF_MAX = 0.500 # 500ms max backoff
476+
_BACKOFF_INITIAL = 0.001 # 1ms initial backoff
477477

478478

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

pymongo/synchronous/client_session.py

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

476476

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

0 commit comments

Comments
 (0)