This repository has been archived by the owner on Oct 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from hjacobs/kubeconfig
Kubeconfig & Backoff
- Loading branch information
Showing
10 changed files
with
377 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import random | ||
|
||
|
||
def expo(n: int, base=2, factor=1, max_value=None): | ||
"""Exponential decay. | ||
Adapted from https://github.com/litl/backoff/blob/master/backoff.py (MIT License) | ||
Args: | ||
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: | ||
return a | ||
else: | ||
return max_value | ||
|
||
|
||
def random_jitter(value, jitter=1): | ||
"""Jitter the value a random number of milliseconds. | ||
Copied from https://github.com/litl/backoff/blob/master/backoff.py (MIT License) | ||
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. | ||
""" | ||
return value + random.uniform(0, jitter) | ||
|
||
|
||
def full_jitter(value): | ||
"""Jitter the value across the full range (0 to value). | ||
Copied from https://github.com/litl/backoff/blob/master/backoff.py (MIT License) | ||
This corresponds to the "Full Jitter" algorithm specified in the | ||
AWS blog's post on the performance of various jitter algorithms. | ||
(http://www.awsarchitectureblog.com/2015/03/backoff.html) | ||
Args: | ||
value: The unadulterated backoff value. | ||
""" | ||
return random.uniform(0, value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.