Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry backoff docs? #2168

Closed
MarkMurphy opened this issue Jan 29, 2015 · 4 comments
Closed

Retry backoff docs? #2168

MarkMurphy opened this issue Jan 29, 2015 · 4 comments

Comments

@MarkMurphy
Copy link

According to the wiki here: https://github.com/mperham/sidekiq/wiki/Error-Handling

The default retry backoff algorithm is:

(retry_count ** 4) + 15 + (rand(30) * (retry_count + 1))

The wiki claims that the default 25 count retry using this algorithm spans ~21 days however I only get ~4 days when I put that to the test:

> (0..25).each do |retry_count| 
  puts (retry_count ** 4) + 15 + (rand(30) * (retry_count + 1))
end

35
22
76
144
371
796
1402
2624
4264
6786
10257
14704
20816
28660
38836
50848
66010
83950
105523
130756
160099
194826
234685
280456
332016
391342

Am I miss-understanding something?

@aprescott
Copy link
Contributor

The nth retry happens after the previous n-1 retries, so you have to consider the cumulative time spent getting to the nth retry. Barring off-by-one errors in my code, I think this is the more accurate time:

def retry_for(retry_count)
  (retry_count ** 4) + 15 + (rand(30) * (retry_count + 1))
end

(1..25).each do |n|
  cumulative_days = (1..n).map { |x| retry_for(x) }.inject(:+).to_f / (60 * 60 * 24)
  puts "#{cumulative_days} days for retry attempt #{n}"
end

# 0.000787037037037037 days for retry attempt 1
# 0.0013078703703703703 days for retry attempt 2
# 0.003993055555555555 days for retry attempt 3
# 0.006400462962962963 days for retry attempt 4
# 0.015925925925925927 days for retry attempt 5
# 0.0340162037037037 days for retry attempt 6
# 0.06439814814814815 days for retry attempt 7
# 0.11091435185185185 days for retry attempt 8
# 0.18971064814814814 days for retry attempt 9
# 0.30571759259259257 days for retry attempt 10
# 0.47291666666666665 days for retry attempt 11
# 0.7178472222222222 days for retry attempt 12
# 1.0547916666666666 days for retry attempt 13
# 1.4991087962962963 days for retry attempt 14
# 2.0853819444444444 days for retry attempt 15
# 2.8479282407407407 days for retry attempt 16
# 3.8154050925925924 days for retry attempt 17
# 5.029976851851852 days for retry attempt 18
# 6.559722222222222 days for retry attempt 19
# 8.407662037037037 days for retry attempt 20
# 10.647604166666667 days for retry attempt 21
# 13.372638888888888 days for retry attempt 22
# 16.627037037037038 days for retry attempt 23
# 20.459085648148147 days for retry attempt 24
# 24.980717592592594 days for retry attempt 25

@mperham
Copy link
Collaborator

mperham commented Jan 29, 2015

Yes, you need to add the retry times together! Looks like it's closer to 25 days:

> i = 0 ; (0..25).each { |retry_count| i += (retry_count ** 4) + 15 + (rand(30) * (retry_count + 1)) }; i
=> 2159131
> i / 86400.0
=> 24.98994212962963

With 0..24, it's 20.5 days so someone probably has an off-by-one.

@aprescott
Copy link
Contributor

@mperham snap :)

@mperham mperham closed this as completed Jan 29, 2015
@MarkMurphy
Copy link
Author

Ah, makes sense! Thanks guys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants