vmware linux top si高以及网卡队列、软负载相关优化

今日,测试公司自行开发的一rpc中间件,期间发现top si的比例很高,且几乎只有一个cpu是繁忙的,其他均基本为0。

经查,si主要是系统软中断,最后确定是网卡导致的系统中断。于是,往上搜了下资料,主流的用法是如果网卡支持多队列的,则启用之。

常用的Intel的82575、82576,I350,Boardcom的57711等网卡都支持多队列。如果是实体机,可通过如下方式判断是否支持多队列:

lspci -vvv  #lspci在centos 6.x之后的版本不会默认安装,可yum install pciutils进行安装。

对于8257*网卡,如果有类似如下输出,则代表支持多队列模式(对于I350网卡,通常输出中并没有MSI-X信息,此时可查看/proc/interupts,见下文)。

Message Signaled Interrupts(MSI)是PCI规范的一个实现,可以突破CPU 256条interrupt的限制,使每个设备具有多个中断线变成可能,多队列网卡驱动给每个queue申请了MSI。MSI-X是MSI数组,Enable+指使能,TabSize是数组大小。

 

查看I350支持多队列网卡情况,如下:

[root@localhost conf]# cat /proc/interrupts | grep em

            CPU0       CPU1       CPU2       CPU3       CPU4       CPU5       CPU6       CPU7       CPU8       CPU9       CPU10      CPU11      CPU12      CPU13      CPU14      CPU15      CPU16      CPU17      CPU18      CPU19      CPU20      CPU21      CPU22      CPU23 

第一列为irq的序号,最后两列为可编程中断控制器,设备名称(request_irq的dev_name字段)。中间N列为每个CPU的中断次数。
122: 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI-edge em1
123: 317 0 1525002 0 136796294 0 14608 0 36575 0 234650 0 112581 0 57594 0 2421679 0 356527 0 14841 0 43626 0 IR-PCI-MSI-edge em1-TxRx-0
124: 32759769 0 1014 0 2379 0 20687952 0 13631008 0 139 0 0 0 0 0 2329 0 1198 0 0 0 5017 0 IR-PCI-MSI-edge em1-TxRx-1
125: 79104 0 53120 0 197685 0 5310542 0 76355 0 188193 0 1942667 0 1344601 0 102724702 0 591552 0 257979 0 35252479 0 IR-PCI-MSI-edge em1-TxRx-2
126: 35124 0 28296053 0 298217 0 55493 0 41066 0 59423596 0 15789451 0 5433763 0 7282131 0 2488752 0 659172 0 740602 0 IR-PCI-MSI-edge em1-TxRx-3
127: 4348 0 37168 0 4258 0 6092 0 24019 0 7139 0 67133 0 70650 0 22483330 0 8788922 0 33297183 0 9071877 0 IR-PCI-MSI-edge em1-TxRx-4
128: 51834 0 19953406 0 32644 0 13201 0 50038651 0 78453 0 6586627 0 4350927 0 3563993 0 1590572 0 1227042 0 315684 0 IR-PCI-MSI-edge em1-TxRx-5
129: 13213287 0 13061 0 14871 0 5212485 0 17315 0 8097 0 486486 0 326284 0 918310 0 5816261 0 7420585 0 16253590 0 IR-PCI-MSI-edge em1-TxRx-6
130: 72244 0 72511 0 118347 0 6870910 0 156832 0 260694 0 21476142 0 5635175 0 4064530 0 8211846 0 2005408 0 3933305 0 IR-PCI-MSI-edge em1-TxRx-7
132: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI-edge em2
133: 90459 0 5975 0 62380 0 263900 0 41705 0 20558 0 262884 0 58614 0 43445 0 220422 0 57085 0 168755 0 IR-PCI-MSI-edge em2-TxRx-0
134: 7039 0 29185 0 25785 0 62442 0 29437 0 19950 0 243960 0 145535 0 101070 0 369315 0 176670 0 85794 0 IR-PCI-MSI-edge em2-TxRx-1
135: 9754 0 27260 0 37691 0 51555 0 34490 0 26055 0 112325 0 222156 0 130001 0 273594 0 208185 0 163116 0 IR-PCI-MSI-edge em2-TxRx-2
136: 8144 0 34842 0 27950 0 36975 0 27415 0 26215 0 197285 0 253643 0 148800 0 210380 0 170284 0 154249 0 IR-PCI-MSI-edge em2-TxRx-3
137: 9352 0 20077 0 29560 0 37561 0 25489 0 27155 0 130522 0 205660 0 214906 0 328060 0 124765 0 143075 0 IR-PCI-MSI-edge em2-TxRx-4
138: 7334 0 16901 0 21110 0 34270 0 29165 0 15060 0 162101 0 179681 0 202381 0 348260 0 192640 0 87279 0 IR-PCI-MSI-edge em2-TxRx-5
139: 9959 0 28310 0 30568 0 41550 0 32910 0 27325 0 154500 0 167498 0 218879 0 310999 0 145064 0 128620 0 IR-PCI-MSI-edge em2-TxRx-6
140: 11774 0 27740 0 43110 0 58246 0 37295 0 34885 0 196624 0 199484 0 152231 0 250235 0 123110 0 161448 0 IR-PCI-MSI-edge em2-TxRx-7
141: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI-edge em3
142: 11649 0 33485 0 36340 0 42105 0 44700 0 32530 0 191085 0 177009 0 163050 0 330534 0 160346 0 73349 0 IR-PCI-MSI-edge em3-TxRx-0
143: 11379 0 22335 0 35585 0 48650 0 35425 0 32335 0 179401 0 193488 0 192232 0 170335 0 136336 0 238681 0 IR-PCI-MSI-edge em3-TxRx-1
144: 10069 0 44811 0 37000 0 39910 0 39335 0 43160 0 134806 0 205363 0 226019 0 221720 0 127399 0 166590 0 IR-PCI-MSI-edge em3-TxRx-2
145: 15774 0 36851 0 49295 0 42040 0 51080 0 44805 0 108183 0 202266 0 189370 0 236519 0 156377 0 163622 0 IR-PCI-MSI-edge em3-TxRx-3
146: 15384 0 44440 0 63305 0 64655 0 41611 0 44325 0 111958 0 253747 0 217559 0 133340 0 196733 0 109125 0 IR-PCI-MSI-edge em3-TxRx-4
147: 14579 0 39240 0 58215 0 67860 0 61555 0 40870 0 102890 0 194096 0 287778 0 204359 0 104175 0 120565 0 IR-PCI-MSI-edge em3-TxRx-5
148: 14244 0 36155 0 56975 0 55257 0 50834 0 44535 0 91614 0 126635 0 179910 0 244226 0 229117 0 166680 0 IR-PCI-MSI-edge em3-TxRx-6
149: 15524 0 39270 0 61032 0 73560 0 49980 0 57285 0 83711 0 221278 0 219587 0 188061 0 183589 0 103305 0 IR-PCI-MSI-edge em3-TxRx-7
150: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 IR-PCI-MSI-edge em4
151: 14974 0 38157 0 52126 0 57610 0 48440 0 31945 0 172255 0 185329 0 129305 0 173168 0 234898 0 157975 0 IR-PCI-MSI-edge em4-TxRx-0
152: 16699 0 48430 0 64680 0 79250 0 68830 0 59345 0 117371 0 221335 0 155726 0 212181 0 172655 0 79680 0 IR-PCI-MSI-edge em4-TxRx-1
153: 18754 0 53052 0 65058 0 85732 0 78820 0 63424 0 78089 0 191158 0 196012 0 152555 0 95383 0 218145 0 IR-PCI-MSI-edge em4-TxRx-2
154: 17584 0 45570 0 62421 0 64330 0 58415 0 47925 0 111414 0 217125 0 185040 0 204959 0 153232 0 128167 0 IR-PCI-MSI-edge em4-TxRx-3
155: 16859 0 45385 0 57915 0 76571 0 72495 0 54665 0 132613 0 143151 0 191921 0 238210 0 159712 0 106685 0 IR-PCI-MSI-edge em4-TxRx-4
156: 17209 0 47805 0 75373 0 75690 0 67166 0 63775 0 135487 0 206185 0 159658 0 173140 0 180429 0 94265 0 IR-PCI-MSI-edge em4-TxRx-5
157: 16939 0 49385 0 75025 0 93725 0 82650 0 72350 0 138203 0 168072 0 81415 0 206450 0 174517 0 137451 0 IR-PCI-MSI-edge em4-TxRx-6
158: 18769 0 49092 0 76005 0 84715 0 89460 0 68645 0 93165 0 141489 0 151775 0 257523 0 150548 0 114996 0 IR-PCI-MSI-edge em4-TxRx-7

可以发现在本系统中,有4张网卡(PowerEdge R630的机器),两个CPU的网卡中断特别高,其中一个又是另一个的4倍左右。其中每张网卡最多支持8个队列,一般网卡规范都会说明。

[root@localhost conf]# cat /proc/irq/126/smp_affinity
00000000,00000000,00000000,00000000,00000000,00000040(‭00101000‬)

可知默认使用4/6号 CPU。

关于RPS/RFS,网上已经很多资料,读者搜一下就有很多了。本文更多的是从使用的角度进行一些介绍。

因为我们使用的是vmware上的linux虚拟机,因为vmware在vmxnet3开始支持多队列虚拟网卡,所以我们需要找到vmxnet是否安装以及其版本(往上很多都是转载的XEN的虚拟机,因此无法直接套用)。如下:

[root@localhost logs]# modprobe -cc | grep vmx
alias pci:v000015ADd000007B0sv*sd*bc*sc*i* vmxnet3

然后要查看vmxnet的实际版本号,如下:

[root@localhost logs]# ethtool -i eno16777736
driver: e1000
version: 7.3.21-k8-NAPI
firmware-version:
bus-info: 0000:02:01.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no

并且据官网所述,e1000好像不支持多队列特征,因此计划采用rps进行模拟,对于rps,可通过如下方式进行启用。

rps的设置在文件/sys/class/net/device/queues/rx-queue/rps_cpus中,参见https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Performance_Tuning_Guide/network-rps.html。

默认情况下,他们的值为0。

网上提及的rps_flow_cnt主要是RFS,其相当于RPS上的协调器,参见https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Performance_Tuning_Guide/network-rfs.html。

RPS有两种实现方式:

1 每队列绑定到1个CPU(其中eth0为网卡名,rx-n为队列号,如果不支持多队列的,则只会有rx-0)

/sys/class/net/eth0/queues/rx-0/rps_cpus 00000001

/sys/class/net/eth0/queues/rx-1/rps_cpus 00000002

/sys/class/net/eth0/queues/rx-2/rps_cpus 00000004

/sys/class/net/eth0/queues/rx-3/rps_cpus 00000008

/sys/class/net/eth0/queues/rx-4/rps_cpus 00000010

/sys/class/net/eth0/queues/rx-5/rps_cpus 00000020

/sys/class/net/eth0/queues/rx-6/rps_cpus 00000040

/sys/class/net/eth0/queues/rx-7/rps_cpus 00000080

2 每队列绑定到多个或所有CPU

/sys/class/net/eth0/queues/rx-0/rps_cpus 000000ff

/sys/class/net/eth0/queues/rx-1/rps_cpus 000000ff

/sys/class/net/eth0/queues/rx-2/rps_cpus 000000ff

/sys/class/net/eth0/queues/rx-3/rps_cpus 000000ff

/sys/class/net/eth0/queues/rx-4/rps_cpus 000000ff

/sys/class/net/eth0/queues/rx-5/rps_cpus 000000ff

/sys/class/net/eth0/queues/rx-6/rps_cpus 000000ff

/sys/class/net/eth0/queues/rx-7/rps_cpus 000000ff

通过,echo "000000ff" > /sys/class/net/eth0/queues/rx-0/rps_cpus 000000ff 启用了模拟之后,在我们的测试中,tps并没有预期的上升,而是下降了。

于是全部改了回去,si又降下来了,这个参数是实时生效的。

另外一篇讲解网卡优化较好的文章是https://www.mjmwired.net/kernel/Documentation/networking/scaling.txt。

网上较为合理的测试RFS/RPS的文章可以参考http://blog.csdn.net/yy405145590/article/details/9837839。

PS:阿里云ECS截至目前还不支持多队列网卡,同时也不支持一台ECS多张网卡,初步测试下来RPS的效果并没觉得有多好。阿里云那边反馈说可以考虑设置nox2apic boot选项看看,本地服务器测试了下,似乎没达到所说的软负载均衡的效果。

posted @ 2016-11-01 18:53  zhjh256  阅读(4523)  评论(0编辑  收藏  举报