網(wǎng)絡(luò)性能提升實(shí)戰(zhàn):單隊(duì)列vs多隊(duì)列性能實(shí)測對比

在某項(xiàng)目上線后,用戶訪問量激增,Kubernetes 集群承載的網(wǎng)絡(luò)壓力驟升。通過 Prometheus 監(jiān)控發(fā)現(xiàn),高峰期丟包嚴(yán)重;結(jié)合 top 命令觀察,部分 CPU 核心軟中斷SI占用率飆升至 100%,成為系統(tǒng)性能瓶頸。

本文通過單隊(duì)列與多隊(duì)列網(wǎng)卡配置對比,觀察丟包率、延遲和 CPU 利用率的差異,對比兩種模式下的性能差異。
一、實(shí)驗(yàn)準(zhǔn)備
1?? 主機(jī)角色與軟件環(huán)境
- 服務(wù)器端 IP:10.xx.16.103
- 客戶端 IP:10.xx.16.102
- 安裝工具:
yum install -y iperf3 # 壓測網(wǎng)絡(luò)吞吐量
yum install -y sysstat # CPU 性能監(jiān)控 (mpstat)2?? 網(wǎng)卡隊(duì)列模式
- 查看當(dāng)前網(wǎng)卡隊(duì)列數(shù)
ethtool -l enp1s0輸出示例:
Channel parameters for enp1s0:
Pre-set maximums:
RX: 0
TX: 0
Other: 0
Combined: 1
Current hardware settings:
RX: 0
TX: 0
Other: 0- 單隊(duì)列 → RX:1 / TX:1
- 多隊(duì)列 → RX/TX 可大于 1,如 4 或 8
二、單隊(duì)列壓測
1?? iperf3 測試帶寬
- UDP 模式,4 并發(fā)連接:
iperf3 -c 10.xx.16.103 -u -b 1G -P 4測試結(jié)果:
[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%) receiver2?? ping 測試丟包
[root@reg ~]# ping 10.xx.16.103
PING 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 ms
64 bytes from 10.xx.16.103: icmp_seq=5 ttl=64 time=17.7 ms
64 bytes from 10.xx.16.103: icmp_seq=6 ttl=64 time=14.7 ms
64 bytes from 10.xx.16.103: icmp_seq=7 ttl=64 time=12.4 ms
64 bytes from 10.xx.16.103: icmp_seq=8 ttl=64 time=16.1 ms
64 bytes from 10.xx.16.103: icmp_seq=12 ttl=64 time=16.6 ms
64 bytes from 10.217.16.103: icmp_seq=14 ttl=64 time=0.439 ms
64 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 16458ms
rtt min/avg/max/mdev = 0.276/6.674/17.705/7.558 ms- 丟包率 29%
- 延遲波動(dòng)大(最大達(dá)到 17ms)
3?? CPU 負(fù)載分析
[root@localhost ~]# mpstat -P ALL 1
.....
11時(shí)29分07秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
11時(shí)29分08秒 all 20.81 0.00 17.84 0.00 0.00 6.82 0.00 0.00 0.00 54.53
11時(shí)29分08秒 0 30.43 0.00 20.65 0.00 0.00 1.09 0.00 0.00 0.00 47.83
11時(shí)29分08秒 1 13.64 0.00 15.91 0.00 0.00 0.00 0.00 0.00 0.00 70.45
11時(shí)29分08秒 2 18.56 0.00 19.59 0.00 0.00 0.00 0.00 0.00 0.00 61.86
11時(shí)29分08秒 3 25.00 0.00 22.92 0.00 0.00 1.04 0.00 0.00 0.00 51.04
11時(shí)29分08秒 4 13.10 0.00 34.52 0.00 0.00 0.00 0.00 0.00 0.00 52.38
11時(shí)29分08秒 5 17.71 0.00 21.88 0.00 0.00 0.00 0.00 0.00 0.00 60.42
11時(shí)29分08秒 6 29.03 0.00 19.35 0.00 0.00 0.00 0.00 0.00 0.00 51.61
11時(shí)29分08秒 7 25.77 0.00 20.62 0.00 0.00 0.00 0.00 0.00 0.00 53.61
11時(shí)29分08秒 8 30.39 0.00 23.53 0.00 0.00 0.00 0.00 0.00 0.00 46.08
11時(shí)29分08秒 9 21.11 0.00 12.22 0.00 0.00 0.00 0.00 0.00 0.00 66.67
11時(shí)29分08秒 10 25.00 0.00 10.71 0.00 0.00 1.19 0.00 0.00 0.00 63.10
11時(shí)29分08秒 11 0.00 0.00 1.01 0.00 0.00 98.99 0.00 0.00 0.00 0.00
11時(shí)29分08秒 12 23.16 0.00 18.95 0.00 0.00 0.00 0.00 0.00 0.00 57.89
11時(shí)29分08秒 13 26.04 0.00 18.75 0.00 0.00 0.00 0.00 0.00 0.00 55.21
11時(shí)29分08秒 14 9.76 0.00 12.20 0.00 0.00 0.00 0.00 0.00 0.00 78.05
11時(shí)29分08秒 15 22.47 0.00 12.36 0.00 0.00 0.00 0.00 0.00 0.00 65.17- %soft(軟中斷)高達(dá) 98% 在單核(第11核)
- 說明網(wǎng)絡(luò)中斷處理高度集中,成為性能瓶頸
網(wǎng)卡隊(duì)列利用率(看是否有單個(gè)隊(duì)列打滿)
[root@localhost ~]# ethtool -i enp1s0
driver: virtio_net #檢查驅(qū)動(dòng)類型
version: 1.0.0
firmware-version:
expansion-rom-version:
bus-info: 0000:01:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
[root@localhost ~]# cat /proc/interrupts |grep -i virtio
288 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三、多隊(duì)列壓測
1?? 修改網(wǎng)卡隊(duì)列數(shù)(KVM 虛擬機(jī)示例)
- 首先修改網(wǎng)卡為多隊(duì)列
virsh console 10.xx.xx.103-host
....
<interface type='bridge'>
<mac address='52:54:00:2a:c4:41'/>
<source bridge='dq'/>
<model type='virtio'/>
<driver name='vhost' queues='8'/> #新增隊(duì)列為8,不要超過cpu核數(shù)
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' functinotallow='0x0'/>
</interface>- 驗(yàn)證:
Channel parameters for enp1s0:
Pre-set maximums:
RX: 0
TX: 0
Other: 0
Combined: 8
Current hardware settings:
RX: 0
TX: 0
Other: 0
Combined: 82?? 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 ms
64 bytes from 10.xx.16.103: icmp_seq=159 ttl=64 time=0.451 ms
64 bytes from 10.xx.16.103: icmp_seq=160 ttl=64 time=1.33 ms
64 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 165183ms
rtt min/avg/max/mdev = 0.295/1.329/42.263/3.980 ms- ping 測試也無丟包,延遲穩(wěn)定 <1.5ms
3?? CPU 負(fù)載分析
檢查cpu負(fù)載
[root@localhost ~]# mpstat -P ALL 1
......
12時(shí)04分31秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
12時(shí)04分32秒 all 55.94 0.00 17.79 0.00 0.00 22.54 0.00 0.00 0.00 3.73
12時(shí)04分32秒 0 46.67 0.00 33.33 0.00 0.00 0.00 0.00 0.00 0.00 20.00
12時(shí)04分32秒 1 68.04 0.00 24.74 0.00 0.00 7.22 0.00 0.00 0.00 0.00
12時(shí)04分32秒 2 65.66 0.00 19.19 0.00 0.00 5.05 0.00 0.00 0.00 10.10
12時(shí)04分32秒 3 85.86 0.00 12.12 0.00 0.00 1.01 0.00 0.00 0.00 1.01
12時(shí)04分32秒 4 18.00 0.00 3.00 0.00 0.00 79.00 0.00 0.00 0.00 0.00
12時(shí)04分32秒 5 73.74 0.00 25.25 0.00 0.00 0.00 0.00 0.00 0.00 1.01
12時(shí)04分32秒 6 74.49 0.00 19.39 0.00 0.00 6.12 0.00 0.00 0.00 0.00
12時(shí)04分32秒 7 64.89 0.00 26.60 0.00 0.00 2.13 0.00 0.00 0.00 6.38
12時(shí)04分32秒 8 50.51 0.00 37.37 0.00 0.00 7.07 0.00 0.00 0.00 5.05
12時(shí)04分32秒 9 87.76 0.00 12.24 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12時(shí)04分32秒 10 9.09 0.00 7.07 0.00 0.00 82.83 0.00 0.00 0.00 1.01
12時(shí)04分32秒 11 15.46 0.00 6.19 0.00 0.00 77.32 0.00 0.00 0.00 1.03
12時(shí)04分32秒 12 73.91 0.00 20.65 0.00 0.00 0.00 0.00 0.00 0.00 5.43
12時(shí)04分32秒 13 82.47 0.00 16.49 0.00 0.00 1.03 0.00 0.00 0.00 0.00
12時(shí)04分32秒 14 75.51 0.00 19.39 0.00 0.00 1.02 0.00 0.00 0.00 4.08
12時(shí)04分32秒 15 5.94 0.00 3.96 0.00 0.00 84.16 0.00 0.00 0.00 5.94- %soft 分布在多個(gè)核上
- 網(wǎng)絡(luò)中斷處理負(fù)載均衡,單核壓力顯著降低

四、性能瓶頸分析
項(xiàng)目 | 單隊(duì)列 | 多隊(duì)列 |
丟包率 | 高(≈30%) | 低(0%) |
ping 延遲 | 波動(dòng)大(最大 17ms) | 穩(wěn)定 <1.5ms |
CPU %soft | 單核 98% | 多核均衡分布 |
流量吞吐 | 約 235-242 Mbps | 可線性提升至接近網(wǎng)卡速率 |
結(jié)論:
1. 單隊(duì)列模式下,中斷處理集中在單核,導(dǎo)致軟中斷 CPU 飽和、丟包和延遲高。
2. 多隊(duì)列模式通過多核并行處理網(wǎng)絡(luò)流量,顯著提升吞吐量,降低延遲和丟包。
3. 高并發(fā)、高速網(wǎng)絡(luò)環(huán)境下,多隊(duì)列幾乎是網(wǎng)絡(luò)性能優(yōu)化的必備手段。
五、配置命令匯總
- 修改為單隊(duì)列:
ethtool -L eth0 rx 1 tx 1- 修改為多隊(duì)列(示例 4 個(gè)隊(duì)列):
ethtool -L eth0 rx 4 tx 4- 查看隊(duì)列數(shù):
ethtool -l eth0六、總結(jié)
- 單隊(duì)列:適合低速、低并發(fā)場景,CPU 負(fù)載集中,容易成為瓶頸。
- 多隊(duì)列:充分利用多核 CPU,提高吞吐量、降低延遲和丟包率,適用于高性能場景、虛擬化環(huán)境和大流量應(yīng)用。
- 實(shí)踐中,合理配置隊(duì)列數(shù)并結(jié)合 RSS/RPS/XPS 可以讓網(wǎng)絡(luò)性能發(fā)揮到極致。
?? 注意:隊(duì)列數(shù)不宜超過 CPU 核心數(shù),否則部分隊(duì)列空閑,資源浪費(fèi)。





























