How to set up worker_processes of nginx
淡淡烟草味
淡淡烟草味 2017-05-16 17:29:54
0
3
899

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?

淡淡烟草味
淡淡烟草味

reply all(3)
曾经蜡笔没有小新

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.

worker_processes auto;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template