Should I use preload_app with Puma on Heroku?

I am running a small Rails application on Heroku with one dinosaur and several Puma employees.

Puma docs say:

The general rule is to use preload_app when your employees die often and require a quick start. If you have a lot of workers, you should probably not use preload_app.

This suggests that I should not use preload_app! in my config/puma.rb However, I have a few unanswered questions:

  • When do my workers die? Will they be received and re-forked after a certain number of requests? How can I control this?
  • How do I know if my employees need a quick start?

Clearly, preload_app! should save resources when using many workers, but I see no shortage of its use even with a small number of workers.

Heroku's recommended configuration for a "simple Rails application" includes preload_app! but they do not offer any indication when not to use it.

When preload_app! not to use and why? (Ignoring the issue with a phased restart.)

+8
ruby-on-rails heroku preload puma
source share
1 answer

In addition to a quick start, preload_app! also saves memory with the Copy on Write feature introduced in Ruby 2.0.

You can read this great Heroku post introducing the idea of ​​copy-to-write in Ruby:

Copy to record or COW is an optimization that can reduce the amount of memory in the ruby ​​process when copying it. Instead of allocating duplicate memory in a forked process, COW allows several processes to share the same memory, while one of the processes does not need to modify part of the information.

Thus, no matter how much work you have, it is always recommended to include preload_app! , if possible.

0
source share

All Articles