oct*_*tal 6 kernel networking tcp-ip
我正在玩 Ubuntu 18.04,我注意到 TCP 性能回归阻止我升级当前正在运行的服务器,因为它们对延迟非常敏感。
对于我的特定用例,我实现了一个简单的 TCP 测试程序,该程序作为服务器运行,在向所有客户端发送一批消息之前等待连接一定数量的客户端。然后我测量所花费的时间SENDMSG()固定大小的缓冲器,以N个客户端。
代码示例
我在位于同一数据中心的两台不同的机器上运行服务器和客户端。
结果
Ubuntu 16.04
版本
srv01:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial
srv01:~$ uname -ra
Linux srv01 4.4.0-97-generic #120-Ubuntu SMP Tue Sep 19 17:28:18 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
系统控制
net.core.netdev_max_backlog = 3000
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_moderate_rcvbuf = 0
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_rmem = 131072 1048576 16777216
net.ipv4.tcp_wmem = 131072 1048576 16777216
Run Code Online (Sandbox Code Playgroud)
跑
srv01:~$ taskset -c 15,17,19 ./iouring --port 4040 --clients-count 3 --buffer-size 128 --batch-size 100 --sleep-ms 1 --total-messages 500000 --sockopt n
Send latency report
Min: 679ns
Mean: 1048ns
Max: 13949ns
p(0.100000) = 726ns
p(0.200000) = 734ns
p(0.500000) = 750ns
p(0.800000) = 859ns
p(0.900000) = 1338ns
p(0.990000) = 5024ns
Run Code Online (Sandbox Code Playgroud)
Ubuntu 18.04
版本
srv02:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Release: 18.04
Codename: bionic
srv02:~$ uname -ra
Linux srv02 4.20.17-042017-generic #201903190933 SMP Tue Mar 19 13:36:11 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
系统控制
net.core.netdev_max_backlog = 3000
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_moderate_rcvbuf = 0
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_rmem = 131072 1048576 16777216
net.ipv4.tcp_wmem = 131072 1048576 16777216
Run Code Online (Sandbox Code Playgroud)
跑
srv02:~$ taskset -c 15,17,19 ./iouring --port 4040 --clients-count 3 --buffer-size 128 --batch-size 100 --sleep-ms 1 --total-messages 500000 --sockopt n
Send latency report
Min: 819ns
Mean: 4660ns
Max: 25061ns
p(0.100000) = 1379ns
p(0.200000) = 2660ns
p(0.500000) = 4871ns
p(0.800000) = 6559ns
p(0.900000) = 7416ns
p(0.990000) = 9444ns
Run Code Online (Sandbox Code Playgroud)
如您所见,使用内核 4.20 的Ubuntu 18.04 的性能显着下降(我在内核 4.15 和 4.18 上观察到完全相同)。我正在使用完全相同的机器(相同的硬件)。
不知何故,它看起来与TCP_NODELAY是否启用有关。禁用TCP_NODELAY(无--sockopt)时,我第 50 次获得1005ns(Ubuntu 18.04)。
srv02:~$ taskset -c 15,17,19 ./iouring --port 4040 --clients-count 3 --buffer-size 128 --batch-size 100 --sleep-ms 1 --total-messages 500000
Send latency report
Min: 817ns
Mean: 1790ns
Max: 15374ns
p(0.100000) = 955ns
p(0.200000) = 964ns
p(0.500000) = 1006ns
p(0.800000) = 1601ns
p(0.900000) = 4475ns
p(0.990000) = 9516ns
Run Code Online (Sandbox Code Playgroud)
在RHEL8上的相同测试,内核4.18没有显示有或没有TCP_NODELAY(950ns 50th)的任何性能差异。
知道是什么原因造成的吗?如果需要,我可以提供更多详细信息。
谢谢
看来您的 16.04 内核没有针对 spectre/meltdown 进行修补。
据我了解,内核 4.4.0-109 包含部分补丁,您运行的是 4.4.0-97,它没有减轻任何解决旁路攻击的操作,从而提供更好的性能。
在 SMP 生产系统上运行这些是否明智 - 完全不同的问题......