{"id":877,"date":"2021-12-19T00:18:49","date_gmt":"2021-12-18T16:18:49","guid":{"rendered":"https:\/\/blog.cauchyschwarz.com\/?p=877"},"modified":"2021-12-19T00:34:31","modified_gmt":"2021-12-18T16:34:31","slug":"tcp%e8%b6%85%e6%97%b6%e4%b8%8e%e9%87%8d%e4%bc%a0","status":"publish","type":"post","link":"https:\/\/blog.cauchyschwarz.com\/?p=877","title":{"rendered":"TCP\u8d85\u65f6\u4e0e\u91cd\u4f20"},"content":{"rendered":"\n<p><strong>\u8fd9\u7bc7\u6587\u7ae0\u4ec5\u4ee3\u8868\u300aTCP\/IP\u8be6\u89e3 \u5377I\u300b\u7b2c\u4e00\u7248\u7684\u8bfb\u4e66\u7b14\u8bb0\uff0c\u53ef\u80fd\u548c\u5f53\u524dLinux\u4ee3\u7801\u5b9e\u73b0\u6709\u51fa\u5165\u6216\u8005\u5185\u5bb9\u53ef\u80fd\u5df2\u7ecf\u8fc7\u65f6\u3002<\/strong><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"e68c87e695b0e59b9ee98080-1\">\u6307\u6570\u56de\u9000<\/h1>\n\n\n\n<p><strong>exponential backoff<\/strong>\uff1a\u5728\u91cd\u4f20\u8d85\u65f6\u7684\u60c5\u51b5\u4e0b\uff0cTCP\u4f1a\u5c06RTO\u7684\u503c\u7ffb\u500d\u3002<\/p>\n\n\n\n<p>Solaris\u7b49\u4e00\u4e9b\u7cfb\u7edf\u6709\u4e00\u4e2a<em>tcp_ip_abort_interval<\/em>\u7684\u53c2\u6570\uff0c\u8868\u793a\u5728\u8fde\u7eed\u91cd\u4f20\u7684\u603b\u65f6\u95f4\u5230\u8fbe\u8fd9\u4e2a\u503c\u540e(\u5927\u69822min\u6216\u80059min\u7684\u91cf\u7ea7)\uff0c\u5c31\u5e94\u8be5\u65ad\u5f00\u8fd9\u4e2aTCP\u8fde\u63a5\u3002Linux\u5e76\u6ca1\u6709\u8fd9\u4e2a\u53c2\u6570\uff0c\u800c\u662f\u6709\u4e00\u4e2a\u4e0e\u4e4b\u5bf9\u5e94\u7684<em>tcp_retries<\/em>\u53c2\u6570\uff0c\u8868\u793a\u5728\u8fde\u7eed\u91cd\u4f20\u8d85\u8fc7\u8fd9\u4e48\u591a\u6b21\u4e4b\u540e\uff0c\u5e94\u8be5\u65ad\u5f00\u5bf9\u5e94\u7684TCP\u8fde\u63a5\u3002<a href=\"https:\/\/support.hpe.com\/hpsc\/doc\/public\/display?docId=emr_na-c02441450\">\u53ef\u4ee5\u53c2\u8003\u8fd9\u4e2a\u94fe\u63a5<\/a>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sysctl net.ipv4.tcp_retries2\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>net.ipv4.tcp_retries2 = 15<\/p><\/blockquote>\n\n\n\n<p>RTO\u7684\u503c\u6709\u4e00\u4e2a\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u7684\u9650\u5236\uff0c<a href=\"https:\/\/pracucci.com\/linux-tcp-rto-min-max-and-tcp-retries2.html\">\u53ef\u53c2\u8003\u8fd9\u7bc7\u6587\u7ae0<\/a>\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"rtte79a84e6b58be9878f-1\">RTT\u7684\u6d4b\u91cf<\/h1>\n\n\n\n<p>\u65e9\u671f\u7684\u65b9\u6848\uff1a<\/p>\n\n\n\n<p>\\( R \\leftarrow \\alpha R + (1 &#8211; \\alpha)M \\)<br>\\( RTO = R \\beta \\)<\/p>\n\n\n\n<p>\u5176\u4e2d\\(M\\)\u8868\u793a\u6bcf\u6b21\u6d4b\u91cf\u5f97\u5230\u7684RTT\uff0c\\(R\\)\u8868\u793a\u901a\u8fc7\u4e0a\u9762\u7684\u516c\u5f0f\u8ba1\u7b97\u5f97\u5230\u7684Smoothed RTT\u3002\u5176\u4e2d\\(\\alpha\\)\u4e00\u822c\u53d60.9\uff0c\\(\\beta\\)\u4e00\u822c\u53d62\u3002\u8fd9\u79cd\u65b9\u6848\u7684\u7f3a\u70b9\u662f\u7531\u4e8e0.9\u8fd9\u4e2a\u503c\u7684\u8bbe\u7f6e\u5bfc\u81f4\u5386\u53f2RTT\u7684\u5f71\u54cd\u8fc7\u5927\uff0c\u5728RTT\u7684\u503c\u53d8\u5316\u6bd4\u8f83\u5927\u65f6\uff0cSRTT\u7684\u66f4\u65b0\u8ddf\u4e0d\u4e0aRTT\u6d4b\u91cf\u503c\u7684\u53d8\u5316\u60c5\u51b5\uff0c\u7531\u6b64\u53ef\u80fd\u5bfc\u81f4\u4e0d\u5fc5\u8981\u7684\u91cd\u4f20\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u8003\u8651\u53e6\u4e00\u79cd\u65b9\u6848\uff0c\u8ba1\u7b97RTO\u65f6\u628aRTT\u7684\u65b9\u5dee\/\u6807\u51c6\u5dee\u8003\u8651\u8fdb\u6765(\u4e3a\u4e86\u8ba1\u7b97\u7b80\u5355\uff0c\u5e76\u4e0d\u8ba1\u7b97\u65b9\u5dee\/\u6807\u51c6\u5dee\uff0c\u800c\u4f7f\u7528\u5e73\u5747\u504f\u5dee(mean deviation))\uff1a<\/p>\n\n\n\n<p>\\( Err = M &#8211; A \\)<br>\\( A \\leftarrow A + gErr \\)<br>\\( D \\leftarrow D + h(|Err| &#8211; D) \\)<br>\\( RTO = A + 4D \\)<\/p>\n\n\n\n<p>\u5176\u4e2d\uff0c\\(A\\)\u662fSRTT\uff0c\\(D\\)\u662f\u5e73\u6ed1\u8fc7\u540e\u7684\u5e73\u5747\u504f\u5dee\u3002\\(Err\\)\u662f\u6d4b\u91cf\u51fa\u7684RTT\u503c\u548cSRTT\u503c\u4e4b\u95f4\u7684\u5dee\u503c\u3002\\(g\\)\u4e00\u822c\u53d60.125\uff0c\\(h\\)\u4e00\u822c\u53d60.25\u3002\\(h\\)\u7684\u503c\u8d8a\u5927\uff0cRTO\u8d8a\u80fd\u53cd\u6620RTT\u7684\u53d8\u5316\u3002<\/p>\n\n\n\n<p><strong>retransmission ambiguity problem<\/strong>\uff1a\u5728\u8d85\u65f6\u91cd\u4f20\u7684\u65f6\u5019\uff0c\u5982\u679c\u6211\u4eec\u6536\u5230\u4e86&#8221;\u91cd\u4f20\u5305\u7684ack&#8221;\uff0c\u6211\u4eec\u662f\u5206\u4e0d\u6e05\u8fd9\u4e2a\u5305\u662f\u539f\u59cb\u5305\u7684ack\u8fd8\u662f\u8fd9\u4e2a\u91cd\u4f20\u5305\u7684ack\uff0c\u4e5f\u5c31\u4e0d\u80fd\u6839\u636e\u8fd9\u4e2aack\u6765\u8ba1\u7b97RTT\uff0cSRTT\uff0c\u6807\u51c6\u504f\u5dee\uff0cRTO\u8981\u4fdd\u6301\u4e0d\u53d8\u3002\u6362\u8a00\u4e4b\uff0cTCP\u91cc\u7684RTT\u6d4b\u91cf\u53ea\u80fd\u7528\u975e\u91cd\u4f20\u5305\u548c\u5176ack\u6765\u505a\uff0c\u8fd9\u5c31\u662f\u4e66\u4e2d\u6240\u8c13\u7684<em>Karn&#8217;s algorithm<\/em>\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\uff0cTCP\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u8fde\u63a5\u53ea\u4f1a\u540c\u65f6\u505a\u4e00\u4e2aRTT\u7684\u6d4b\u91cf\uff0c\u4e5f\u5c31\u662f\u5728\u6536\u5230\u7528\u4e8eRTT\u6d4b\u91cf\u7684\u5305\u7684ack\u4e4b\u524d(\u6216\u8005\u8d85\u65f6)\uff0c\u662f\u4e0d\u4f1a\u7528\u5176\u4ed6\u7684\u5305\u53c2\u4e0eRTT\u76f8\u5173\u7684\u8ba1\u7b97\u548c\u64cd\u4f5c\u7684\u3002<br>\u540c\u65f6\uff0cTCP\u53ea\u7528\u6570\u636e\u5305\u505aRTT\u6d4b\u91cf\uff0c\u4e0d\u4f1a\u7528ack\u5305\u505aRTT\u6d4b\u91cf\u3002<\/p>\n\n\n\n<p>\u4e0a\u9762\u51e0\u4e2a\u516c\u5f0f\u53ea\u662f\u7528\u4e8e\u66f4\u65b0SRTT\u548c\u5e73\u5747\u504f\u5dee\uff0c\u5bf9\u4e8e\u8fd9\u51e0\u4e2a\u503c\u7684\u521d\u59cb\u5316\uff0c\u8fc7\u7a0b\u7a0d\u6709\u4e0d\u540c\uff0c\u6309\u7167\u4e66\u4e2d\u4e3e\u4f8b\u5927\u81f4\u5982\u4e0b(\u5177\u4f53\u9700\u8981\u770b\u4e66\u5bf9\u5e94\u4e0a)\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u521d\u59cb\u5316\u5373\u53d1\u9001\u7b2c\u4e00\u4e2a\u5305\u7684\u65f6\u5019\uff0c\\(A\\)\u4f1a\u88ab\u521d\u59cb\u5316\u4e3a0\uff0c\\(D\\)\u4f1a\u521d\u59cb\u5316\u4e3a3\u79d2\uff1b\u800c\u4e14\u7b2c\u4e00\u4e2a\u5305\u7684\\(RTO\\)\u7684\u8ba1\u7b97\u516c\u5f0f\u662f\uff1a\\(RTO = A + 2D \\)\uff1b<\/li><li>\u7b2c\u4e00\u4e2a\u5305\u53d1\u51fa\u53bb\u4e22\u4e86\uff0c\u7136\u540e\u89e6\u53d1\u8d85\u65f6\uff0c\u6b64\u65f6\\(A\\)\u548c\\(D\\)\u90fd\u4e0d\u53d1\u751f\u53d8\u5316\uff0c\u4f46\\(RTO\\)\u8981\u91cd\u65b0\u8ba1\u7b97\uff0c\u53ea\u662f\u516c\u5f0f\u53d8\u4e3a\u4e86\u4e4b\u524d\u8bf4\u7684\u66f4\u65b0\u516c\u5f0f\uff1a\\(RTO = A + 4D\\)\uff0c\u4e5f\u5c31\u662f12\u79d2\uff0c\u6b64\u65f6\u7531\u4e8e\u4e22\u5305\uff0c\u6307\u6570\u56de\u9000\u88ab\u89e6\u53d1\uff0c\u56e0\u6b64\uff0c\u8fd9\u4e2aRTO\u8fd8\u8981\u4e58\u4e0a\u989d\u5916\u7cfb\u65702(\u56e0\u4e3a\u662f\u7b2c\u4e00\u6b21\u4e22\u5305\uff0c\u6240\u4ee5\u662f2)\uff0c\u4e8e\u662f\u6700\u7ec8\u7684RTO\u662f24\u79d2\uff1b<\/li><li>\u6839\u636e<em>Karn&#8217;s algorithm<\/em>\uff0c\u91cd\u4f20\u7684\u5305\u53ca\u5176ack\u4e0d\u80fd\u7528\u4e8eRTT\u6d4b\u91cf\uff0c\u4e8e\u662f\u76f4\u5230\u7b2c\u4e00\u4e2a\u975e\u91cd\u4f20\u5305\u7684ack\u6536\u5230\u540e\uff0c\u7b2c\u4e00\u6b21\u6d4b\u91cf\u51faRTT\u503c\uff0c\u6b64\u65f6\uff0c\\(A\\)\u548c\\(D\\)\u7684\u503c\u7531\u7279\u6b8a\u7684\u516c\u5f0f\u521d\u59cb\u5316\uff1a\\(A=M+0.5\\)\uff0c\\(D=A\/2\\)\u3002\u8fd9\u4e24\u4e2a\u516c\u5f0f\u4e13\u95e8\u7528\u4e8e\u7b2c\u4e00\u6b21\u6d4b\u91cf\u51faRTT\u540e\u521d\u59cb\\(A\\)\u548c\\(D\\)\uff0c\u6b64\u65f6RTO\u8fd8\u662f\u9700\u8981\u91cd\u65b0\u8ba1\u7b97\uff0c\u516c\u5f0f\u4f9d\u7136\u662f\\(RTO=A+4D\\)\u3002<\/li><li>\u518d\u4e4b\u540e\u7684\u8fc7\u7a0b\u5c31\u6ca1\u6709\u7279\u6b8a\u4e4b\u5904\u4e86\uff0c\u5b8c\u5168\u6309\u7167\u4e4b\u524d\u8bf4\u76844\u4e2a\u516c\u5f0f\u6765\u66f4\u65b0\\(Err\\)\uff0c\\(A\\)\uff0c\\(D\\)\uff0c\\(RTO\\)\u3002<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"411\" height=\"987\" src=\"https:\/\/blog.cauchyschwarz.com\/wp-content\/uploads\/2021\/12\/tcp_timeout_and_retransmission.png\" alt=\"\" class=\"wp-image-879\" srcset=\"https:\/\/blog.cauchyschwarz.com\/wp-content\/uploads\/2021\/12\/tcp_timeout_and_retransmission.png 411w, https:\/\/blog.cauchyschwarz.com\/wp-content\/uploads\/2021\/12\/tcp_timeout_and_retransmission-125x300.png 125w\" sizes=\"auto, (max-width: 411px) 100vw, 411px\" \/><\/figure>\n\n\n\n<p>\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\u8ba9\u4eba\u611f\u89c9\u6bd4\u8f83\u5947\u602a\u7684\u5c31\u662f\u7b2c\u4e00\u4e2a\u5305\u4e22\u5931\u540e\uff0cRTO\u5c45\u7136\u662f\u5148\u8981\u91cd\u65b0\u8ba1\u7b97\u4e00\u6b21\uff0c\u518d\u5e94\u7528\u6307\u6570\u56de\u9000\uff0c\u800c\u4e0d\u662fRTO\u5148\u4e0d\u53d8\u518d\u5e94\u7528\u6307\u6570\u56de\u9000\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"e68ba5e5a19ee98080e981bfe7ae97e6b395-1\">\u62e5\u585e\u9000\u907f\u7b97\u6cd5<\/h1>\n\n\n\n<p><strong>\u5224\u65ad\u662f\u5426\u4e22\u5305<\/strong>\uff1a\u5982\u679c\u4e00\u4e2a\u5305\u89e6\u53d1\u8d85\u65f6\u3001\u6216\u8005\u6536\u5230\u8be5\u5305\u7684\u4e09\u4e2a\u91cd\u590dack(\u4e5f\u5c31\u662f\u4e00\u5171\u6536\u52304\u4e2aack\u5305)\uff0c\u90a3\u4e48\u5c31\u5224\u5b9a\u8be5\u5305\u5728\u7f51\u7edc\u4f20\u8f93\u7684\u8fc7\u7a0b\u4e2d\u4e22\u5931\u4e86\u3002<\/p>\n\n\n\n<p>plantuml\u6e90\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">@startuml\n[*] --> State0\nstate \"\u53d1\u5730\u4e00\u4e2a\u5305\u7684\u65f6\u5019\u521d\u59cb\u5316&lt;latex>A&lt;\/latex>,&lt;latex>D&lt;\/latex>\" as State0\nState0: &lt;latex>A=0&lt;\/latex>\nState0: &lt;latex>D=3&lt;\/latex>\nState0: &lt;latex>RTO=A+2D=6&lt;\/latex>\n\nstate \"\u7b2c\u4e00\u4e2a\u5305\u4e22\u5305\u89e6\u53d1\u8d85\u65f6\u7684\u65f6\u5019\" as State1\nState1: Do not update &lt;latex>A&lt;\/latex> and &lt;latex>D&lt;\/latex>\nState1: &lt;latex>RTO=A+4D=12&lt;\/latex>\nState1: Apply exponential backoff: &lt;latex> RTO=2*RTO=24 &lt;\/latex>\n\nState0 --> State1\n\nstate \"\u6536\u5230\u7b2c\u4e00\u4e2a\u5305\u6216\u5176\u91cd\u4f20\u5305\u7684ack\u7684\u65f6\u5019\" as State2\nState2: According to Karn's algorithm, do not update A, D and RTO\nState2: &lt;latex>RTO = 24&lt;\/latex>\n\nState1 --> State2\n\nstate \"\u6536\u5230\u7b2c\u4e00\u4e2a\u975e\u91cd\u4f20\u5305\u7684ack\u7684\u65f6\u5019\" as State3\nState3: Update &lt;latex>A&lt;\/latex> and &lt;latex>D&lt;\/latex> with specialized formula\nState3: &lt;latex>A=M+0.5&lt;\/latex>\nState3: &lt;latex>D=A\/2&lt;\/latex>\nState3: &lt;latex>RTO=A+4D&lt;\/latex.\n\nState2 --> State3\n\nstate \"\u7ee7\u7eed\u6536\u5230\u7b2c\u4e8c\u4e2a\u975e\u91cd\u4f20\u5305\u7684ack\" as State4\nState4: Update &lt;latex>A&lt;\/latex>, &lt;latex>D&lt;\/latex> and &lt;latex>RTO&lt;\/latex> with the generalilzed formulas\nState4: &lt;latex> Err = M - A &lt;\/latex>\nState4: &lt;latex> A \\leftarrow A + gErr &lt;\/latex>\nState4: &lt;latex> D \\leftarrow D + h(|Err| - D) &lt;\/latex>\nState4: &lt;latex> RTO = A + 4D &lt;\/latex>\n\nState3 --> State4\n\nState4 --> [*]\n@enduml<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4ec5\u4ee3\u8868\u300aTCP\/IP\u8be6\u89e3 \u5377I\u300b\u7b2c\u4e00\u7248\u7684\u8bfb\u4e66\u7b14\u8bb0\uff0c\u53ef\u80fd\u548c\u5f53\u524dLinux\u4ee3\u7801\u5b9e\u73b0\u6709\u51fa\u5165\u6216\u8005\u5185\u5bb9\u53ef\u80fd\u5df2\u7ecf\u8fc7\u65f6\u3002 \u6307\u6570\u56de\u9000 exponential backoff\uff1a\u5728\u91cd\u4f20\u8d85\u65f6\u7684\u60c5\u51b5\u4e0b\uff0cTCP\u4f1a\u5c06RT&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,6],"tags":[100],"class_list":["post-877","post","type-post","status-publish","format-standard","hentry","category-10","category-6","tag-tcp"],"_links":{"self":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/877","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=877"}],"version-history":[{"count":3,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/877\/revisions"}],"predecessor-version":[{"id":881,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/877\/revisions\/881"}],"wp:attachment":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}