Nginx Worker Tuning

On high traffic servers running Nginx, you will want to ensure the proper number of processes are available for the requests. This can be fine tuned in the nginx.conf configuration file via both worker_processes and worker_connections.

# grep worker /etc/nginx/nginx.conf
worker_processes 1;
worker_connections 1024;

worker_processes:

The number of NGINX worker processes (the default is 1). In most cases, running one worker process per CPU core works well. There are times when you may want to increase this number, such as when the worker processes have to do a lot of disk I/O.

worker_connections:

The maximum number of connections that each worker process can handle simultaneously. The default is 512, but most systems have enough resources to support a larger number. The appropriate setting depends on the size of the server and the nature of the traffic, and can be discovered through testing.


Maximum Connections = worker_processes * worker_connections.

Both of these values multiplied result in the maximum number of concurrent connections. Its important to keep in mind that each connection will require a file handler, and two if the connection is proxied, so you will need to verify the open file limit. You will find errors in the Nginx log if you hit the open file limit.

The Nginx configuration option worker_rlimit_nofile sets the value for the maximum file descriptors that can be opened by a single worker process. If you don't set the worker_rlimit_nofile directive, then the OS settings will determine how many FDs can be used by Nginx. One method of changing the FD limit for Nginx is to change the values in the OS.

Further Information
https://www.nginx.com/blog/tuning-nginx/
http://nginx.org/en/docs/ngx_core_module.html#worker_rlimit_nofile
https://www.linode.com/docs/websites/nginx/configure-nginx-for-optimized-performance

Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments