Introduction nginx does not enable multi-core CPU by default. We can add worker_cpu_affinity configuration parameters to fully utilize the performance of multi-core CPU. CPU is the most critical resource for task processing and Computing. The more CPU cores, the better the performance. Rule setting (1) How many cores a CPU has, there are several digits, 1 indicates that the kernel is enabled, 0 indicates that the kernel is disabled (2) worker_processes can be enabled at most 8, the performance of more than eight processes will not be improved, and the stability will be reduced. Therefore, eight processes are enough to demonstrate the two-core CPU of the instance and start two processes.
worker_processes 2;worker_cpu_affinity 01 10;
01 indicates that the first CPU kernel is enabled, and 10 indicates that the second CPU kernel is enabled.
Worker_cpu_affinity 01 10; indicates that two processes are enabled. The first process corresponds to the first CPU kernel, and the second process corresponds to the second CPU core and two-core CPU, enabling eight processes.
worker_processes 8;worker_cpu_affinity 01 10 01 10 01 10 01 10;
Eight processes are enabled, which correspond to two kernels.
8-core CPU, enabling 8 Processes
worker_processes 8;worker_cpu_affinity 10000000 01000000 00100000 00010000 00001000 00000100 00000010 00000001;
00000001 indicates that the first CPU kernel is enabled, 00000010 indicates that the second CPU kernel is enabled, and so on.
8-core CPU, enabling 2 processes
worker_processes 2;worker_cpu_affinity 10101010 01010101;
10101010 indicates that kernel 01010101, and are enabled. indicates that kernel, and are started.
Two processes correspond to eight kernels. After nginx configuration is restarted, The nginx service needs to be restarted.
/etc/init.d/nginx restart