Last Updated: February 25, 2016
·
908
· jasperkennis

Reduce Rails request time with some extra instances of passenger

Using * ab -n200 -c25 http://yoururl.com * you can bombard your server with requests (in this case 200 requests, 25 at a time). You can run the command from most Linux based machines and also from a Mac. It gives you some insight in the speed of your application when there's a lot of traffic.

For my site, performing 200 requests divided in 25 requests, initially took 90 seconds to process, the longest requests taking up to 4 seconds to complete. Of course that's a heavy load, but it's not unrealistic. So, how to reduce that response time.

I had a lot of succes increasing the maximum number of instances of the app running. to do so, add the following to your nginx.conf:

http {
  passenger_max_instances_per_app  4;
  rails_spawn_method               smart;
  passenger_max_pool_size 4;
}

Where 4 is the actual number of instances I'm running. The number you should be running depends on your hardware, see http://www.modrails.com/documentation/Users%20guide%20Nginx.html#!/_passenger_max_instances_per_app_lt_integer_gt for more on that. The span method you should use also depends on your system, see the same documentation page. Good luck!