-->
当前位置:首页 > DayDayUp > 正文内容

openwrt 开启p2p下载后不定时断流

Luz2年前 (2022-11-10)DayDayUp3878

日志查看

查看日志,发现内核报错

  1. [82722.521673] net_ratelimit: 52 callbacks suppressed
  2. [82722.521686] TCP: too many orphaned sockets
  3. [82722.572764] TCP: too many orphaned sockets
  4. [82722.578580] TCP: too many orphaned sockets
  5. [82722.627996] TCP: too many orphaned sockets
  6. [82722.628003] TCP: too many orphaned sockets
  7. [82722.629368] TCP: too many orphaned sockets
  8. [82722.737297] TCP: too many orphaned sockets
  9. [82722.821365] TCP: too many orphaned sockets
  10. [82722.826418] TCP: too many orphaned sockets
  11. [82722.830779] TCP: too many orphaned sockets
  12. [82727.660978] net_ratelimit: 88 callbacks suppressed
  13. [82727.660990] TCP: too many orphaned sockets
  14. [82727.661166] TCP: too many orphaned sockets
  15. [82727.661299] TCP: too many orphaned sockets
  16. [82727.661877] TCP: too many orphaned sockets
  17. [82727.662378] TCP: too many orphaned sockets
  18. [82727.662926] TCP: too many orphaned sockets
  19. [82727.690757] TCP: too many orphaned sockets
  20. [82727.741138] TCP: too many orphaned sockets
  21. [82727.742036] TCP: too many orphaned sockets
  22. [82727.746508] TCP: too many orphaned sockets
  23. [82733.391249] net_ratelimit: 71 callbacks suppressed
  24. [82733.391260] TCP: too many orphaned sockets
  25. [82733.392081] TCP: too many orphaned sockets
  26. [82733.404570] TCP: too many orphaned sockets
  27. [82733.520939] TCP: too many orphaned sockets
  28. [82733.520944] TCP: too many orphaned sockets
  29. [82733.561052] TCP: too many orphaned sockets
  30. [82733.565318] TCP: too many orphaned sockets
  31. [82733.565517] TCP: too many orphaned sockets
  32. [82733.591031] TCP: too many orphaned sockets
  33. [82733.626538] TCP: too many orphaned sockets
  34. [82738.410793] net_ratelimit: 50 callbacks suppressed
  35. [82738.410805] TCP: too many orphaned sockets
  36. [82738.410886] TCP: too many orphaned sockets
  37. [82738.432898] TCP: too many orphaned sockets
  38. [82738.437242] TCP: too many orphaned sockets
  39. [82738.437851] TCP: too many orphaned sockets
  40. [82738.514986] TCP: too many orphaned sockets
  41. [82738.531098] TCP: too many orphaned sockets
  42. [82738.563451] TCP: too many orphaned sockets
  43. [82738.568405] TCP: too many orphaned sockets
  44. [82738.810959] TCP: too many orphaned sockets
  45. [82743.457123] net_ratelimit: 85 callbacks suppressed
  46. [82743.457136] TCP: too many orphaned sockets
  47. [82743.461618] TCP: too many orphaned sockets
  48. [82743.461661] TCP: too many orphaned sockets
  49. [82743.462961] TCP: too many orphaned sockets
  50. [82743.730626] TCP: too many orphaned sockets
  51. [82743.735824] TCP: too many orphaned sockets
  52. [82743.786934] TCP: too many orphaned sockets
  53. [82743.787056] TCP: too many orphaned sockets
  54. [82743.795363] TCP: too many orphaned sockets
  55. [82743.833571] TCP: too many orphaned sockets
  56. [82748.501001] net_ratelimit: 61 callbacks suppressed
  57. [82748.501012] TCP: too many orphaned sockets
  58. [82748.510258] TCP: too many orphaned sockets
  59. [82748.516021] TCP: too many orphaned sockets
  60. [82748.516030] TCP: too many orphaned sockets
  61. [82748.749464] TCP: too many orphaned sockets
  62. [82748.756431] TCP: too many orphaned sockets
  63. [82748.969228] TCP: too many orphaned sockets
  64. [82748.973687] TCP: too many orphaned sockets
  65. [82748.981033] TCP: too many orphaned sockets
  66. [82748.983183] TCP: too many orphaned sockets
  67. [82753.510116] net_ratelimit: 87 callbacks suppressed
  68. [82753.510129] TCP: too many orphaned sockets
  69. [82753.510634] TCP: too many orphaned sockets
  70. [82753.515943] TCP: too many orphaned sockets
  71. [82753.521337] TCP: too many orphaned sockets
  72. [82753.528290] TCP: too many orphaned sockets
  73. [82753.533948] TCP: too many orphaned sockets
  74. [82753.630058] TCP: too many orphaned sockets
  75. [82753.630064] TCP: too many orphaned sockets
  76. [82753.638469] TCP: too many orphaned sockets
  77. [82753.655716] TCP: too many orphaned sockets
  78. [82758.610666] net_ratelimit: 63 callbacks suppressed
  79. [82758.610682] TCP: too many orphaned sockets
  80. [82758.610704] TCP: too many orphaned sockets
  81. [82758.610712] TCP: too many orphaned sockets
  82. [82758.628093] TCP: too many orphaned sockets
  83. [82758.629826] TCP: too many orphaned sockets
  84. [82758.633840] TCP: too many orphaned sockets
  85. [82758.690563] TCP: too many orphaned sockets
  86. [82758.736475] TCP: too many orphaned sockets
  87. [82758.740353] TCP: too many orphaned sockets
  88. [82758.930691] TCP: too many orphaned sockets
  89. [82765.620008] net_ratelimit: 34 callbacks suppressed
  90. [82765.620022] TCP: too many orphaned sockets
  91. [82765.639635] TCP: too many orphaned sockets
  92. [82765.641787] TCP: too many orphaned sockets
  93. [82765.648547] TCP: too many orphaned sockets
  94. [82765.648552] TCP: too many orphaned sockets
  95. [82765.823903] TCP: too many orphaned sockets
  96. [82765.950389] TCP: too many orphaned sockets
  97. [82769.840376] TCP: too many orphaned sockets
  98. [82769.845240] TCP: too many orphaned sockets
  99. [82770.227278] TCP: too many orphaned sockets
  100. [82770.640331] net_ratelimit: 11 callbacks suppressed
  101. [82770.640344] TCP: too many orphaned sockets
  102. [82770.641484] TCP: too many orphaned sockets
  103. [82770.645247] TCP: too many orphaned sockets
  104. [82770.650358] TCP: too many orphaned sockets
  105. [82771.158001] TCP: too many orphaned sockets
  106. [82771.162039] TCP: too many orphaned sockets
  107. [82771.167442] TCP: too many orphaned sockets
  108. [82771.168473] TCP: too many orphaned sockets
  109. [82771.231748] TCP: too many orphaned sockets
  110. [82771.231787] TCP: too many orphaned sockets
  111. [82786.070035] net_ratelimit: 4 callbacks suppressed
  112. [82786.070047] TCP: too many orphaned sockets
  113. [82786.083469] TCP: too many orphaned sockets
  114. [82786.083473] TCP: too many orphaned sockets
  115. [82786.221163] TCP: too many orphaned sockets
  116. [82786.222039] TCP: too many orphaned sockets
  117. [82786.235116] TCP: too many orphaned sockets
  118. [82786.260067] TCP: too many orphaned sockets
  119. [82786.270141] TCP: too many orphaned sockets
  120. [82786.282189] TCP: too many orphaned sockets
  121. [82786.327654] TCP: too many orphaned sockets
  122. [83878.613866] nf_ct_snmp: dropping packet: parser failed
  123. [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 
  124. [85606.561639] nf_ct_snmp: dropping packet: parser failed
  125. [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 
  126. [87435.943390] nf_ct_snmp: dropping packet: parser failed
  127. [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 
  128. [89248.970344] nf_ct_snmp: dropping packet: parser failed
  129. [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读取缓冲区,单位为字节,查看默认值

  1. cat /proc/sys/net/ipv4/tcp_rmem
  2. 4096 131072 1952256

默认值为131072 byte = 128K,最小为4096 byte=4K,最大值为1906K。

image.png

第二个需要调整的是tcp_wmem,发送缓冲区,单位是字节,默认值

  1. cat /proc/sys/net/ipv4/tcp_wmem
  2. 4096    16384   1952256

image.png

第三个需要调整的tcp_mem,调整TCP的内存大小,其单位是页,1页等于4096字节。系统默认值:

  1. cat /proc/sys/net/ipv4/tcp_mem
  2. 2859    3813    5718

image.png

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最大页面值数量比较吻合,因此此值也需要修改。

  1. echo "net.ipv4.tcp_mem = 4096 40960 19522560">> /etc/sysctl.conf
  2. echo "net.ipv4.tcp_rmem = 4096 40960 19522560">> /etc/sysctl.conf
  3. echo "net.ipv4.tcp_wmem = 4096 4096 102400">> /etc/sysctl.conf
  4. 重启路由器后查看效果

image.png

重启路由器后观察效果

image.png

  1.             设备信息:           d-team_newifi-d2
  2.             内核版本:           5.4.203
  3.             可用内存:           358.2M  | 71.9% of 498.4M
  4.             可用存储:           3.0M    | 82.1% of 3.7M
  5.             性能得分:           5137
  6.             运行时间:           0  0 小时 4 分钟 12 
  7.             登录用户:           root    | 192.168.2.111:2757
  8.  
  9. root@NEWIFI3[d-team_newifi-d2]:~# cat /proc/sys/net/ipv4/tcp_rmem
  10. 4096    40960   19522560
  11. root@NEWIFI3[d-team_newifi-d2]:~# cat /proc/sys/net/ipv4/tcp_wmem
  12. 4096    4096    102400
  13. root@NEWIFI3[d-team_newifi-d2]:~# cat /proc/sys/net/ipv4/tcp_mem
  14. 4096    40960   19522560
  15. root@NEWIFI3[d-team_newifi-d2]:~#

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。