search

Home  >  Q&A  >  body text

How to set up worker_processes of nginx

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?

淡淡烟草味淡淡烟草味2796 days ago918

reply all(3)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 17:31:54

    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/

    reply
    0
  • 某草草

    某草草2017-05-16 17:31:54

    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~

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-16 17:31:54

    I think auto is fine.

    worker_processes auto;

    reply
    0
  • Cancelreply