Nginx optimized for CPU configuration instructions

"In Nginx profile, there are two instruction 'worker_processes', 'worker_cpu_affinity' can be configured optimized for multicore CPU"

# worker_processes

The number of processes worker_processes instructions to set Nginx services, based on past experience, in order to allow multi-core CPU parallel processing tasks well, we will recommend an appropriate increase worker_processes command assignment, of course, this value is not bigger is better, Nginx process too much may increase the burden on the main scheduling process, IO may also affect the efficiency of the system, so that, in general, and quite a few core CPU or two times to the number of cores. Take 4-core CPU, for example:
worker_processes = 4;

Once set up worker_processes instruction, it is necessary to set worker_cpu_affinity instruction.

# worker_cpu_affinity

worker_cpu_affinity instruction is used for the allocation of CPU cores in each work process, the value of this instruction is represented by several groups of binary values, so set up a little trouble, but be tracked, it is not difficult. In the setting value, several processes on a few number of groups, each group on a few number of several core CPU, 1 representative of use, 0 is not used. It is worth noting that the order and the order of bits CPU is reversed, recommended that the average allocation to different processes running on different CPU cores. Example 4 quad-core process, there will be four sets of values, and each group has a four-digit number, the following command set:
worker_cpu_affinity = 0001 0010 0100 1000;		#第一个进程使用第一个内核,第二个进程使用第二个内核,以此类推

If the value of worker_processes instruction is 8, namely a quad-core 8 process, the assignment method:

worker_cpu_affinity = 0001 0010 0100 1000 0001 0010 0100 1000;	 #循环赋值

If a machine is an eight-core CPU, and worker_processes = 8, then the assignment method worker_cpu_affinity as follows:

worker_cpu_affinity = 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000

Content Source: "Nginx high-performance web server explanation"

Guess you like

Origin blog.csdn.net/Linux_liuge/article/details/94891437