{"id":121,"date":"2026-01-22T07:59:28","date_gmt":"2026-01-22T07:59:28","guid":{"rendered":"https:\/\/blog.gpst.net.cn:4008\/?p=121"},"modified":"2026-01-28T06:24:16","modified_gmt":"2026-01-28T06:24:16","slug":"%e8%87%aa%e5%8a%a8%e4%bc%98%e5%8c%96%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%bd%91%e5%8d%a1%e7%9a%84%e6%94%b6%e5%8f%91%e9%98%9f%e5%88%97%ef%bc%88ring-buffer%ef%bc%89%e9%85%8d%e7%bd%ae%e7%9a%84bash-shell","status":"publish","type":"post","link":"https:\/\/opshub.com.cn\/?p=121","title":{"rendered":"\u81ea\u52a8\u4f18\u5316\u670d\u52a1\u5668\u7f51\u5361\u7684\u6536\u53d1\u961f\u5217\uff08Ring Buffer\uff09\u914d\u7f6e\u7684bash shell\u811a\u672c"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">\u6838\u5fc3\u80cc\u666f\uff1a\u4e3a\u4ec0\u4e48\u8981\u8c03\u6574 Ring Buffer\uff1f<\/h3>\n\n\n\n<p>\u7f51\u5361\u7684 RX\/TX \u73af\u5f62\u961f\u5217\uff08Ring Buffer\uff09\u662f\u7f51\u5361\u786c\u4ef6\u7f13\u5b58\uff0c\u4f5c\u7528\u662f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>RX \u961f\u5217<\/strong>\uff1a\u7f51\u5361\u63a5\u6536\u5230\u6570\u636e\u5305\u540e\uff0c\u5148\u5b58\u5165 RX \u961f\u5217\uff0c\u518d\u7531\u5185\u6838\u8bfb\u53d6\u5904\u7406\uff1b<\/li>\n\n\n\n<li><strong>TX \u961f\u5217<\/strong>\uff1a\u5185\u6838\u8981\u53d1\u9001\u7684\u6570\u636e\u5305\uff0c\u5148\u5b58\u5165 TX \u961f\u5217\uff0c\u518d\u7531\u7f51\u5361\u53d1\u9001\u51fa\u53bb\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5982\u679c\u961f\u5217\u5927\u5c0f\u8fc7\u5c0f\uff0c\u9ad8\u6d41\u91cf\u573a\u666f\u4e0b\u4f1a\u51fa\u73b0\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>netstat -s | grep -i drop<\/code> \u663e\u793a \u201crx\/tx packets dropped\u201d\uff08\u5305\u4e22\u5931\uff09\uff1b<\/li>\n\n\n\n<li>\u7f51\u7edc\u5ef6\u8fdf\u589e\u52a0\u3001\u5e94\u7528\u5361\u987f\uff08\u5982\u6570\u636e\u5e93 \/ WEB \u670d\u52a1\u8d85\u65f6\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5c06\u961f\u5217\u8bbe\u4e3a\u786c\u4ef6\u6700\u5927\u503c\uff0c\u53ef\u6700\u5927\u5316\u5229\u7528\u7f51\u5361\u7f13\u5b58\uff0c\u51cf\u5c11\u4e22\u5305\uff0c\u63d0\u5347\u7f51\u7edc\u541e\u5410\u3002<\/p>\n\n\n\n<p>\u811a\u672c\u7684\u6838\u5fc3\u76ee\u6807\u662f<strong>\u904d\u5386\u6240\u6709\u6709\u6570\u636e\u6536\u53d1\u7684\u7f51\u5361\uff0c\u5c06\u5176 RX\/TX \u73af\u5f62\u961f\u5217\u5927\u5c0f\u6062\u590d\u4e3a\u786c\u4ef6\u9ed8\u8ba4\u6700\u5927\u503c<\/strong>\uff0c\u662f\u63d0\u5347\u7f51\u5361\u7f51\u7edc\u541e\u5410\u3001\u51cf\u5c11\u4e22\u5305\u7684\u5e38\u7528\u4f18\u5316\u624b\u6bb5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u6b65\u9aa41\uff1a\u7b5b\u9009\u6709\u6570\u636e\u6536\u53d1\u7684\u7f51\u5361\u540d\u79f0\ncat \/proc\/net\/dev | egrep \".+:\" | awk '{if($5&gt;0 || $13&gt;0){print $0}}' | egrep -o \".+:\" | sed 's\/\\(\\ \\|:\\)\/\/g;\/^$\/d' | while read _netdev_\ndo\n    # \u6b65\u9aa42\uff1a\u5b9a\u4e49\u961f\u5217\u7c7b\u578b\uff08rx=\u63a5\u6536\uff0ctx=\u53d1\u9001\uff09\n    _Xxs_=(rx tx)\n    \n    # \u6b65\u9aa43\uff1a\u8bfb\u53d6\u7f51\u5361RX\/TX\u961f\u5217\u7684\u786c\u4ef6\u6700\u5927\u503c\n    _Mxs_=($(ethtool -g $_netdev_ 2&gt;\/dev\/null | egrep \"(RX|TX):\" | head -n 2 | awk -F':' '{printf\"%d \",$2}'))\n    \n    # \u6b65\u9aa44\uff1a\u904d\u5386RX\/TX\uff0c\u5c06\u961f\u5217\u5927\u5c0f\u8bbe\u4e3a\u786c\u4ef6\u6700\u5927\u503c\n    for ((i=0;i&lt;${#_Xxs_&#091;@]};i++))\n    do\n        ethtool -G $_netdev_ ${_Xxs_&#091;$i]} ${_Mxs_&#091;$i]} 2&gt;\/dev\/null\n    done        \ndone<\/code><\/pre>\n\n\n\n<p>\u6027\u80fd\u8c03\u4f18\u8865\u5145\uff1a<\/p>\n\n\n\n<p>\u7f16\u8f91 \/etc\/sysctl.conf <\/p>\n\n\n\n<p>echo &#8220;net.core.rx_max_qlen = 4096&#8221; &gt;&gt; \/etc\/sysctl.conf <\/p>\n\n\n\n<p>echo &#8220;net.core.netdev_max_backlog = 16384&#8221; &gt;&gt; \/etc\/sysctl.conf <\/p>\n\n\n\n<p>echo &#8220;net.core.rmem_max = 16777216&#8221; &gt;&gt; \/etc\/sysctl.conf <\/p>\n\n\n\n<p>echo &#8220;net.core.wmem_max = 16777216&#8221; &gt;&gt; \/etc\/sysctl.conf <\/p>\n\n\n\n<p>\u751f\u6548\u914d\u7f6e <\/p>\n\n\n\n<p>sysctl -p<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6838\u5fc3\u80cc\u666f\uff1a\u4e3a\u4ec0\u4e48\u8981\u8c03\u6574 Ring Buffer\uff1f \u7f51\u5361\u7684 RX\/TX \u73af\u5f62\u961f\u5217\uff08Ring Buffer\uff09\u662f\u7f51\u5361\u786c\u4ef6\u7f13\u5b58\uff0c\u4f5c\u7528\u662f\uff1a \u5982\u679c\u961f\u5217\u5927\u5c0f\u8fc7\u5c0f\uff0c\u9ad8\u6d41\u91cf\u573a\u666f\u4e0b\u4f1a\u51fa\u73b0\uff1a \u5c06\u961f\u5217\u8bbe\u4e3a\u786c\u4ef6\u6700\u5927\u503c\uff0c\u53ef\u6700\u5927\u5316\u5229\u7528\u7f51\u5361\u7f13\u5b58\uff0c\u51cf\u5c11\u4e22\u5305\uff0c\u63d0\u5347\u7f51\u7edc\u541e\u5410\u3002 \u811a\u672c\u7684\u6838\u5fc3\u76ee\u6807\u662f\u904d\u5386\u6240\u6709\u6709\u6570\u636e\u6536\u53d1\u7684\u7f51\u5361\uff0c\u5c06\u5176 RX\/TX \u73af\u5f62\u961f\u5217\u5927\u5c0f\u6062\u590d\u4e3a\u786c\u4ef6\u9ed8\u8ba4\u6700\u5927\u503c\uff0c\u662f\u63d0\u5347\u7f51\u5361\u7f51\u7edc\u541e\u5410\u3001\u51cf\u5c11\u4e22\u5305\u7684\u5e38\u7528\u4f18\u5316\u624b\u6bb5 \u6027\u80fd\u8c03\u4f18\u8865\u5145\uff1a \u7f16\u8f91 \/etc\/sysctl.conf echo &#8220;net.core.rx_max_qlen = 4096&#8221; &gt;&gt; \/etc\/sysctl.conf echo &#8220;net.core.netdev_max_backlog = 16384&#8221; &gt;&gt; \/etc\/sysctl.conf echo &#8220;net.core.rmem_max = 16777216&#8221; &gt;&gt; \/etc\/sysctl.conf echo &#8220;net.core.wmem_max = 16777216&#8221; &gt;&gt; \/etc\/sysctl.conf \u751f\u6548\u914d\u7f6e sysctl -p<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-121","post","type-post","status-publish","format-standard","hentry","category-9"],"_links":{"self":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=121"}],"version-history":[{"count":2,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/121\/revisions"}],"predecessor-version":[{"id":674,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/121\/revisions\/674"}],"wp:attachment":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}