Skip to content

Instantly share code, notes, and snippets.

@rinov
Last active May 11, 2022 09:29
Show Gist options
  • Save rinov/89f99f0d41bc25d1e4e0d78e446d5bd1 to your computer and use it in GitHub Desktop.
Save rinov/89f99f0d41bc25d1e4e0d78e446d5bd1 to your computer and use it in GitHub Desktop.
import random
def exponential_backoff_and_jitter(n):
"""
Exponential Backoff And Jitter Algorithm (Full Jitter)
:param n: Retry number of times
:return: Retry interval (ms)
"""
backoff = pow(2, n) * 1000
return backoff + random.randint(0, backoff)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment