{"id":1729,"date":"2018-10-12T17:34:33","date_gmt":"2018-10-12T09:34:33","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=1729"},"modified":"2018-10-24T17:55:13","modified_gmt":"2018-10-24T09:55:13","slug":"%e4%b8%80%e6%ac%a1%e5%88%a8%e6%a0%b9%e9%97%ae%e5%ba%95%e7%9a%84socket%e6%94%b6%e5%8c%85%e8%bf%87%e7%a8%8b%ef%bc%88linux%ef%bc%89","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/1729","title":{"rendered":"\u4e00\u6b21\u5228\u6839\u95ee\u5e95\u7684socket\u6536\u5305\u8fc7\u7a0b\uff08Linux\uff09"},"content":{"rendered":"<div class=\"article-header-box\">\n<div class=\"article-header\">\n<div class=\"article-title-box\"><\/div>\n<\/div>\n<\/div>\n<article>\n<div id=\"article_content\" class=\"article_content clearfix csdn-tracking-statistics\" data-pid=\"blog\" data-mod=\"popu_307\" data-dsm=\"post\">\n<div class=\"article-copyright\"><strong>\u524d\u8a00\uff1a<\/strong><\/div>\n<div class=\"htmledit_views\">\n<p>\u5728\u4e00\u6b21socket\u7684\u6536\u5305\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u56e0\u4e3a\u4e00\u4e9b\u7cfb\u7edf\u56e0\u7d20\u5e26\u6765\u4e00\u5b9a\u7684\u5ef6\u8fdf\uff0c\u4e0b\u9762\u6765\u8bb2\u8ff0\u8fd9\u4e9b\u7cfb\u7edf\u56e0\u7d20\u3002<\/p>\n<p><strong>\u8fc7\u7a0b\uff1a<\/strong><\/p>\n<p>Linux\u4f1a\u5bf9\u4e00\u4e2a\u7f51\u7edc\u5305\uff08packet\uff09\u7684\u6536\u548c\u53d1\u505a\u5927\u91cf\u7684\u5904\u7406\u3002packet\u5728\u88ab\u53d1\u9001\u4e4b\u524d\u4f1a\u88ab\u5b58\u5728\u961f\u5217\u4e2d\uff0c\u800c\u5728\u88ab\u63a5\u6536\u4e4b\u540e\u4e5f\u4f1a\u5b58\u5728\u961f\u5217\u4e2d\uff0c\u5171\u6709\u4e09\u4e2a\u961f\u5217\uff1areception\uff08\u63a5\u6536\uff09\uff0ctransmission\uff08\u53d1\u9001\uff09\u548cBacklog\u3002\u5b83\u4eec\u90fd\u53d7\u5230spinlock\u7684\u4fdd\u62a4\uff0c\u662f\u4e3a\u4e86\u4fdd\u8bc1\u5728\u5e76\u53d1\u8bbf\u95ee\u65f6\u7684\u4e00\u81f4\u6027\u3002\u8a00\u5f52\u6b63\u4f20\uff0c\u63a5\u4e0b\u6765\u770b\u770b\u5f53\u4e00\u4e2apacket\u5230\u8fbeNIC\uff08\u7f51\u5361\uff09\u65f6\uff0clinux\u90fd\u4f1a\u505a\u4e9b\u4ec0\u4e48\u5de5\u4f5c\u3002<\/p>\n<p>\u5148\u6765\u770b\u4e00\u4e2a\u56fe\uff08\u6765\u81ea\u8bba\u6587\u00a0<a href=\"http:\/\/www.jcc2014.ucm.cl\/jornadas\/WORKSHOP\/WSDP%202014\/WSDP-4.pdf\" target=\"_blank\" rel=\"nofollow noopener\">Analysis of Linux UDP Sockets Concurrent Performance<\/a>\uff09<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img-blog.csdn.net\/20150204233937960\" alt=\"\" \/><\/p>\n<p>1\uff09\u5148\u89e6\u53d1\u786c\u4e2d\u65ad\uff08HardIRQ\uff09\uff0c\u518d\u8fdb\u884c\u8f6f\u4e2d\u65ad\uff08SoftIRQ\uff09\u3002<\/p>\n<p>2\uff09\u8f6f\u4e2d\u65ad\u6267\u884c\u8fc7\u7a0b\u4e2d\u7684Lower Processing\u5904\u7406\u4f1a\u5c06packet\u4eceL2\u5c42\u9001\u5230L4\u5c42\u3002<\/p>\n<p>3\uff09\u63a5\u4e0b\u6765\u5c31\u662fpacket\u5165\u961f\uff0c\u540c\u6b65\u539f\u8bed\u4f1a\u5f71\u54cd\u5230\u6536\u5305\u6027\u80fd\u3002\uff08\u518d\u4e4b\u540e\u5c31\u662f\u88ab\u5e94\u7528\u7a0b\u5e8f\u8bfb\u53d6\uff09<\/p>\n<p>\u8865\u5145\u4e00\u70b9\uff1a\u5c31\u62ff\u6536\u5305\u6765\u8bf4\uff0c\u5728\u88ab\u5e94\u7528\u7a0b\u5e8f\u8bfb\u5230\u4e4b\u524d\uff0clinux\u8981\u5c06\u5176\u4ece\u7f51\u5361\u642c\u5230\u5185\u6838\u5185\u5b58\uff08kernel&#8217;s memory\uff09\uff0c\u4f46\u662f\u4e00\u4e2asocket\u53ea\u80fd\u4f7f\u7528\u6709\u9650\u5236\u7684\u5185\u6838\u5185\u5b58\u6765\u5b58\u5305\uff0c\u5426\u5219\u4f1a\u8ba9\u5185\u6838\u5185\u5b58\u6ea2\u51fa\uff08overflow\uff09\u3002<\/p>\n<p>\u66f4\u8be6\u7ec6\u7684\u6536\u5305\u8fc7\u7a0b\u53ef\u4ee5\u770b\u8fd9\u7bc7\u6587\u7ae0\uff1a<a href=\"http:\/\/cd-docdb.fnal.gov\/0019\/001968\/001\/Linux-Pkt-Recv-Performance-Analysis-Final.pdf\" target=\"_blank\" rel=\"nofollow noopener\">The performance analysis of linux networking \u2013 packet receiving<\/a>\u3002<\/p>\n<p>\u8fd9\u7bc7\u6587\u7ae0\u4e5f\u628a\u6536\u5305\u8fc7\u7a0b\u5206\u6210\u4e86\u4e09\u4e2a\u66f4\u6e05\u6670\u7684\u9636\u6bb5\uff1a<\/p>\n<p>1\uff09\u7f51\u5361\u9a71\u52a8\u7a0b\u5e8f\u5c06packet\u4eceNIC\u642c\u5230ring buffer\u4e2d\uff0c\u8fd9\u5c31\u662f\u5e38\u8bf4\u7684DMA\u8fc7\u7a0b<\/p>\n<p>2\uff09\u63a5\u4e0b\u6765\u89e6\u53d1\u8f6f\u4e2d\u65ad\uff08SoftIRQ\uff09\uff0clinux kernel\u4f1a\u53c2\u4e0e\u8fdb\u6765\uff0c\u5c06packet\u4ecering buffer\u642c\u5230socket\u7684\u63a5\u6536\u7f13\u51b2\u533a\u91cc\u3002<\/p>\n<p>3\uff09\u6700\u540e\u5c31\u662f\u6211\u4eec\u6700\u719f\u6089\u7684\uff0c\u5e94\u7528\u7a0b\u5e8f\u4ece\u7f13\u51b2\u533a\u91cc\u8bfb\u53d6packet\uff0c\u5c31\u662fC\u8bed\u8a00socket\u7f16\u7a0b\u4e2d\u7684recv\u51fd\u6570\uff0c\u5b83\u4f1a\u8fdb\u884c\u4e00\u4e2a\u7cfb\u7edf\u8c03\u7528\u6765\u8bfb\u53d6packet\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img-blog.csdn.net\/20150205100621592\" alt=\"\" \/><\/p>\n<p>\u8865\u5145\u4e00\u70b9\uff1a\u540c\u6837\u5728\u9636\u6bb52\u4e2d\uff0c\u4e5f\u662f\u8981\u8bbf\u95eelock\u7684\uff0c\u6211\u4eec\u5728\u4e4b\u524d\u63d0\u5230\u8fc7\u4e09\u4e2a\u63a5\u6536\u961f\u5217\uff0c\u5176\u4e2d\u4e00\u4e2a\u53ebBacklog\uff0c\u5f53socket\u5904\u4e8e\u88ab\u9501\u72b6\u6001\u65f6\uff0cpacket\u5c31\u6682\u5b58\u5728Backlog\u4e2d\u4ee5\u5f85\u8fdb\u4e00\u6b65\u5904\u7406\u3002<\/p>\n<p>\u76ee\u7684\uff1a<\/p>\n<p>\u5728\u666e\u901a\u7684i5\u7b14\u8bb0\u672c\u4e0a\uff0c\u6211\u4eec\u53d1\u73b0\u4e00\u6b21socket\u7684loopback\u7684TCP\u7684\u53d1\uff08client\uff09\u548c\u6536\uff08server\uff09\u8981\u8017\u65f6100\uff5e200 us\u3002\u800cloopback\u7684\u5e26\u5bbd\u53ef\u4ee5\u8fbe\u523030\uff5e40Gbps\uff0c\u6240\u4ee5\u5e76\u4e0d\u662f\u7f51\u7edc\u4f20\u8f93\u4ea7\u751f\u8fd9\u6837\u7684\u5ef6\u8fdf\uff08latency\uff09\u3002\u901a\u8fc7\u4e0a\u9762\u7684\u5206\u6790\uff0c\u5f53server\u8fd9\u7aef\u7684\u7f51\u5361\u6536\u5230\u5305\u65f6\uff0c\u4f1a\u7ecf\u8fc7\u4e00\u7cfb\u5217\u7684\u6b65\u9aa4\u624d\u80fd\u88ab\u7528\u6237\u7a0b\u5e8f\u8bfb\u53d6\uff0c\u8fd9\u4e00\u8fc7\u7a0b\u5305\u62ec\u89e6\u53d1\u4e2d\u65ad\uff0c\u5185\u6838\u5185\u5b58\u62f7\u8d1d\uff0c\u8fdb\u5165\u5e26\u9501\u7684\u961f\u5217\uff0c\u7b49\u3002\u4f1a\u4e0d\u4f1a\u662f\u8fd9\u4e9b\u64cd\u4f5c\u5360\u636e\u4e86\u5927\u90e8\u5206\u65f6\u95f4\uff0c\u73b0\u5728\u4ecd\u4e0d\u80fd\u65ad\u8a00\u5c31\u662f\uff0c\u4ecd\u7136\u9700\u8981\u66f4\u786e\u51ff\u7684\u8bc1\u636e\u3002<\/p>\n<p>\u5228\u4e86\u8fd9\u4e48\u591a\uff0c\u5728Dolphin SuperSockets\u7684\u4ecb\u7ecd\u4e2d\u53d1\u73b0\u8fd9\u4e2afigure\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img-blog.csdn.net\/20150205123149759\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img-blog.csdn.net\/20150205123157171\" alt=\"\" \/><\/p>\n<p>\u8fd9\u4e24\u5e45\u56fe\u4f50\u8bc1\u4e86\u786e\u5b9e\u9700\u8981\u5341\u51e0\u5fae\u79d2\u6216\u51e0\u5341\u5fae\u79d2\u7684\u65f6\u95f4\u53bb\u5904\u7406\u9664\u4e86packet\u7f51\u7edc\u4f20\u8f93\u4e4b\u5916\u7684\u5176\u4ed6\u64cd\u4f5c\uff0c\u800c\u8fd9\u4e2aSuperSockets\u4e4b\u6240\u4ee5\u80fd\u51cf\u5c11\u5176\u4e2d\u7684\u5ef6\u8fdf\uff0c\u4e00\u5b9a\u662f\u9488\u5bf9\u6211\u4eec\u4e0a\u9762\u6240\u63d0\u7684\u51e0\u4e2a\u9636\u6bb5\u8fdb\u884c\u4e86\u4f18\u5316\u3002<\/p>\n<p>\u5728\u6587\u7ae0\u00a0<a href=\"http:\/\/tech-forge.com\/Latency_IJPP2009.pdf\" target=\"_blank\" rel=\"nofollow noopener\">Architectural Breakdown of End-to-End Latency\u00a0in a TCP\/IP Network<\/a>\u00a0\u4e2d\uff0c\u6709\u8fd9\u6837\u7684\u8bdd\uff1a<\/p>\n<p>For a small message of 64B,<br \/>\nlatency with Infiniband was measured at 5.3\u00b5s and Myrinet at 8.3\u00b5s compared to<br \/>\n60 \u00b5s on Ethernet with TCP\/IP.<\/p>\n<p>&#8230; &#8230;<\/p>\n<p>It may be obvious why TCP\/IP has a much higher latency than Infiniband and Myrinet<br \/>\nand other hardware based protocols to efficiently pass point-to-point messages<br \/>\nbetween applications. Key to the differences is that, in the case of Infiniband and Myrinet,<br \/>\nthe hardware supports the packetization, segmentation, reassembly and movement<br \/>\nof payload data into user space. This is directly accessible by the user space application<br \/>\nwithout a transition from kernel space to user space with memory copies or complex<br \/>\npointer redirection.<\/p>\n<p>&#8230; &#8230;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img-blog.csdn.net\/20150205162150884\" alt=\"\" \/><\/p>\n<p>\u53e6\u5916\u8fd9\u91cc\u8fd8\u6d89\u53ca\u4e0a\u4e0b\u6587\u5207\u6362\uff1a\u5e94\u7528\u7a0b\u5e8f\u5e76\u6ca1\u6709\u8fd0\u884c\u5728\u6b63\u5728\u5904\u7406packet\u7684core\u4e0a\u3002Linux\u4e3a\u6b64\u4f1a\u82b1\u8d39 2 us \u7684overhead\u3002<\/p>\n<p>\u5728\u8fd9\u7bc7\u6587\u7ae0\u7ed3\u5c3e\uff0c\u603b\u7ed3\u4e86\u56db\u4e2a\u5730\u65b9\u4f1a\u5e26\u6765 12\uff5e282 us \u7684latency\uff1a<\/p>\n<p>1) head-of-queue effect<\/p>\n<p>2) system bandwidth contention<\/p>\n<p>3) application core affinity<\/p>\n<p>4) interrupt\u00a0and timer<\/p>\n<\/div>\n<\/div>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00\uff1a \u5728\u4e00\u6b21socket\u7684\u6536\u5305\u8fc7\u7a0b\u4e2d\uff0c<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[24],"tags":[121],"class_list":["post-1729","post","type-post","status-publish","format-standard","hentry","category-value_docs","tag-05-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/1729","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=1729"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/1729\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=1729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=1729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=1729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}