Last Updated: February 25, 2016
·
732
· vansickle

Fix Ruby app shutdowns inside Passenger/Nginx

If you have Ruby web app, that can be used occasionally and you using Passenger/Nginx to serve it you can find that sometimes you wait too long for response from it.
It happens when nobody used app for sometime - Passenger kills it for releasing memory. So every time any user opens this web app after long time he must wait until app starts. 10-15 seconds for me (and even more as users reported). It's understandable from performance view, but very annoying in our case.

So to overcome this we must set some options in Passenger.

Passenger has huge docs - http://www.modrails.com/documentation/Users%20guide%20Nginx.html#PassengerPoolIdleTime

Doc for v3 by now, we used 2.7 so a bit different (nginx.conf):

rails_spawn_method               smart; #deprecated in 3.0, use passenger_spawn_method
rails_app_spawner_idle_time      0;
rails_framework_spawner_idle_time 0;
passenger_pool_idle_time         0;

And know our app never unloaded.

Another on this:
http://stackoverflow.com/questions/853532/slow-initial-server-startup-when-using-phusion-passenger-and-rails
But nobody there advised to set poolidletime to 0 which I found necessary to solve problem.