NGINX: How to calculate an optimal no. of worker processes and worker connections

nginxphusion-passengerruby-on-rails

Our web app is running on a Linode 2048 server at the moment (~ 2048 GB of RAM)

The MYSQL database is on another linode of it's own so this server is really only handling NGINX and and the Rails application.

The application itself uses about 185976 of memory per instance (RSS).

Our traffic is < 1000 per day and the pages are mostly cached so there are fewer hits to the rails app itself.

My question is – how can I calculate optimal NGINX config settings for my app?

Below is the current config:

worker_processes  1;

# pid of nginx master process
pid /var/run/nginx.pid;

events {
  worker_connections  1024;
}


http {

  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;

  passenger_root /home/user/.rvm/gems/ree-1.8.7-2011.01@URTV/gems/passenger-3.0.3;
  passenger_ruby /home/user/.rvm/rubies/ree-1.8.7-2011.01/bin/ruby;

  include       mime.types;
  default_type  application/octet-stream;

  sendfile        on;

  tcp_nopush    on;
  tcp_nodelay   on;

  # gzip settings
  gzip  on;
  gzip_http_version 1.0;
  gzip_comp_level 2; 
  gzip_vary on;
  gzip_proxied any; 
  gzip_types text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

  # load extra modules from the vhosts directory
  include /opt/nginx/vhosts/*.conf;
}

Any advice would be appreciated! 🙂

Best Answer

You can have a look a this blog post: http://www.alfajango.com/blog/performance-tuning-for-phusion-passenger-an-introduction/ which will explain how to calculate it