Skip to content

Commit 94e5458

Browse files
committed
api: Improve and optimize Random Exponential Backoff algorithm.
Fixes #537.
1 parent 35c3dca commit 94e5458

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

zulip/zulip/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ def fail(self):
9494
super(RandomExponentialBackoff, self).fail()
9595
# Exponential growth with ratio sqrt(2); compute random delay
9696
# between x and 2x where x is growing exponentially
97-
delay_scale = int(2 ** (self.number_of_retries / 2.0 - 1)) + 1
98-
delay = min(delay_scale + random.randint(1, delay_scale), delay_cap)
99-
message = "Sleeping for %ss [max %s] before retrying." % (delay, delay_scale * 2)
97+
delay = random.random() * min(self.delay_cap, 2 ** self.number_of_retries)
98+
99+
message = "Sleeping for %ss before retrying." % (delay,)
100100
try:
101101
logger.warning(message)
102102
except NameError:

0 commit comments

Comments
 (0)