@@ -7,11 +7,14 @@ def expo(n: int, base=2, factor=1, max_value=None):
|
||||
Adapted from https://github.com/litl/backoff/blob/master/backoff.py (MIT License)
|
||||
|
||||
Args:
|
||||
----
|
||||
n: The exponent.
|
||||
base: The mathematical base of the exponentiation operation
|
||||
factor: Factor to multiply the exponentation by.
|
||||
max_value: The maximum value to yield. Once the value in the
|
||||
true exponential sequence exceeds this, the value
|
||||
of max_value will forever after be yielded.
|
||||
|
||||
"""
|
||||
a = factor * base ** n
|
||||
if max_value is None or a < max_value:
|
||||
@@ -27,8 +30,12 @@ def random_jitter(value, jitter=1):
|
||||
|
||||
This adds up to 1 second of additional time to the original value.
|
||||
Prior to backoff version 1.2 this was the default jitter behavior.
|
||||
|
||||
Args:
|
||||
----
|
||||
value: The unadulterated backoff value.
|
||||
jitter: Jitter amount.
|
||||
|
||||
"""
|
||||
return value + random.uniform(0, jitter)
|
||||
|
||||
@@ -43,6 +50,8 @@ def full_jitter(value):
|
||||
(http://www.awsarchitectureblog.com/2015/03/backoff.html)
|
||||
|
||||
Args:
|
||||
----
|
||||
value: The unadulterated backoff value.
|
||||
|
||||
"""
|
||||
return random.uniform(0, value)
|
||||
|
||||
Reference in New Issue
Block a user