backoff icon indicating copy to clipboard operation
backoff copied to clipboard

backoff.expo base

Open gregroberts opened this issue 8 years ago • 4 comments

First off, crackin' little library. Really like the api.

However, in backoff.expo:

https://github.com/litl/backoff/blob/master/backoff/_wait_gen.py#L14

Having n=0 means the second attempt will always happen only 1 second after the first attempt, regardles of base, factor.

My assumption was that base would set the minimum backoff time.

Is this intended behaviour? To me it seems counter-intuitive to the meaning of the 'base' parameter!

This could be addressed in one of two simple ways.

Change https://github.com/litl/backoff/blob/master/backoff/_wait_gen.py#L14

to

n = 1

OR

change

https://github.com/litl/backoff/blob/master/backoff/_wait_gen.py#L16

to

a = base * factor ** n

Either of these changes would mean the minimum retry interval was equal to base, and not 1.

gregroberts avatar Aug 16 '17 13:08 gregroberts

Sorry for the slow response - I was away last week.

You may be right that it should be

a = base * factor ** n

but I need to refresh my thinking about base and factor - I believe those were included when adding support for the jitter algorithm from https://www.awsarchitectureblog.com/2015/03/backoff.html

I will get back to you when I have a few minutes to investigate.

bgreen-litl avatar Aug 21 '17 14:08 bgreen-litl

Happy to submit a ludicrously small PR if you like ; )

gregroberts avatar Aug 30 '17 08:08 gregroberts

I think the equation itself makes sense as it is.

In

a = factor * (base ** n)

base is the component that's exponentiated, and the result is scaled by factor. There might be some confusion due to the lack of parentheses in the source.

If I'm not mistaken, it looks like the only change required here is to set n = 1, although you could simply adjust factor to get whatever starting value you'd like.

tasercake avatar Aug 31 '18 02:08 tasercake

I think the equation itself makes sense as it is.

In

a = factor * (base ** n)

base is the component that's exponentiated, and the result is scaled by factor. There might be some confusion due to the lack of parentheses in the source.

If I'm not mistaken, it looks like the only change required here is to set n = 1, although you could simply adjust factor to get whatever starting value you'd like.

I prefer this approach.

flaurencin avatar Apr 21 '20 14:04 flaurencin