openwrt 开启p2p下载后不定时断流
日志查看
查看日志,发现内核报错
[82722.521673] net_ratelimit: 52 callbacks suppressed [82722.521686] TCP: too many orphaned sockets [82722.572764] TCP: too many orphaned sockets [82722.578580] TCP: too many orphaned sockets [82722.627996] TCP: too many orphaned sockets [82722.628003] TCP: too many orphaned sockets [82722.629368] TCP: too many orphaned sockets [82722.737297] TCP: too many orphaned sockets [82722.821365] TCP: too many orphaned sockets [82722.826418] TCP: too many orphaned sockets [82722.830779] TCP: too many orphaned sockets [82727.660978] net_ratelimit: 88 callbacks suppressed [82727.660990] TCP: too many orphaned sockets [82727.661166] TCP: too many orphaned sockets [82727.661299] TCP: too many orphaned sockets [82727.661877] TCP: too many orphaned sockets [82727.662378] TCP: too many orphaned sockets [82727.662926] TCP: too many orphaned sockets [82727.690757] TCP: too many orphaned sockets [82727.741138] TCP: too many orphaned sockets [82727.742036] TCP: too many orphaned sockets [82727.746508] TCP: too many orphaned sockets [82733.391249] net_ratelimit: 71 callbacks suppressed [82733.391260] TCP: too many orphaned sockets [82733.392081] TCP: too many orphaned sockets [82733.404570] TCP: too many orphaned sockets [82733.520939] TCP: too many orphaned sockets [82733.520944] TCP: too many orphaned sockets [82733.561052] TCP: too many orphaned sockets [82733.565318] TCP: too many orphaned sockets [82733.565517] TCP: too many orphaned sockets [82733.591031] TCP: too many orphaned sockets [82733.626538] TCP: too many orphaned sockets [82738.410793] net_ratelimit: 50 callbacks suppressed [82738.410805] TCP: too many orphaned sockets [82738.410886] TCP: too many orphaned sockets [82738.432898] TCP: too many orphaned sockets [82738.437242] TCP: too many orphaned sockets [82738.437851] TCP: too many orphaned sockets [82738.514986] TCP: too many orphaned sockets [82738.531098] TCP: too many orphaned sockets [82738.563451] TCP: too many orphaned sockets [82738.568405] TCP: too many orphaned sockets [82738.810959] TCP: too many orphaned sockets [82743.457123] net_ratelimit: 85 callbacks suppressed [82743.457136] TCP: too many orphaned sockets [82743.461618] TCP: too many orphaned sockets [82743.461661] TCP: too many orphaned sockets [82743.462961] TCP: too many orphaned sockets [82743.730626] TCP: too many orphaned sockets [82743.735824] TCP: too many orphaned sockets [82743.786934] TCP: too many orphaned sockets [82743.787056] TCP: too many orphaned sockets [82743.795363] TCP: too many orphaned sockets [82743.833571] TCP: too many orphaned sockets [82748.501001] net_ratelimit: 61 callbacks suppressed [82748.501012] TCP: too many orphaned sockets [82748.510258] TCP: too many orphaned sockets [82748.516021] TCP: too many orphaned sockets [82748.516030] TCP: too many orphaned sockets [82748.749464] TCP: too many orphaned sockets [82748.756431] TCP: too many orphaned sockets [82748.969228] TCP: too many orphaned sockets [82748.973687] TCP: too many orphaned sockets [82748.981033] TCP: too many orphaned sockets [82748.983183] TCP: too many orphaned sockets [82753.510116] net_ratelimit: 87 callbacks suppressed [82753.510129] TCP: too many orphaned sockets [82753.510634] TCP: too many orphaned sockets [82753.515943] TCP: too many orphaned sockets [82753.521337] TCP: too many orphaned sockets [82753.528290] TCP: too many orphaned sockets [82753.533948] TCP: too many orphaned sockets [82753.630058] TCP: too many orphaned sockets [82753.630064] TCP: too many orphaned sockets [82753.638469] TCP: too many orphaned sockets [82753.655716] TCP: too many orphaned sockets [82758.610666] net_ratelimit: 63 callbacks suppressed [82758.610682] TCP: too many orphaned sockets [82758.610704] TCP: too many orphaned sockets [82758.610712] TCP: too many orphaned sockets [82758.628093] TCP: too many orphaned sockets [82758.629826] TCP: too many orphaned sockets [82758.633840] TCP: too many orphaned sockets [82758.690563] TCP: too many orphaned sockets [82758.736475] TCP: too many orphaned sockets [82758.740353] TCP: too many orphaned sockets [82758.930691] TCP: too many orphaned sockets [82765.620008] net_ratelimit: 34 callbacks suppressed [82765.620022] TCP: too many orphaned sockets [82765.639635] TCP: too many orphaned sockets [82765.641787] TCP: too many orphaned sockets [82765.648547] TCP: too many orphaned sockets [82765.648552] TCP: too many orphaned sockets [82765.823903] TCP: too many orphaned sockets [82765.950389] TCP: too many orphaned sockets [82769.840376] TCP: too many orphaned sockets [82769.845240] TCP: too many orphaned sockets [82770.227278] TCP: too many orphaned sockets [82770.640331] net_ratelimit: 11 callbacks suppressed [82770.640344] TCP: too many orphaned sockets [82770.641484] TCP: too many orphaned sockets [82770.645247] TCP: too many orphaned sockets [82770.650358] TCP: too many orphaned sockets [82771.158001] TCP: too many orphaned sockets [82771.162039] TCP: too many orphaned sockets [82771.167442] TCP: too many orphaned sockets [82771.168473] TCP: too many orphaned sockets [82771.231748] TCP: too many orphaned sockets [82771.231787] TCP: too many orphaned sockets [82786.070035] net_ratelimit: 4 callbacks suppressed [82786.070047] TCP: too many orphaned sockets [82786.083469] TCP: too many orphaned sockets [82786.083473] TCP: too many orphaned sockets [82786.221163] TCP: too many orphaned sockets [82786.222039] TCP: too many orphaned sockets [82786.235116] TCP: too many orphaned sockets [82786.260067] TCP: too many orphaned sockets [82786.270141] TCP: too many orphaned sockets [82786.282189] TCP: too many orphaned sockets [82786.327654] TCP: too many orphaned sockets [83878.613866] nf_ct_snmp: dropping packet: parser failed [83878.613866] IN= OUT= PHYSIN=eth0.1 SRC=192.168.1.3 DST=94.190.129.70 LEN=126 TOS=0x00 PREC=0x00 TTL=127 ID=59452 PROTO=UDP SPT=17491 DPT=161 LEN=106 [85606.561639] nf_ct_snmp: dropping packet: parser failed [85606.561639] IN= OUT= PHYSIN=eth0.1 SRC=192.168.1.3 DST=94.190.129.70 LEN=126 TOS=0x00 PREC=0x00 TTL=127 ID=26161 PROTO=UDP SPT=17491 DPT=161 LEN=106 [87435.943390] nf_ct_snmp: dropping packet: parser failed [87435.943390] IN= OUT= PHYSIN=eth0.1 SRC=192.168.1.3 DST=94.190.129.70 LEN=126 TOS=0x00 PREC=0x00 TTL=127 ID=43511 PROTO=UDP SPT=17491 DPT=161 LEN=106 [89248.970344] nf_ct_snmp: dropping packet: parser failed [89248.970344] IN= OUT= PHYSIN=eth0.1 SRC=192.168.1.3 DST=94.190.129.70 LEN=126 TOS=0x00 PREC=0x00 TTL=127 ID=2675 PROTO=UDP SPT=17491 DPT=161 LEN=106
解决方法
tcp_mem
在服务端,连接达到一定数量,诸如50W时,有些隐藏很深的问题,就不断的抛出来。 通过查看dmesg命令查看,发现大量TCP: too many of orphaned sockets错误,也很正常,下面到了需要调整tcp socket参数的时候了。
第一个需要调整的是tcp_rmem,即TCP读取缓冲区,单位为字节,查看默认值
cat /proc/sys/net/ipv4/tcp_rmem 4096 131072 1952256
默认值为131072 byte = 128K,最小为4096 byte=4K,最大值为1906K。
第二个需要调整的是tcp_wmem,发送缓冲区,单位是字节,默认值
cat /proc/sys/net/ipv4/tcp_wmem 4096 16384 1952256
第三个需要调整的tcp_mem,调整TCP的内存大小,其单位是页,1页等于4096字节。系统默认值:
cat /proc/sys/net/ipv4/tcp_mem 2859 3813 5718
tcp_mem(3个INTEGER变量):low, pressure, high
low:当TCP使用了低于该值的内存页面数时,TCP不会考虑释放内存。
pressure:当TCP使用了超过该值的内存页面数量时,TCP试图稳定其内存使用,进入pressure模式,当内存消耗低于low值时则退出pressure状态。
high:允许所有tcp sockets用于排队缓冲数据报的页面量,当内存占用超过此值,系统拒绝分配socket,后台日志输出“TCP: too many of orphaned sockets”。
一般情况下这些值是在系统启动时根据系统内存数量计算得到的。 根据当前tcp_mem最大内存页面数是1864896,当内存为(1864896*4)/1024K=7284.75M时,系统将无法为新的socket连接分配内存,即TCP连接将被拒绝。
实际测试环境中,据观察大概在99万个连接左右的时候(零头不算),进程被杀死,触发out of socket memory错误(dmesg命令查看获得)。每一个连接大致占用7.5K内存(下面给出计算方式),大致可算的此时内存占用情况(990000 * 7.5 / 1024K = 7251M)。
这样和tcp_mem最大页面值数量比较吻合,因此此值也需要修改。
echo "net.ipv4.tcp_mem = 4096 40960 19522560">> /etc/sysctl.conf echo "net.ipv4.tcp_rmem = 4096 40960 19522560">> /etc/sysctl.conf echo "net.ipv4.tcp_wmem = 4096 4096 102400">> /etc/sysctl.conf 重启路由器后查看效果
重启路由器后观察效果
设备信息: d-team_newifi-d2 内核版本: 5.4.203 可用内存: 358.2M | 71.9% of 498.4M 可用存储: 3.0M | 82.1% of 3.7M 性能得分: 5137 运行时间: 0 天 0 小时 4 分钟 12 秒 登录用户: root | 192.168.2.111:2757 root@NEWIFI3[d-team_newifi-d2]:~# cat /proc/sys/net/ipv4/tcp_rmem 4096 40960 19522560 root@NEWIFI3[d-team_newifi-d2]:~# cat /proc/sys/net/ipv4/tcp_wmem 4096 4096 102400 root@NEWIFI3[d-team_newifi-d2]:~# cat /proc/sys/net/ipv4/tcp_mem 4096 40960 19522560 root@NEWIFI3[d-team_newifi-d2]:~#