ruby-on-railsnginxserverhotpatching

During hot patch in nginx ruby on rails can I reload the specific file instead of whole application by server restart?


Sometimes I have to hot patch production code due to an error/bug (mostly in a single file) but I have set eager_load and cache_classes to true in the development environment. Because of these two, the server takes around 2 and half minutes to load and the same goes for a hot patch.

My end goal is to reduce server load time. One way is to add 'require: false' for gems which are not required when the application starts and then load them later when required. But is it possible reload only the updated file instead of restarting the whole application?

I am using an nginx free server (Enterprise nginx version could be a solution which provides zero downtime but is it possible in the version?)


Solution

  • Buying enterprise version of Nginx will not help you. Nginx is used in pair with Phusion Passenger/Unicorn/Thin. Zero downtime deployment should be implemented not in Nginx, but in Passenger/Unicorn. I prefer to use Unicorn, it's free, powerful and it supports zero downtime deployment.

    In production environment Rails needs to load and cache every file to server HTTP requests quickly, I suggest not change this behavior, changing it will slow down your production.

    I strongly suggest not to modify files on the server. se Capistrano/Mina for deployment. Changing files by-hand can break production, and you will definitely have huge downtime.

    Capistrano can help you to deploy project using one command. Also Capistrano can help you to revert quickly to the previous version if something will go wrong.

    https://www.digitalocean.com/community/tutorials/how-to-set-up-zero-downtime-rails-deploys-using-puma-and-foreman

    https://www.devroom.io/2011/09/14/lighting-fast-zero-downtime-deployments-with-git-capistrano-nginx-and-unicorn/