Skip to content

Commit 9c3a3c2

Browse files
committed
api: Improve and optimize Random Exponential Backoff algorithm.
Fixes #537.
1 parent 056963b commit 9c3a3c2

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

zulip/zulip/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ 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+
message = "Sleeping for %ss before retrying." % (delay,)
10099
try:
101100
logger.warning(message)
102101
except NameError:

0 commit comments

Comments
 (0)