Improve Nginx performance by configuring CPU parameters Worker_cpu_affinity

Source: Internet
Author: User

Brief introduction
Nginx does not turn on using multicore CPUs by default, we can take advantage of the performance of multicore CPUs by adding worker_cpu_affinity configuration parameters. CPU is the task processing, compute the most critical resources, the more CPU cores, the better performance.

Rule setting

(1) How many cores the CPU has, there are several, 1 means the kernel is on, 0 is the kernel shutdown

(2) worker_processes up to 8, more than 8 performance will no longer increase, and stability will become lower, so 8 processes enough

Example: Linode VPS minimum, 8-Core Cpu,nginx configuration information:

Worker_processes 8;worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

Configure 1:4 CPU (4 Core) + 4 worker_processes (1 CPUs per worker_processes)

[Email protected] ~]#  cat/proc/cpuinfo | grep processorprocessor       : 0processor       : 1processor       : 2processor       : 3

Nginx can be configured below, each CPU assigned one:

Worker_processes 4;worker_cpu_affinity 0001 0010 0100 1000;

Configure 2:8 CPU (8 Core) + 8 worker_processes (1 CPUs per worker_processes)

Worker_processes 8;worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

Configure 3:16 CPU (Core) + worker_processes (1 CPUs per worker_processes)

Worker_processes 16;worker_cpu_affinity 0000000000000001 0000000000000010 0000000000000100 0000000000001000 0000000000010000 0000000000100000 0000000001000000 0000000010000000 0000000100000000 0000001000000000 0000010000000000 0000100000000000 0001000000000000 0010000000000000 0100000000000000 1000000000000000;

Configure 4:2 CPU (2 Core) + 8 worker_processes (1 CPUs per worker_processes)

Worker_processes  8;  worker_cpu_affinity 01 10 01 10 01 10 01 10;

Configure 5:8 CPU (8 Core) +2 worker_processes (1 CPUs per worker_processes)

Worker_processes  2;  Worker_cpu_affinity 10101010 01010101;

Description: 10101010 indicates that the 2,4,6,8 kernel is turned on and 01010101 indicates that the 1,3,5,7 kernel is started
Check the usage status of Nginx CPU using Apache AB Test:

top-11:16:01 up 188 days, 19:50,  2 users,  load average:0.43, 0.72, 0.71tasks:185 Total,   1 running, 184 SLE Eping,   0 stopped,   0 zombieCpu0  : 26.0%us, 10.5%sy,  0.0%ni, 42.9%id, 19.3%wa  , 0.7%hi, 0.7%si ,  0.0%stcpu1  :  7.7%us,  5.4%sy,  0.0%ni, 87.0%id,  0.0%wa,  0.0%hi  , 0.0%si,  0.0%stcpu2  :  9.7%us,  3.3%sy,  0.0%ni, 85.0%id,  1.7%wa,  0.0%hi  , 0.3%si,  0.0%stcpu3  :  6.0%us,  4.0%sy,  0.0%ni, 90.0%id,  0.0%wa,  0.0%hi  , 0.0%si,  0.0%stmem:   8058060k Total,  4953400k used,  3104660k free,   104856k buffersswap:   490488k Total,    55468k used,   435020k free,  1610876k Cached

If the utilization of multiple CPU cores is not much different, it proves that Nginx has successfully utilized multi-core CPU.
At the end of the test, the load on the CPU core should be reduced at the same time.

Reference:

http://www.freewil.net/blog/archives/198

http://luy.li/2009/12/30/nginx-user_agent-limit_rate/

Improve Nginx performance by configuring CPU parameters Worker_cpu_affinity

Related Article

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.