How to make full use of CPU resources to improve server performance

Source: Internet
Author: User

The basic idea is how to make the CPU hyper-threading or multi-core more balanced and efficient use. We know that there is always a CPU dedicated to responding to the NIC interrupt requests. If the network request package is very large, A single CPU may not be able to handle the problem. Therefore, you need to activate multi-core or hyper-threading to distribute Nic interrupt requests to multiple CPUs for execution, so as to improve the overall server access performance, it is also a good way to improve CPU resource utilization. We will discuss it as follows:

I. Dual-CPU hyper-threading Server

We know that in Linux, for servers with dual-CPU hyper-threading, if the kernel activates the CPU hyper-threading function (HT), four CPUs can be identified through CAT/proc/cpuinfo: CPU0-3, CPU 0 and cpu1 is the same real CPU itself and its hyper-threading CPU, cpu2 and cpu3 is also the same.

We can configure the IRQ route of the NIC to select a specified CPU to process the interrupt request of the NIC, so that the Interrupt Processing of multiple NICS is allocated to two real CPUs respectively, to make full use of the performance of Dual CPU.

1. First, you can view the CPU details by accessing/proc/cpuinfo.

CAT/proc/cpuinfo

 

CAT/proc/cpuinfo | grep Processor

 

CAT/proc/cpuinfo | grep processor | WC-l

The last command can get the current number of CPUs.

 

2. Obtain the interrupt IRQ numbers of eth0 and eth1 NICs respectively, and assign them to shell variables.

Eth0_irq_num = 'cat/proc/interrupts | grep eth0 | awk-F': ''{print $1 }''

Eth1_irq_num = 'cat/proc/interrupts | grep eth1 | awk-F': ''{print $1 }''

 

3. Specify the CPU to process the interrupt request of the corresponding Nic

First, you can check the current CPU usage (the root user is required ):

CAT/proc/IRQ/$ eth0_irq_num/smp_affinity

CAT/proc/IRQ/$ eth1_irq_num/smp_affinity

 

Echo 8>/proc/IRQ/$ eth0_irq_num/smp_affinity

(Specify cpu3 to process the eth0 interrupt request)

 

Echo 2>/proc/IRQ/$ eth1_irq_num/smp_affinity

(Specify cpu1 to process the eth1 interrupt request)

 

4. view the effect after switchover.

Watch CAT/proc/interrupts

We can see the interrupt processing effect at intervals of 2 seconds.

 

Ii. Dual-CPU dual-core servers

In Linux, for dual-CPU dual-core servers, if the kernel does not enable the hyper-threading HT option, access CAT/proc/cpuinfo can identify 4 CPUs, are CPU0-3, cpu0 and cpu1 are two cores of the same real CPU. Likewise, cpu2 and cpu3 are two cores of another real CPU. And shared a 4 m second-level cache for the core of the same real CPU. Therefore, if we map the interrupt request of a network card to the two cores of the same real CPU, the dual-core CPU performance can be fully utilized to improve the overall server performance while ensuring the second-level cache hit rate.

The specific setting method is described above.

 

3. Additional instructions

Note: For smp_affinity, a byte (eight bits) essentially corresponds to a binary bit: XXXXXXXX, indicating cpu7, cpu6, cpu5, cpu4, cpu3, cpu2, cpu1, cpu0, the corresponding bit is 1, indicating the selected CPU status.

1, Echo 8>/proc/IRQ/$ eth0_nu/smp_affinity. Because 8 = 1000, CPU 3 is specified to respond.

2, Echo 2>/proc/IRQ/$ eth1_nu/smp_affinity. Because 2 = 0010, cpu1 is specified to respond.

3, Echo C>/proc/IRQ/$ eth0_nu/smp_affinity. Because c = 1100, cpu2 and cpu3 are specified to respond.

4, Echo 3>/proc/IRQ/$ eth1_nu/smp_affinity. Because 3 = 0011, cpu0 and cpu1 are specified to respond.

 

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.