How Nginx Ingress calculates the worker_processes and worker_rlimit_nofile
Article Number: 000020079
Situation
Question
How Nginx Ingress calculates the worker_processes and worker_rlimit_nofile
Answer
About the parameters;
worker_processes
This parameter determines the number of Nginx worker processes to spawn during startup.
worker_rlimit_nofile
This parameter controls the open file limit per worker process.
More details can be found on Nginx documentation
Both worker_processes
and worker_rlimit_nofile
are calculated dynamically by Nginx Ingress during startup.
Based on the source code of Ingress Nginx;
worker_processes = Number of CPUs ($ grep -c processor /proc/cpuinfo)
worker_rlimit_nofile = ( RLIMIT_NOFILE / worker_processes ) - 1024
where RLIMIT_NOFILE is the maximum allowed open files by the process ( ulimit -n
)
From Nginx Ingress shell, you can verify the same.
# kubectl exec -it -n ingress-nginx nginx-ingress-controller-8ln2b -- bash
bash-5.0$ ulimit -n
1048576
bash-5.0$
bash-5.0$ grep -c processor /proc/cpuinfo
2 <<---- worker_processes
bash-5.0$
bash-5.0$ echo $(((1048576/2)-1024))
523264 <<--- worker_rlimit_nofile
bash-5.0$
bash-5.0$ egrep "worker_processes|worker_rlimit_nofile" /etc/nginx/nginx.conf
worker_processes 2;
worker_rlimit_nofile 523264;
bash-5.0$