本文通过单队列与多队列网卡配置对比,观察丢包率、延迟和 CPU 利用率的差异,对比两种模式下的性能差异。

在某项目上线后,用户访问量激增,Kubernetes 集群承载的网络压力骤升。通过 Prometheus 监控发现,高峰期丢包严重;结合top命令观察,部分 CPU 核心软中断SI占用率飙升至 100%,成为系统性能瓶颈。

本文通过单队列与多队列网卡配置对比,观察丢包率、延迟和 CPU 利用率的差异,对比两种模式下的性能差异。
一、实验准备
1️⃣ 主机角色与软件环境
服务器端 IP:10.xx.16.103客户端 IP:10.xx.16.102安装工具:yum install -y iperf3 # 压测网络吞吐量yum install -y sysstat # CPU 性能监控 (mpstat)
2️⃣ 网卡队列模式
查看当前网卡队列数ethtool -l enp1s0
输出示例:
Channel parameters for enp1s0:Pre-set maximums:RX: 0TX: 0Other: 0Combined: 1Current hardware settings:RX: 0TX: 0Other: 0单队列→ RX:1 / TX:1多队列→ RX/TX 可大于 1,如 4 或 8
二、单队列压测
1️⃣ iperf3 测试带宽
UDP 模式,4 并发连接:iperf3 -c 10.xx.16.103 -u -b 1G -P 4
测试结果:
[root@reg ~]#iperf3 -c 10.xx.16.103 -u -b 1G -P 4- - - - - - - - - - - - - - - - - - - - - - - - -[SUM] 0.00-10.00 sec 1.71 GBytes 1.47 Gbits/sec 0.000 ms 0/1267733 (0%) sender[SUM] 0.00-10.22 sec 1.13 GBytes 952 Mbits/sec 0.067 ms 427544/1267651 (34%) receiver
2️⃣ ping 测试丢包
[root@reg ~]# ping 10.xx.16.103PING 10.xx.16.103 (10.xx.16.103) 56(84) bytes of data.64 bytes from 10.xx.16.103: icmp_seq=3 ttl=64 time=0.276 ms64 bytes from 10.xx.16.103: icmp_seq=5 ttl=64 time=17.7 ms64 bytes from 10.xx.16.103: icmp_seq=6 ttl=64 time=14.7 ms64 bytes from 10.xx.16.103: icmp_seq=7 ttl=64 time=12.4 ms64 bytes from 10.xx.16.103: icmp_seq=8 ttl=64 time=16.1 ms64 bytes from 10.xx.16.103: icmp_seq=12 ttl=64 time=16.6 ms64 bytes from 10.217.16.103: icmp_seq=14 ttl=64 time=0.439 ms64 bytes from 10.xx.16.103: icmp_seq=15 ttl=64 time=0.398 ms--- 10.xx.16.103 ping statistics ---17 packets transmitted, 12 received, 29.4118% packet loss, time 16458msrtt min/avg/max/mdev = 0.276/6.674/17.705/7.558 ms丢包率 29%延迟波动大(最大达到 17ms)
3️⃣ CPU 负载分析
[root@localhost ~]# mpstat -P ALL 1.....11时29分07秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle11时29分08秒 all 20.81 0.00 17.84 0.00 0.00 6.82 0.00 0.00 0.00 54.5311时29分08秒 0 30.43 0.00 20.65 0.00 0.00 1.09 0.00 0.00 0.00 47.8311时29分08秒 1 13.64 0.00 15.91 0.00 0.00 0.00 0.00 0.00 0.00 70.4511时29分08秒 2 18.56 0.00 19.59 0.00 0.00 0.00 0.00 0.00 0.00 61.8611时29分08秒 3 25.00 0.00 22.92 0.00 0.00 1.04 0.00 0.00 0.00 51.0411时29分08秒 4 13.10 0.00 34.52 0.00 0.00 0.00 0.00 0.00 0.00 52.3811时29分08秒 5 17.71 0.00 21.88 0.00 0.00 0.00 0.00 0.00 0.00 60.4211时29分08秒 6 29.03 0.00 19.35 0.00 0.00 0.00 0.00 0.00 0.00 51.6111时29分08秒 7 25.77 0.00 20.62 0.00 0.00 0.00 0.00 0.00 0.00 53.6111时29分08秒 8 30.39 0.00 23.53 0.00 0.00 0.00 0.00 0.00 0.00 46.0811时29分08秒 9 21.11 0.00 12.22 0.00 0.00 0.00 0.00 0.00 0.00 66.6711时29分08秒 10 25.00 0.00 10.71 0.00 0.00 1.19 0.00 0.00 0.00 63.1011时29分08秒 11 0.00 0.00 1.01 0.00 0.00 98.99 0.00 0.00 0.00 0.0011时29分08秒 12 23.16 0.00 18.95 0.00 0.00 0.00 0.00 0.00 0.00 57.8911时29分08秒 13 26.04 0.00 18.75 0.00 0.00 0.00 0.00 0.00 0.00 55.2111时29分08秒 14 9.76 0.00 12.20 0.00 0.00 0.00 0.00 0.00 0.00 78.0511时29分08秒 15 22.47 0.00 12.36 0.00 0.00 0.00 0.00 0.00 0.00 65.17%soft(软中断)高达 98% 在单核(第11核)说明网络中断处理高度集中,成为性能瓶颈
网卡队列利用率(看是否有单个队列打满)
[root@localhost ~]# ethtool -i enp1s0driver: virtio_net #检查驱动类型version: 1.0.0firmware-version: expansion-rom-version: bus-info: 0000:01:00.0supports-statistics: yessupports-test: nosupports-eeprom-access: nosupports-register-dump: nosupports-priv-flags: no[root@localhost ~]# cat /proc/interrupts |grep -i virtio288 Edge virtio0-config 69: 0 0 0 0 0 0 0 23 0 0 0 3367977005 0 0 0 0 ITS-MSI 524289 Edge virtio0-input.0 70: 0 0 0 0 0 0 0 0 1 185898 0 0 0 0 0 0 ITS-MSI 524
三、多队列压测
1️⃣ 修改网卡队列数(KVM 虚拟机示例)
首先修改网卡为多队列virsh console 10.xx.xx.103-host....验证:
Channel parameters for enp1s0:Pre-set maximums:RX: 0TX: 0Other: 0Combined: 8Current hardware settings:RX: 0TX: 0Other: 0Combined: 8
2️⃣ iperf3 与 ping 测试
UDP 模式压测:iperf3 -c 10.xx.16.103 -u -b 1G -P 4丢包率降为0%
64 bytes from 10.xx.16.103: icmp_seq=158 ttl=64 time=0.368 ms64 bytes from 10.xx.16.103: icmp_seq=159 ttl=64 time=0.451 ms64 bytes from 10.xx.16.103: icmp_seq=160 ttl=64 time=1.33 ms64 bytes from 10.xx.16.103: icmp_seq=161 ttl=64 time=0.428 ms--- 10.xx.16.103 ping statistics ---161 packets transmitted, 161 received, 0% packet loss, time 165183msrtt min/avg/max/mdev = 0.295/1.329/42.263/3.980 msping 测试也无丢包,延迟稳定 <1.5ms
3️⃣ CPU 负载分析
检查cpu负载
[root@localhost ~]# mpstat -P ALL 1......12时04分31秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle12时04分32秒 all 55.94 0.00 17.79 0.00 0.00 22.54 0.00 0.00 0.00 3.7312时04分32秒 0 46.67 0.00 33.33 0.00 0.00 0.00 0.00 0.00 0.00 20.0012时04分32秒 1 68.04 0.00 24.74 0.00 0.00 7.22 0.00 0.00 0.00 0.0012时04分32秒 2 65.66 0.00 19.19 0.00 0.00 5.05 0.00 0.00 0.00 10.1012时04分32秒 3 85.86 0.00 12.12 0.00 0.00 1.01 0.00 0.00 0.00 1.0112时04分32秒 4 18.00 0.00 3.00 0.00 0.00 79.00 0.00 0.00 0.00 0.0012时04分32秒 5 73.74 0.00 25.25 0.00 0.00 0.00 0.00 0.00 0.00 1.0112时04分32秒 6 74.49 0.00 19.39 0.00 0.00 6.12 0.00 0.00 0.00 0.0012时04分32秒 7 64.89 0.00 26.60 0.00 0.00 2.13 0.00 0.00 0.00 6.3812时04分32秒 8 50.51 0.00 37.37 0.00 0.00 7.07 0.00 0.00 0.00 5.0512时04分32秒 9 87.76 0.00 12.24 0.00 0.00 0.00 0.00 0.00 0.00 0.0012时04分32秒 10 9.09 0.00 7.07 0.00 0.00 82.83 0.00 0.00 0.00 1.0112时04分32秒 11 15.46 0.00 6.19 0.00 0.00 77.32 0.00 0.00 0.00 1.0312时04分32秒 12 73.91 0.00 20.65 0.00 0.00 0.00 0.00 0.00 0.00 5.4312时04分32秒 13 82.47 0.00 16.49 0.00 0.00 1.03 0.00 0.00 0.00 0.0012时04分32秒 14 75.51 0.00 19.39 0.00 0.00 1.02 0.00 0.00 0.00 4.0812时04分32秒 15 5.94 0.00 3.96 0.00 0.00 84.16 0.00 0.00 0.00 5.94%soft 分布在多个核上网络中断处理负载均衡,单核压力显著降低

四、性能瓶颈分析
结论:
1. 单队列模式下,中断处理集中在单核,导致软中断 CPU 饱和、丢包和延迟高。
2. 多队列模式通过多核并行处理网络流量,显著提升吞吐量,降低延迟和丢包。
3. 高并发、高速网络环境下,多队列几乎是网络性能优化的必备手段。
五、配置命令汇总
修改为单队列:ethtool -L eth0 rx 1 tx 1修改为多队列(示例 4 个队列):
ethtool -L eth0 rx 4 tx 4查看队列数:
ethtool -l eth0
