为什么 Wifi 无线网卡 Ping 延迟会周期变化

我有一台 NUC 设备,之前一直通过 Wifi 对外暴露

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
root:~/ # cat /etc/netplan/00-installer-config.yaml                     
# This is the network config written by 'subiquity'
network:
ethernets:
eno1:
dhcp4: no
optional: true
gateway4: 192.168.2.1
nameservers:
addresses: [223.5.5.5]
addresses: [192.168.2.52/24]
version: 2
wifis:
wlp0s20f3:
optional: true
access-points:
"******":
password: "************"
dhcp4: no
addresses: [192.168.2.53/24]
gateway4: 192.168.2.1
nameservers:
addresses: [223.5.5.5]

但在某一天发现我在内网中 ping 192.168.2.53 时,发现延迟出现了规律性的变化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
➜  ~ ping 192.168.2.53
PING 192.168.2.53 (192.168.2.53) 56(84) bytes of data.
64 bytes from 192.168.2.53: icmp_seq=1 ttl=63 time=55.6 ms
64 bytes from 192.168.2.53: icmp_seq=2 ttl=63 time=78.0 ms
64 bytes from 192.168.2.53: icmp_seq=3 ttl=63 time=101 ms
64 bytes from 192.168.2.53: icmp_seq=4 ttl=63 time=20.8 ms
64 bytes from 192.168.2.53: icmp_seq=5 ttl=63 time=47.6 ms
64 bytes from 192.168.2.53: icmp_seq=6 ttl=63 time=66.7 ms
64 bytes from 192.168.2.53: icmp_seq=7 ttl=63 time=88.2 ms
64 bytes from 192.168.2.53: icmp_seq=8 ttl=63 time=111 ms
64 bytes from 192.168.2.53: icmp_seq=9 ttl=63 time=31.3 ms
64 bytes from 192.168.2.53: icmp_seq=10 ttl=63 time=59.2 ms
64 bytes from 192.168.2.53: icmp_seq=11 ttl=63 time=77.1 ms
64 bytes from 192.168.2.53: icmp_seq=12 ttl=63 time=100 ms
64 bytes from 192.168.2.53: icmp_seq=13 ttl=63 time=19.9 ms
64 bytes from 192.168.2.53: icmp_seq=14 ttl=63 time=43.5 ms
64 bytes from 192.168.2.53: icmp_seq=15 ttl=63 time=65.3 ms
64 bytes from 192.168.2.53: icmp_seq=16 ttl=63 time=88.5 ms
^C
--- 192.168.2.53 ping statistics ---
16 packets transmitted, 16 received, 0% packet loss, time 15022ms
rtt min/avg/max/mdev = 19.894/65.852/111.087/27.441 ms

一直没搞清楚为什么会这样,最近偶然发现是 Wifi 网卡节能模式(Power Save Mode)的原因
手动关闭网卡的节能模式

1
iw dev wlp0s20f3 set power_save off

再次尝试 ping

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
➜  ~ ping 192.168.2.53
PING 192.168.2.53 (192.168.2.53) 56(84) bytes of data.
64 bytes from 192.168.2.53: icmp_seq=1 ttl=63 time=4.33 ms
64 bytes from 192.168.2.53: icmp_seq=2 ttl=63 time=4.13 ms
64 bytes from 192.168.2.53: icmp_seq=3 ttl=63 time=4.86 ms
64 bytes from 192.168.2.53: icmp_seq=4 ttl=63 time=3.85 ms
64 bytes from 192.168.2.53: icmp_seq=5 ttl=63 time=4.35 ms
64 bytes from 192.168.2.53: icmp_seq=6 ttl=63 time=3.90 ms
64 bytes from 192.168.2.53: icmp_seq=7 ttl=63 time=3.74 ms
64 bytes from 192.168.2.53: icmp_seq=8 ttl=63 time=4.69 ms
64 bytes from 192.168.2.53: icmp_seq=9 ttl=63 time=4.11 ms
^C
--- 192.168.2.53 ping statistics ---
9 packets transmitted, 9 received, 0% packet loss, time 8013ms
rtt min/avg/max/mdev = 3.738/4.217/4.857/0.356 ms

稳定且延迟大大降低😀