Based on the documentation here, https://nginx.org/en/docs/ngx_core_module.html#worker_processes
The worker_processes is defined as the number of worker processes.
The optimal value depends on many factors including (but not limited to) the number of CPU cores, the number of hard disk drives that store data, and load pattern. When one is in doubt, setting it to the number of available CPU cores would be a good start (the value “auto” will try to autodetect it).
Most of the guides recommend setting this value to the number of cores on the server or set to auto which itself sets it to the number of cores on the machine.
I'm running OpenResty on kubernetes so when I check the number of CPU cores from inside the openresty pod, it returns me the number of cores my physical machine (node) has. However, with CPU requests & limits on the k8s, all the 8 cores wouldn't be available for the pod.
So what should be worker_processes's value for shared CPUs in case of kubernetes?
Thanks!
Good question and one I'm still looking for the answer to. However, at current my thinking is this, Nginx + Kubernetes where Nginx is not the ingress controller should have worker processes = 1. Why? Each worker process is a new process within the container and the general guidance is that there should only be one process. So Nginx will have n + 1 processes in a single container if you use 'auto' where n is the number of cores. Even setting worker processes = 1 is 2 total processes in the container.
Assuming that Nginx is really good at maintaining its additional processes then you can probably go with 'auto' and take advantage of Nginx in a single pod. Alternatively, you can go with worker processes = 1, and then scale the pod outside to achieve similar scale.
Ultimately some performance testing of different scenarios is required to confirm how it works for your application.