我有一个应用程序在端口12201上接收大量UDP流量,我注意到一些UDP数据包永远不会进入应用程序(仅由内核接收).
我跑的时候
netstat -c --udp -an | grep 12201
我可以看到Recv-Q几乎总是126408,很少低于,从未超过:
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
udp 126408 0 :::12201 :::*
这是否意味着接收队列已满?编号126408来自哪里?我该如何增加它?
Sysctl配置:
# sysctl -a | grep mem
vm.overcommit_memory = 0
vm.nr_hugepages_mempolicy = 0
vm.lowmem_reserve_ratio = 256 256 32
vm.meminfo_legacy_layout = 1
vm.memory_failure_early_kill = 0
vm.memory_failure_recovery = 1
net.core.wmem_max = 124928
net.core.rmem_max = 33554432
net.core.wmem_default = 124928
net.core.rmem_default = 124928
net.core.optmem_max = 20480
net.ipv4.igmp_max_memberships = 20
net.ipv4.tcp_mem = 365760 487680 731520
net.ipv4.tcp_wmem = 4096 16384 4194304
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.udp_mem = 262144 327680 393216
net.ipv4.udp_rmem_min = 4096
net.ipv4.udp_wmem_min = 4096
解决方法:
看起来您的应用程序使用系统默认接收缓冲区,该缓冲区是通过sysctl定义的
net.core.rmem_default = 124928
因此,您可以看到Recv-Q的上限接近上方.尝试将应用程序中的SO_RCVBUF套接字选项更改为更高的值,可能达到最大限制.如sysctl设置net.core.rmem_max = 33554432中所定义
由于队列已满而丢弃的数据包计数,可以通过netstat -us查看(查找数据包接收错误)
标签:udp,linux
来源: https://codeday.me/bug/20190623/1273674.html