About how much of a memory footprint reduction does nginx give over Apache2? About how much of a memory footprint reduction does nginx give over Apache2? nginx nginx

About how much of a memory footprint reduction does nginx give over Apache2?


The answer is highly dependent on:

  • The web server modules you have enabled
  • The implementation of Ruby you use (e.g. Ruby Enterprise Edition vs MRI)
  • The traffic patterns of your app.

Setting up nginx + Passenger is really easy. Just quickly install each environment on cloud servers or virtual machines, and run some benchmarking tools against them.

Generally speaking, though, the largest RAM consumer is your Rails app, not the web server. If you're concerned about RAM usage, your time will be better spent comparing Ruby implementations or reducing the number of gems/plugins/libraries your code uses, or reducing the number of web server modules you use.

Someone did a benchmark of Nginx vs Apache memory utilization per concurrent connection. Nginx is the clear winner. But it should be noted that the highest memory utilization on that graph is only ~40MB at about 4000 concurrent connections. 40MB is a smaller footprint than even a single Rails instance in most cases, and it is not likely that you'll be able to achieve 4000 concurrent rails requests on a single server. So it pays to switch to Nginx secondarily, but primarily, you should switch to Ruby Enterprise Edition if you haven't already, then try reducing the memory footprint of your application, because your Rails application will use significantly more memory than either of these web servers.

For example, I run Apache/Passenger/REE in production, and even with REE's improved memory footprint, my Rails app is using 13 times as much memory as Apache, as reported by passenger-memory-stats.

the growth rate of memory usage vs concurrent connections is starkly larger with apache