Skip to content

Instantly share code, notes, and snippets.

@schneems
Last active May 15, 2018 09:38
Show Gist options
  • Save schneems/c07d93d5a4ade679bbc3 to your computer and use it in GitHub Desktop.
Save schneems/c07d93d5a4ade679bbc3 to your computer and use it in GitHub Desktop.
Puma Backlog Setting on Heroku

Why not set backlog on Heroku?

First read this: https://mikecoutermarsh.com/adjusting-pumas-backlog-for-heroku/

Now we're on the same page. Heroku will re-route bounced requests from your dynos but it assumes when this happens that your entire app is saturated. https://devcenter.heroku.com/articles/http-routing#dyno-connection-behavior. Each connection gets delayed by 5 seconds, so you're automatically being docked 5 seconds per request.

If you're setting your backlog to a low value (i.e. if you'll ever actually ever hit backlog) then you'll be in for pain. When you get a spike of requests from slashdot/reddit/whatever you're telling your dynos that you would rather they failed then returned slow responses. So this does mean that some requests will be served, but all the others will fail.

If your app ever hits your backlog (no matter what value it is) it is an indicator you don't have enough throughput and you need to scale out to more dynos. If you set this to an arbitrarilly low value, that point comes up earlier.

If you're getting to the point where you have 20-30 requests regularly queued up in one dyno, there's probably that many queued up in all your other dynos, so bouncing the request doesn't buy you extra speed, it just guarantees that the request will fail by putting it at the end of another dyno's queue that will probably bounce.

TLDR

It looks like an easy cheap performance win, but it's not. Setting backlog comes at the huge cost of trading speed for availability. If you offered to serve 50% of my requests faster and not respond to 50% of my other requests, i'm not going to be a happy customer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment