Nginx does not enable the use of multi-core CPUs by default. We can make full use of multi-core CPUs by increasing the worker_cpu_affinity configuration parameter. The CPU is the most critical resource for task processing and calculation. The more CPU cores, the better the performance.
Configure Nginx multi-core CPU, worker_cpu_affinity usage methods and examples
1. 2-core CPU, start 2 processes
worker_processes 2;
worker_cpu_affinity 01 10;
01 Indicates enabling the first CPU core , 10 means enabling the second CPU core
worker_cpu_affinity 01 10; means starting two processes, the first process corresponds to the first CPU core, and the second process corresponds to the second CPU core.
2. 2-core CPU, open 4 processes
worker_processes 4;
worker_cpu_affinity 01 10 01 10;
opened four processes, which correspond to opening 2 CPU cores
3 . 4-core CPU, open 4 processes
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
0001 means enabling the first CPU core, 0010 means enabling the second CPU core, and so on
4. 4-core CPU, start 2 processes
worker_processes 2;
worker_cpu_affinity 0101 1010;
0101 means turning on the first and third cores, 1010 means turning on the second and fourth cores
2 processes correspond to four cores
worker_cpu_affinity configuration is written in /etc/nginx/nginx.conf.
2 cores are 01, 4 cores are 0001, and 8 cores are 00000001. There are several digits depending on the number of cores. 1 means the core is on, 0 means the core is off.
5. 8-core CPU, open 8 processes
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 0010000 0 01000000 10000000;
0001 means enabling the first CPU core, 0010 means enabling the second one CPU core, and so on
worker_processes can open up to 8. The performance improvement of more than 8 will not be improved, and the stability will become lower, so 8 processes are enough.
After the configuration is completed, restart nginx and execute /etc/init.d/nginx restart
Test whether nginx can use multiple CPU cores. Execute ab.exe -c 1000 -n 1000 http on another machine ://www.domain.com/index.php
ab.exe is a performance testing tool that comes with installing apache. It can simulate concurrent requests from multiple clients.
Execute top on the server and press 1 to see the working status of the CPU core. If the utilization rates of multiple CPU cores are similar, it proves that nginx has successfully utilized multi-core CPUs.
After the test, the load on the CPU cores should be reduced at the same time.
http://blog.chinaunix.net/uid-20662363-id-2953741.html
The above introduces the methods and examples of configuring Nginx multi-core CPU, worker_cpu_affinity, including affinity content. I hope it will be helpful to friends who are interested in PHP tutorials.