In CentOS6.5, Nginx loads multiple CPU Cores

Source: Internet
Author: User


How to configure Nginx multi-core CPU and worker_cpu_affinity
1. 2-core CPU, enable 2 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 kernel.
2. 2-core CPU, 4 processes enabled

Worker_processes 4;
Worker_cpu_affinity 01 10 01 10;

Four processes are enabled, which correspond to two CPU Cores
3. 4-core CPU, 4 processes

Worker_processes 4;
Worker_cpu_affinity 0001 0010 0100 1000;
0001 indicates that the first CPU kernel is enabled, 0010 indicates that the second CPU kernel is enabled, and so on.
4. 4-core CPU, enable 2 processes

Worker_processes 2;
Worker_cpu_affinity 0101 1010;
0101 indicates that the first and third kernels are enabled, and 1010 indicates that the second and fourth kernels are enabled.
Two processes correspond to four kernels.
The worker_cpu_affinity configuration is written in/etc/nginx. conf.
The value of 2 cores is 01, and the value of 4 cores is 00000001. The number of cores is several digits. 1 indicates that the kernel is enabled, and 0 indicates that the kernel is disabled.

5. 8-core CPU and 8 Processes

Worker_processes 8;
Worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
0001 indicates that the first CPU kernel is enabled, 0010 indicates that the second CPU kernel is enabled, and so on.

Worker_processes can be enabled at most 8. Performance Improvement of more than 8 processes will not be improved, and the stability will be reduced. Therefore, 8 processes are sufficient.
Restart nginx and run/etc/init. d/nginx restart.
Test whether nginx is useful to multiple CPU cores and execute the AB .exe-c 1000-n 1000 http://www.domain.com/index.php on another machine
AB .exe is a performance testing tool installed with apache. It can simulate concurrent requests from multiple clients.
Run the top command on the server and press 1 to view the CPU kernel. If the utilization of multiple CPU cores is similar, nginx has successfully used multi-core CPUs.
After the test, the CPU kernel load should be reduced at the same time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.