/usr/lib/python3/dist-packages/provisioningserver/utils/backoff.py is in python3-maas-provisioningserver 2.0.0~beta3+bzr4941-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | # Copyright 2015 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Utilities related to back-off.
Many or most of the following are inspired by `Exponential Backoff And
Jitter`__ on the AWS Architecture Blog.
.. __: http://www.awsarchitectureblog.com/2015/03/backoff.html.
"""
__all__ = [
"exponential_growth",
"full_jitter",
]
from itertools import count
from random import random
def exponential_growth(base, rate):
"""Generate successive values for an exponential growth curve.
Intervals are discrete and fixed, starting at 1 (not 0) and increasing by
1 on each iteration.
:param base: The starting value, i.e. where the interval is 0.0.
:type base: float
:param rate: The rate of growth. For a 5% growth rate, pass 1.05.
:type rate: float.
"""
for attempt in count(1):
yield base * (rate ** attempt)
def full_jitter(values):
"""Apply "full jitter" to `values`.
Each value in `values` will be multiplied by a random number in the
interval [0.0, 1.0).
:param values: An iterable of numbers.
"""
for value in values:
yield random() * value
|