I know worker_processes
represents the number of worker processes, but how should this value be set? Theoretically, it is correct to set it according to the multiple of the number of CPU cores, but how many times is it? Some people say that you should set as many processes as there are cores, and another theory is to set it to twice the number of CPU cores.
But I think there should be a principle here. Otherwise, why doesn't nginx determine the number of cores in the program and then fork the corresponding process? I'm sure this value needs to be judged based on some experience. Can anyone share their experience in this regard?
Generally speaking, just set it to the number of CPU cores. Also, don’t forget to set worker_cpu_affinity. This configuration is used to bind the worker process to the specified cpu core, reducing the impact of on-site reconstruction of registers and other registers caused by multi-CPU core switching. Performance loss. For information about this configuration item, please refer to http://www.nginx.org/en/docs/ngx_core....
In addition, Tengine, the nginx branch maintained by Taobao, can use the auto command to automatically configure worker_processes and worker_cpu_affinity. Tengine has been open source: http://tengine.taobao.org/
Personally, if my machine only runs nginx applications, I set the total number of cores to -1. Maybe it is a habit, but it has always worked very well~
I think auto is fine.