Mastering Nginx

(Ron) #1
Chapter 8

[ 209 ]

The preceding two commands will increase the maximum number of file descriptors


allowed for a new process running as user http://www. This will also persist across a reboot.


The following two commands will increase the maximum number of file descriptors
allowed for a running NGINX process:


prctl -r -t privileged -n process.max-file-descriptor -v 65535 -i


process pgrep nginx


prctl -x -t basic -n process.max-file-descriptor -i process `pgrep


nginx`


Each of these methods will change the operating system limit itself, but will have


no effect on the running NGINX process. To enable NGINX to use the number of
file descriptors specified, set the worker_rlimit_nofile directive to this new limit:


worker_rlimit_nofile 65535;

worker_processes 8;

events {

worker_connections 8192;

}

Now, send the running nginx master process the HUP signal:


kill -HUP cat /var/run/nginx.pid


NGINX will then be able to handle just over 65,000 simultaneous clients, connections


to upstream servers, and any local static or cached files. This many worker_processes


only makes sense if you actually have eight CPU cores or are heavily I/O bound. If
that is not the case, decrease the number of worker_processes to match the number


of CPU cores and increase worker_connections so that the product of the two
approaches 65,000.


You can, of course, increase the number of total file descriptors and worker_
connections up to a limit that makes sense for your hardware and use case. NGINX


is capable of handling millions of simultaneous connections, provided the operating
system limits and configuration are set correctly.

Free download pdf