Skip to content

Commit 33768c8

Browse files
committed
Add automatic computation for exponential backoff in retrier
Signed-off-by: lsenta <laurent.senta@gmail.com>
1 parent 7180fd8 commit 33768c8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

hubstorage/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,20 @@ def _create_retrier(self, max_retries, max_retry_time):
118118
if max_retries is not None and max_retry_time is None:
119119
stop_max_delay = None
120120
stop_max_attempt_number = max_retries + 1
121+
wait_exponential_multiplier = self.RETRY_DEFAULT_EXPONENTIAL_BACKOFF_MS
121122
else:
122123
stop_max_delay = (max_retry_time or self.RETRY_DEFAUT_MAX_RETRY_TIME_S) * 1000.0
123124
stop_max_attempt_number = (max_retries or self.RETRY_DEFAULT_MAX_RETRIES) + 1
124125

126+
# Compute the backoff to allow for max_retries queries during the allowed delay
127+
# Solves the following formula (assumes requests are immediate):
128+
# max_retry_time = sum(exp_multiplier * 2 ** i) for i from 1 to max_retries + 1
129+
wait_exponential_multiplier = stop_max_delay / ((2 ** (stop_max_attempt_number + 1)) - 2)
130+
125131
return Retrying(stop_max_attempt_number=stop_max_attempt_number,
126132
stop_max_delay=stop_max_delay,
127133
retry_on_exception=_hc_retry_on_exception,
128-
wait_exponential_multiplier=self.RETRY_DEFAULT_EXPONENTIAL_BACKOFF_MS,
134+
wait_exponential_multiplier=wait_exponential_multiplier,
129135
wait_jitter_max=self.RETRY_DEFAULT_JITTER_MS)
130136

131137
def _create_session(self):

0 commit comments

Comments
 (0)