Nginx worker_rlimit_nofile

worker_rlimit_nofile example
nginx env
nginx keepalive_timeout
worker_connections is a directive contained within
nginx worker_connections proxy
nginx worker_connections error
nginx worker_connections 768
nginx config generator

How does one set worker_rlimit_nofile to a higher number and what's the maxium it can be or is recommended to be?

I'm trying to follow the following advice:

The second biggest limitation that most people run into is also related to your OS. Open up a shell, su to the user nginx runs as and then run the command ulimit -a. Those values are all limitations nginx cannot exceed. In many default systems the open files value is rather limited, on a system I just checked it was set to 1024. If nginx runs into a situation where it hits this limit it will log the error (24: Too many open files) and return an error to the client. Naturally nginx can handle a lot more than 1024 files and chances are your OS can as well. You can safely increase this value.

To do this you can either set the limit with ulimit or you can use worker_rlimit_nofile to define your desired open file descriptor limit.

From: https://blog.martinfjordvald.com/2011/04/optimizing-nginx-for-high-traffic-loads/

worker_rlimit_nofile = worker_connections * 2 file descriptors

Each worker connection open 2 file descriptors (1 for upstream, 1 for downstream)

Nginx worker_rlimit_nofile, Server configuration: 32C 128G Mem cat /proc/sys/fs/file-max 13172534 ps -ef|​grep -i nginx root 23716 23669 0 01:02 ? 00:00:00 nginx:  Not sure whether the formula is correct: worker_rlimit_nofile = (worker_connections * worker_processes) * 2. There seems to be widespread consensus that the correct formula is the one in Azad's answer. The formula in this answer yields the correct result by accident if nginx only has 1 worker process. – Manuel May 12 at 2:15

worker_rlimit_nofile = worker_connections *2

because each connection opens two fd's one for client and one for proxy server.

How to customize nginx worker_rlimit_nofile? · Issue #2710 , # Determines how many clients will be served by each worker process. # (Max clients = worker_connections * worker_processes). # Should be equal to `ulimit -​n /  Both directives clearly reference to corresponding OS limits, RLIMIT_NOFILE and RLIMIT_CORE.Quoting setrlimit() description as available in POSIX:. RLIMIT_CORE This is the maximum size of a core file, in bytes, that may be created by a process.

While setting worker_rlimit_nofile parameter, you should consider both worker_connections and worker_processes. You may want to check your OS's file descriptor first using: ulimit -Hn and ulimit -Sn which will give you the per user hard and soft file limits respectively. You can change the OS limit using systemctl as:

sudo sysctl -w fs.file-max=$VAL

where $VAL is the number you would like to set. Then, you can verify using:

cat /proc/sys/fs/file-max

If you are automating the configuration, it is easy to set worker_rlimit_nofile as:

worker_rlimit_nofile = (worker_connections * worker_processes)*2

The worker_processes is set to 1 by default, however, you can set it to a number less than or equal to the number of cores you have on your server:

grep -c ^processor /proc/cpuinfo

Configuring NGINX for Maximum Throughput Under High , nginx.conf¶. user www www; ## Default: nobody worker_processes 5; ## Default: 1 error_log logs/error.log; pid logs/nginx.pid; worker_rlimit_nofile 8192; events  worker_rlimit_nofile is the maximum file descriptor number that can be opened by one worker process: 1) If the directive is specified, nginx will set it for you (setrlimit(1)). Default value (the ulimit -n number in your case) will be overridden.

Full Example Configuration, In nginx worker_processes are the number of processes nginx will spawn. Default is 1 , worker_rlimit_nofile is the maximum file descriptors that can be opened  nginx worker_rlimit_nofile Option (Increase Open FD Limit at Nginx Level) Nginx also comes with worker_rlimit_nofile directive which allows to enlarge this limit if it’s not enough on fly at process level. To set the value for maximum file descriptors that can be opened by nginx process. Edit nginx.conf file, enter:

nginx configuring worker_rlimit_nofile and worker_processes , you must set worker processes based on your CPU cores, nginx does not benefit from setting more than that worker_processes auto; #some  A full-fledged example of an NGINX configuration. Analytics cookies are off for visitors from the UK or EEA unless they click Accept or submit a form on nginx.com.

How to tune Nginx for best performance – SysAdmin Notes, Default is 768. Theoretically, nginx can handle max clients = worker_processes * worker_connections. We use worker_connections = 10240. worker_rlimit_nofile. Nginx is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet. It is more resource-friendly than Apache in most cases and can be used as a web server or reverse p

Comments
  • Even though the nginx docs are not 100% clear about that, it seems like worker_rlimit_nofile is applied to each worker. Therefore it makes no sense to multiply with worker_processes. But you may have to multiply by 2, since a worker needs 2 File Descriptors per Connection - one for the client, one for the served File (or upstream, proxy...).
  • According to the nginx documentation you don't need to multiply by 2 as worker_connections should already include both types of connections (downstream and upstream).
  • Not sure whether the formula is correct: worker_rlimit_nofile = (worker_connections * worker_processes) * 2. There seems to be widespread consensus that the correct formula is the one in Azad's answer. The formula in this answer yields the correct result by accident if nginx only has 1 worker process.