开启网卡多队列功能

单个CPU处理网络中断存在瓶颈,您可以将DC2实例中的网络中断分散给不同的CPU处理。经测试,在网络PPS和网络带宽的测试中,与1个队列相比,2个队列最多可提升性能达50%到1倍,4个队列的性能提升更大。

配置网卡多队列

手动配置

本节先介绍如何手动配置网卡多队列,centos 7.3镜像为例,主网卡interface名称为eth0。
1、运行命令 ethtool -l eth0 查看主网卡支持多队列的情况。
Image.png

说明:如果两个 Combined 数值相同,则表示已开启支持多队列。

运行命令 ethtool -L eth0 combined 8 开启网卡的多队列功能。

开机自动配置

开机启动时开启网卡多队列,需要在rc.local里写入开机启动脚本, 这样可以使网卡启动网卡多队列。

1、添加脚本 /usr/bin/ddmultiqueue

#!/bin/bash
nicnames=$(ip link | grep -v 'lo: ' | grep '^[0-9]' | awk -F':' '{print $2}')
for nic in $nicnames; do
    queue=$(ethtool -l $nic | grep Combined: | awk '{print $2}' | head -1)
    if [ x"$queue" = x ]; then
         continue
    fi
    if [ $queue -gt 1 ];then
        ethtool -L $nic combined $queue
    fi
done

2、编辑/etc/rc.local ,在文件加入 /bin/sh /usr/bin/ddmultiqueue

/bin/sh /usr/bin/ddmultiqueue

3、如果是centos7系统操作系统,需要给/etc/rc.d/rc.local 添加可执行权限

chmod a+x /etc/rc.d/rc.local

shell if [ “x$" == “x” ]中x的作用(if [ x"$queue" = x ])

防止出现语法错误。如果不写x,只用 if [ “$" == “0” ]来判断$的值,当$为空或未设置时,语句被解释为 if [ == "0" ],出现语法错误。
加上x后,当$
为空或未设置时,解释为if [ “x" == "x" ] ,依然正确。if [ “x$" == “x” ]整句的意思是判断$是否为空。

使用命令查看是否产生了对应队列的中断

cat /proc/interrupts

 27:     183817          0   PCI-MSI 81921-edge      virtio0-input.0
 28:     218643          1   PCI-MSI 81922-edge      virtio0-output.0
 29:          1     198454   PCI-MSI 81923-edge      virtio0-input.1
 30:          0     189946   PCI-MSI 81924-edge      virtio0-output.1

网卡相关的实用命令

查看网卡型号
lspci | grep -i ethernet

查看网卡速率
ethtool eth0

查看网卡多队列
ethtool -l eth0

如果要修改网卡多队列的参数,可以使用
ethtool -L eth0 combined 2