def _exponential_backoff()

in google/cloud/sql/connector/refresh_utils.py [0:0]


def _exponential_backoff(attempt: int) -> float:
    """Calculates a duration to backoff in milliseconds based on the attempt i.

    The formula is:

    base * multi^(attempt + 1 + random)

    With base = 200ms and multi = 1.618, and random = [0.0, 1.0),
    the backoff values would fall between the following low and high ends:

    Attempt  Low (ms)  High (ms)

    0         324	     524
    1         524	     847
    2         847	    1371
    3        1371	    2218
    4        2218	    3588

    The theoretical worst case scenario would have a client wait 8.5s in total
    for an API request to complete (with the first four attempts failing, and
    the fifth succeeding).
    """
    base = 200
    multi = 1.618
    exp = attempt + 1 + random.random()
    return base * pow(multi, exp)