{"id":49944,"date":"2024-10-08T08:48:14","date_gmt":"2024-10-08T00:48:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/49944\/"},"modified":"2024-10-08T08:48:14","modified_gmt":"2024-10-08T00:48:14","slug":"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%84%aa%e5%8c%96-tcp-nodelay-%e5%92%8c-tcp-nopush-%e8%a8%ad%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/49944\/","title":{"rendered":"Nginx \u6280\u5de7\uff1a\u512a\u5316 TCP nodelay \u548c TCP nopush \u8a2d\u7f6e"},"content":{"rendered":"<h1 id=\"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%84%aa%e5%8c%96-tcp-nodelay-%e5%92%8c-tcp-nopush-%e8%a8%ad%e7%bd%ae-zmPKJpfHPO\">Nginx \u6280\u5de7\uff1a\u512a\u5316 TCP nodelay \u548c TCP nopush \u8a2d\u7f6e<\/h1>\n<p>Nginx \u662f\u4e00\u6b3e\u9ad8\u6548\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u8655\u7406\u9ad8\u6d41\u91cf\u7684\u7db2\u7ad9\u3002\u5176\u6027\u80fd\u512a\u5316\u7684\u95dc\u9375\u4e4b\u4e00\u5728\u65bc TCP \u7684\u8a2d\u7f6e\uff0c\u7279\u5225\u662f TCP nodelay \u548c TCP nopush \u9019\u5169\u500b\u9078\u9805\u3002\u9019\u7bc7\u6587\u7ae0\u5c07\u6df1\u5165\u63a2\u8a0e\u9019\u5169\u500b\u8a2d\u7f6e\u7684\u4f5c\u7528\u53ca\u5176\u512a\u5316\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-tcp-nodelay-%e5%92%8c-tcp-nopush%ef%bc%9f-zmPKJpfHPO\">\u4ec0\u9ebc\u662f TCP nodelay \u548c TCP nopush\uff1f<\/h2>\n<p>\u5728\u6df1\u5165\u512a\u5316\u4e4b\u524d\uff0c\u6211\u5011\u9700\u8981\u4e86\u89e3\u9019\u5169\u500b\u9078\u9805\u7684\u57fa\u672c\u6982\u5ff5\u3002<\/p>\n<ul>\n<li><strong>TCP nodelay\uff1a<\/strong>\u9019\u500b\u9078\u9805\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u7981\u7528 Nagle \u6f14\u7b97\u6cd5\u3002Nagle \u6f14\u7b97\u6cd5\u7684\u76ee\u7684\u662f\u6e1b\u5c11\u5c0f\u5305\u7684\u6578\u91cf\uff0c\u901a\u904e\u5c07\u5c0f\u7684\u6578\u64da\u5305\u5408\u4f75\u6210\u4e00\u500b\u8f03\u5927\u7684\u6578\u64da\u5305\u4f86\u63d0\u9ad8\u7db2\u7d61\u6548\u7387\u3002\u7136\u800c\uff0c\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u9019\u6703\u5c0e\u81f4\u5ef6\u9072\uff0c\u7279\u5225\u662f\u5728\u9700\u8981\u5373\u6642\u53cd\u61c9\u7684\u61c9\u7528\u4e2d\uff0c\u5982\u904a\u6232\u6216\u5373\u6642\u901a\u8a0a\u3002<\/li>\n<li><strong>TCP nopush\uff1a<\/strong>\u9019\u500b\u9078\u9805\u5247\u662f\u7528\u4f86\u63a7\u5236 TCP \u7684\u6578\u64da\u5305\u767c\u9001\u884c\u70ba\u3002\u7576\u8a2d\u7f6e\u70ba\u555f\u7528\u6642\uff0cNginx \u6703\u5728\u767c\u9001\u97ff\u61c9\u6642\uff0c\u5c07\u6578\u64da\u7de9\u5b58\u5230\u5167\u5b58\u4e2d\uff0c\u76f4\u5230\u6574\u500b\u97ff\u61c9\u6e96\u5099\u597d\u518d\u4e00\u6b21\u6027\u767c\u9001\u3002\u9019\u6a23\u53ef\u4ee5\u6e1b\u5c11\u7db2\u7d61\u7684\u8ca0\u64d4\uff0c\u7279\u5225\u662f\u5728\u50b3\u8f38\u5927\u6587\u4ef6\u6642\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e5%84%aa%e5%8c%96%e9%80%99%e4%ba%9b%e8%a8%ad%e7%bd%ae%ef%bc%9f-zmPKJpfHPO\">\u70ba\u4ec0\u9ebc\u9700\u8981\u512a\u5316\u9019\u4e9b\u8a2d\u7f6e\uff1f<\/h2>\n<p>\u512a\u5316 TCP nodelay \u548c TCP nopush \u8a2d\u7f6e\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u7db2\u7ad9\u7684\u6027\u80fd\uff0c\u7279\u5225\u662f\u5728\u9ad8\u6d41\u91cf\u7684\u60c5\u6cc1\u4e0b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5177\u9ad4\u7684\u512a\u5316\u7406\u7531\uff1a<\/p>\n<ul>\n<li><strong>\u6e1b\u5c11\u5ef6\u9072\uff1a<\/strong>\u901a\u904e\u7981\u7528 Nagle \u6f14\u7b97\u6cd5\uff0cTCP nodelay \u53ef\u4ee5\u6e1b\u5c11\u6578\u64da\u5305\u7684\u5ef6\u9072\uff0c\u5f9e\u800c\u63d0\u9ad8\u7528\u6236\u7684\u9ad4\u9a57\u3002<\/li>\n<li><strong>\u63d0\u9ad8\u541e\u5410\u91cf\uff1a<\/strong>TCP nopush \u53ef\u4ee5\u5728\u50b3\u8f38\u5927\u6587\u4ef6\u6642\u63d0\u9ad8\u541e\u5410\u91cf\uff0c\u56e0\u70ba\u5b83\u6e1b\u5c11\u4e86 TCP \u7684\u5305\u6578\u91cf\u3002<\/li>\n<li><strong>\u9069\u61c9\u4e0d\u540c\u7684\u61c9\u7528\u5834\u666f\uff1a<\/strong>\u6839\u64da\u4e0d\u540c\u7684\u61c9\u7528\u9700\u6c42\uff0c\u9748\u6d3b\u8abf\u6574\u9019\u4e9b\u8a2d\u7f6e\u53ef\u4ee5\u9054\u5230\u6700\u4f73\u7684\u6027\u80fd\u6548\u679c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e9%85%8d%e7%bd%ae-nginx-%e7%9a%84-tcp-nodelay-%e5%92%8c-tcp-nopush%ef%bc%9f-zmPKJpfHPO\">\u5982\u4f55\u914d\u7f6e Nginx \u7684 TCP nodelay \u548c TCP nopush\uff1f<\/h2>\n<p>\u5728 Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u6307\u4ee4\u4f86\u8a2d\u7f6e TCP nodelay \u548c TCP nopush\uff1a<\/p>\n<pre><code>http {\n    ...\n    tcp_nodelay on;\n    tcp_nopush on;\n    ...\n}<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u9700\u8981\u653e\u5728 http \u5340\u584a\u4e2d\uff0c\u9019\u6a23\u5c31\u53ef\u4ee5\u5168\u5c40\u751f\u6548\u3002\u5982\u679c\u9700\u8981\u91dd\u5c0d\u7279\u5b9a\u7684 server \u6216 location \u9032\u884c\u8a2d\u7f6e\uff0c\u53ef\u4ee5\u5c07\u9019\u4e9b\u6307\u4ee4\u653e\u5728\u76f8\u61c9\u7684\u5340\u584a\u4e2d\u3002<\/p>\n<h3 id=\"%e7%a4%ba%e4%be%8b%e9%85%8d%e7%bd%ae-zmPKJpfHPO\">\u793a\u4f8b\u914d\u7f6e<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684 Nginx \u914d\u7f6e\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u5728\u7279\u5b9a\u7684 server \u5340\u584a\u4e2d\u8a2d\u7f6e\u9019\u4e9b\u9078\u9805\uff1a<\/p>\n<pre><code>server {\n    listen 80;\n    server_name example.com;\n\n    tcp_nodelay on;\n    tcp_nopush on;\n\n    location \/ {\n        proxy_pass http:\/\/backend;\n        ...\n    }\n}<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6%e5%92%8c%e8%aa%bf%e6%95%b4-zmPKJpfHPO\">\u6e2c\u8a66\u548c\u8abf\u6574<\/h2>\n<p>\u5728\u914d\u7f6e\u5b8c\u7562\u5f8c\uff0c\u5efa\u8b70\u4f7f\u7528\u5de5\u5177\u5982 <code>ab<\/code>\uff08Apache Benchmark\uff09\u6216 <code>wrk<\/code> \u4f86\u6e2c\u8a66\u7db2\u7ad9\u7684\u6027\u80fd\u3002\u6839\u64da\u6e2c\u8a66\u7d50\u679c\uff0c\u53ef\u4ee5\u9032\u4e00\u6b65\u8abf\u6574\u9019\u4e9b\u8a2d\u7f6e\uff0c\u4ee5\u9054\u5230\u6700\u4f73\u7684\u6027\u80fd\u6548\u679c\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-zmPKJpfHPO\">\u7d50\u8ad6<\/h2>\n<p>\u512a\u5316 Nginx \u7684 TCP nodelay \u548c TCP nopush \u8a2d\u7f6e\u662f\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u7684\u91cd\u8981\u6b65\u9a5f\u3002\u901a\u904e\u5408\u7406\u914d\u7f6e\u9019\u4e9b\u9078\u9805\uff0c\u53ef\u4ee5\u6709\u6548\u6e1b\u5c11\u5ef6\u9072\uff0c\u63d0\u9ad8\u541e\u5410\u91cf\uff0c\u5f9e\u800c\u6539\u5584\u7528\u6236\u9ad4\u9a57\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u80fd\u7684\u7db2\u7ad9\uff0c\u9019\u4e9b\u8a2d\u7f6e\u7684\u8abf\u6574\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u53ca\u5176\u914d\u7f6e\u7684\u8cc7\u8a0a\uff0c\u6b61\u8fce\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 Nginx \u6280\u5de7\uff0c\u512a\u5316 TCP nodelay \u548c TCP nopush \u8a2d\u7f6e\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u8207\u97ff\u61c9\u901f\u5ea6\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-49944","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=49944"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49944\/revisions"}],"predecessor-version":[{"id":49945,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49944\/revisions\/49945"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=49944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=49944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=49944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}