{"id":1152,"date":"2012-07-11T03:09:45","date_gmt":"2012-07-10T19:09:45","guid":{"rendered":"https:\/\/blog.rexdf.org\/?p=1152"},"modified":"2012-07-11T03:09:45","modified_gmt":"2012-07-10T19:09:45","slug":"%e5%86%8d%e8%b0%88select-iocp-epollkqueue%e5%8f%8a%e5%90%84%e7%a7%8dio%e5%a4%8d%e7%94%a8%e6%9c%ba%e5%88%b6","status":"publish","type":"post","link":"https:\/\/blog.rexdf.org\/ja\/2012\/07\/%e5%86%8d%e8%b0%88select-iocp-epollkqueue%e5%8f%8a%e5%90%84%e7%a7%8dio%e5%a4%8d%e7%94%a8%e6%9c%ba%e5%88%b6\/","title":{"rendered":"\u518d\u8c08select, iocp, epoll,kqueue\u53ca\u5404\u79cdI\/O\u590d\u7528\u673a\u5236"},"content":{"rendered":"<h1><strong>\u9996\u5148\uff0c\u4ecb\u7ecd\u51e0\u79cd\u5e38\u89c1\u7684I\/O\u6a21\u578b\u53ca\u5176\u533a\u522b<\/strong>\uff0c\u5982\u4e0b\uff1a<\/h1>\n<ul>\n<li>blocking I\/O<\/li>\n<li>nonblocking I\/O<\/li>\n<li>I\/O multiplexing (<tt>select<\/tt>\u00a0and\u00a0<tt>poll<\/tt>)<\/li>\n<li>signal driven I\/O (<tt>SIGIO<\/tt>)<\/li>\n<li>asynchronous I\/O (the POSIX\u00a0<tt>aio_<\/tt>functions)<\/li>\n<\/ul>\n<h2><strong>blocking I\/O<\/strong>\u00a0 \u8fd9\u4e2a\u4e0d\u7528\u591a\u89e3\u91ca\u5427\uff0c\u963b\u585e\u5957\u63a5\u5b57\u3002\u4e0b\u56fe\u662f\u5b83\u8c03\u7528\u8fc7\u7a0b\u7684\u56fe\u793a\uff1a<\/h2>\n<p><img decoding=\"async\" class=\"ls_lazyimg\" src=\"https:\/\/static.rexdf.org\/plugins\/images-lazyload-and-slideshow\/blank_250x250.gif\" file=\"http:\/\/hi.csdn.net\/attachment\/201001\/28\/156467_126466013140tA.jpg\" alt=\"\" \/><noscript><img decoding=\"async\" src=\"http:\/\/hi.csdn.net\/attachment\/201001\/28\/156467_126466013140tA.jpg\" alt=\"\" \/><\/noscript><\/p>\n<p>\u91cd\u70b9\u89e3\u91ca\u4e0b\u4e0a\u56fe\uff0c\u4e0b\u9762\u4f8b\u5b50\u90fd\u4f1a\u8bb2\u5230\u3002\u9996\u5148application\u8c03\u7528 recvfrom()\u8f6c\u5165kernel\uff0c\u6ce8\u610fkernel\u67092\u4e2a\u8fc7\u7a0b\uff0cwait for data\u548ccopy data from kernel to user\u3002\u76f4\u5230\u6700\u540ecopy complete\u540e\uff0crecvfrom()\u624d\u8fd4\u56de\u3002\u6b64\u8fc7\u7a0b\u4e00\u76f4\u662f\u963b\u585e\u7684\u3002<\/p>\n<h2><strong>nonblocking I\/O\uff1a<\/strong>\u00a0 \u4e0eblocking I\/O\u5bf9\u7acb\u7684\uff0c\u975e\u963b\u585e\u5957\u63a5\u5b57\uff0c\u8c03\u7528\u8fc7\u7a0b\u56fe\u5982\u4e0b\uff1a<\/h2>\n<p><img decoding=\"async\" class=\"ls_lazyimg\" src=\"https:\/\/static.rexdf.org\/plugins\/images-lazyload-and-slideshow\/blank_250x250.gif\" file=\"http:\/\/hi.csdn.net\/attachment\/201001\/28\/156467_1264660132Vc0H.jpg\" alt=\"\" \/><noscript><img decoding=\"async\" src=\"http:\/\/hi.csdn.net\/attachment\/201001\/28\/156467_1264660132Vc0H.jpg\" alt=\"\" \/><\/noscript><\/p>\n<p>\u53ef\u4ee5\u770b\u89c1\uff0c\u5982\u679c\u76f4\u63a5\u64cd\u4f5c\u5b83\uff0c\u90a3\u5c31\u662f\u4e2a\u8f6e\u8be2\u3002\u3002\u76f4\u5230\u5185\u6838\u7f13\u51b2\u533a\u6709\u6570\u636e\u3002<\/p>\n<h2><strong>I\/O multiplexing (select and poll)<\/strong>\u00a0 \u6700\u5e38\u89c1\u7684I\/O\u590d\u7528\u6a21\u578b\uff0cselect\u3002<\/h2>\n<p><img decoding=\"async\" class=\"ls_lazyimg\" src=\"https:\/\/static.rexdf.org\/plugins\/images-lazyload-and-slideshow\/blank_250x250.gif\" file=\"http:\/\/hi.csdn.net\/attachment\/201001\/28\/156467_126466013344Mb.jpg\" alt=\"\" \/><noscript><img decoding=\"async\" src=\"http:\/\/hi.csdn.net\/attachment\/201001\/28\/156467_126466013344Mb.jpg\" alt=\"\" \/><\/noscript><\/p>\n<p>select\u5148\u963b\u585e\uff0c\u6709\u6d3b\u52a8\u5957\u63a5\u5b57\u624d\u8fd4\u56de\u3002\u4e0e<strong>blocking I\/O<\/strong>\u76f8\u6bd4\uff0cselect\u4f1a\u6709\u4e24\u6b21\u7cfb\u7edf\u8c03\u7528\uff0c\u4f46\u662fselect\u80fd\u5904\u7406\u591a\u4e2a\u5957\u63a5\u5b57\u3002<\/p>\n<h2><strong>signal driven I\/O (SIGIO)<\/strong>\u00a0 \u53ea\u6709UNIX\u7cfb\u7edf\u652f\u6301\uff0c\u611f\u5174\u8da3\u7684\u8bfe\u67e5\u9605\u76f8\u5173\u8d44\u6599<\/h2>\n<p><img decoding=\"async\" class=\"ls_lazyimg\" src=\"https:\/\/static.rexdf.org\/plugins\/images-lazyload-and-slideshow\/blank_250x250.gif\" file=\"http:\/\/hi.csdn.net\/attachment\/201001\/28\/156467_1264660134r93R.jpg\" alt=\"\" \/><noscript><img decoding=\"async\" src=\"http:\/\/hi.csdn.net\/attachment\/201001\/28\/156467_1264660134r93R.jpg\" alt=\"\" \/><\/noscript><\/p>\n<p>\u4e0e<strong>I\/O multiplexing (select and poll)<\/strong>\u76f8\u6bd4\uff0c\u5b83\u7684\u4f18\u52bf\u662f\uff0c\u514d\u53bb\u4e86select\u7684\u963b\u585e\u4e0e\u8f6e\u8be2\uff0c\u5f53\u6709\u6d3b\u8dc3\u5957\u63a5\u5b57\u65f6\uff0c\u7531\u6ce8\u518c\u7684handler\u5904\u7406\u3002<\/p>\n<h2><span style=\"color: #ff0000;\"><strong>asynchronous I\/O (the POSIX aio_functions)<\/strong>\u00a0 <\/span>\u5f88\u5c11\u6709*nix\u7cfb\u7edf\u652f\u6301\uff0cwindows\u7684IOCP\u5219\u662f\u6b64\u6a21\u578b<\/h2>\n<p><img decoding=\"async\" class=\"ls_lazyimg\" src=\"https:\/\/static.rexdf.org\/plugins\/images-lazyload-and-slideshow\/blank_250x250.gif\" file=\"http:\/\/hi.csdn.net\/attachment\/201001\/28\/156467_1264660135UGwy.jpg\" alt=\"\" \/><noscript><img decoding=\"async\" src=\"http:\/\/hi.csdn.net\/attachment\/201001\/28\/156467_1264660135UGwy.jpg\" alt=\"\" \/><\/noscript><\/p>\n<p>\u5b8c\u5168\u5f02\u6b65\u7684I\/O\u590d\u7528\u673a\u5236\uff0c\u56e0\u4e3a\u7eb5\u89c2\u4e0a\u9762\u5176\u5b83\u56db\u79cd\u6a21\u578b\uff0c\u81f3\u5c11\u90fd\u4f1a\u5728\u7531kernel copy data to appliction\u65f6\u963b\u585e\u3002\u800c\u8be5\u6a21\u578b\u662f\u5f53copy<span style=\"color: #ff0000;\">\u5b8c\u6210<\/span>\u540e\u624d\u901a\u77e5application\uff0c\u53ef\u89c1\u662f<span style=\"color: #ff0000;\">\u7eaf\u5f02\u6b65<\/span>\u7684\u3002\u597d\u50cf\u53ea\u6709windows\u7684<span style=\"color: #ff0000;\">\u5b8c\u6210\u7aef\u53e3<\/span>\u662f\u8fd9\u4e2a\u6a21\u578b\uff0c\u6548\u7387\u4e5f\u5f88\u51fa\u8272\u3002<\/p>\n<h1><strong>\u4e0b\u9762\u662f\u4ee5\u4e0a\u4e94\u79cd\u6a21\u578b\u7684\u6bd4\u8f83<\/strong><\/h1>\n<p><strong><img decoding=\"async\" class=\"ls_lazyimg\" src=\"https:\/\/static.rexdf.org\/plugins\/images-lazyload-and-slideshow\/blank_250x250.gif\" file=\"http:\/\/hi.csdn.net\/attachment\/201001\/28\/156467_1264660135Ow47.jpg\" alt=\"\" \/><noscript><img decoding=\"async\" src=\"http:\/\/hi.csdn.net\/attachment\/201001\/28\/156467_1264660135Ow47.jpg\" alt=\"\" \/><\/noscript><\/strong><\/p>\n<p>\u53ef\u4ee5\u770b\u51fa\uff0c\u8d8a\u5f80\u540e\uff0c\u963b\u585e\u8d8a\u5c11\uff0c\u7406\u8bba\u4e0a\u6548\u7387\u4e5f\u662f\u6700\u4f18\u3002<\/p>\n<p>=====================\u5206\u5272\u7ebf==================================<\/p>\n<p>5\u79cd\u6a21\u578b\u7684\u6bd4\u8f83\u6bd4\u8f83\u6e05\u6670\u4e86\uff0c\u5269\u4e0b\u7684\u5c31\u662f\u628aselect,epoll,iocp,kqueue\u6309\u53f7\u5165\u5ea7\u90a3\u5c31OK\u4e86\u3002<\/p>\n<p>select\u548ciocp\u5206\u522b\u5bf9\u5e94\u7b2c3\u79cd\u4e0e\u7b2c5\u79cd\u6a21\u578b\uff0c\u90a3\u4e48epoll\u4e0ekqueue\u5462\uff1f\u5176\u5b9e\u4e5f\u4e8eselect\u5c5e\u4e8e\u540c\u4e00\u79cd\u6a21\u578b\uff0c\u53ea\u662f\u66f4\u9ad8\u7ea7\u4e00\u4e9b\uff0c\u53ef\u4ee5\u770b\u4f5c\u6709\u4e86\u7b2c4\u79cd\u6a21\u578b\u7684\u67d0\u4e9b\u7279\u6027\uff0c\u5982callback\u673a\u5236\u3002<\/p>\n<h1><strong>\u90a3\u4e48\uff0c\u4e3a\u4ec0\u4e48epoll,kqueue\u6bd4select\u9ad8\u7ea7\uff1f\u00a0 <\/strong><\/h1>\n<p>\u7b54\u6848\u662f\uff0c\u4ed6\u4eec\u65e0<span style=\"color: #ff0000;\"><strong>\u8f6e\u8be2<\/strong><\/span>\u3002\u56e0\u4e3a\u4ed6\u4eec\u7528callback\u53d6\u4ee3\u4e86\u3002\u60f3\u60f3\u770b\uff0c\u5f53\u5957\u63a5\u5b57\u6bd4\u8f83\u591a\u7684\u65f6\u5019\uff0c\u6bcf\u6b21select()\u90fd\u8981\u901a\u8fc7\u904d\u5386FD_SETSIZE\u4e2aSocket\u6765\u5b8c\u6210\u8c03\u5ea6,\u4e0d\u7ba1\u54ea\u4e2aSocket\u662f\u6d3b\u8dc3\u7684,\u90fd\u904d\u5386\u4e00\u904d\u3002\u8fd9\u4f1a\u6d6a\u8d39\u5f88\u591aCPU\u65f6\u95f4\u3002\u5982\u679c\u80fd\u7ed9\u5957\u63a5\u5b57\u6ce8\u518c\u67d0\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5f53\u4ed6\u4eec\u6d3b\u8dc3\u65f6\uff0c\u81ea\u52a8\u5b8c\u6210\u76f8\u5173\u64cd\u4f5c\uff0c\u90a3\u5c31\u907f\u514d\u4e86\u8f6e\u8be2\uff0c\u8fd9\u6b63\u662fepoll\u4e0ekqueue\u505a\u7684\u3002<\/p>\n<h1><strong>windows or *nix \uff08IOCP or kqueue\/epoll\uff09\uff1f<\/strong><\/h1>\n<p>\u8bda\u7136\uff0cWindows\u7684IOCP\u975e\u5e38\u51fa\u8272\uff0c\u76ee\u524d\u5f88\u5c11\u6709\u652f\u6301<strong>asynchronous I\/O<\/strong>\u7684\u7cfb\u7edf\uff0c\u4f46\u662f\u7531\u4e8e\u5176\u7cfb\u7edf\u672c\u8eab\u7684\u5c40\u9650\u6027\uff0c\u5927\u578b\u670d\u52a1\u5668\u8fd8\u662f\u5728UNIX\u4e0b\u3002\u800c\u4e14\u6b63\u5982\u4e0a\u9762\u6240\u8ff0\uff0ckqueue\/epoll \u4e0e IOCP\u76f8\u6bd4\uff0c\u5c31\u662f\u591a\u4e86\u4e00\u5c42\u4ece\u5185\u6838copy\u6570\u636e\u5230\u5e94\u7528\u5c42\u7684\u963b\u585e\uff0c\u4ece\u800c\u4e0d\u80fd\u7b97\u4f5c<strong>asynchronous I\/O\u7c7b\u3002<\/strong>\u4f46\u662f\uff0c\u8fd9\u5c42\u5c0f\u5c0f\u7684\u963b\u585e\u65e0\u8db3\u8f7b\u91cd\uff0ckqueue\u4e0eepoll\u5df2\u7ecf\u505a\u5f97\u5f88\u4f18\u79c0\u4e86\u3002<\/p>\n<h1><strong>\u63d0\u4f9b\u4e00\u81f4\u7684\u63a5\u53e3\uff0cIO Design Patterns<\/strong><\/h1>\n<p>\u5b9e\u9645\u4e0a\uff0c\u4e0d\u7ba1\u662f\u54ea\u79cd\u6a21\u578b\uff0c\u90fd\u53ef\u4ee5\u62bd\u8c61\u4e00\u5c42\u51fa\u6765\uff0c\u63d0\u4f9b\u4e00\u81f4\u7684\u63a5\u53e3\uff0c\u5e7f\u4e3a\u4eba\u77e5\u7684\u6709ACE,Libevent\u8fd9\u4e9b\uff0c\u4ed6\u4eec\u90fd\u662f\u8de8\u5e73\u53f0\u7684\uff0c\u800c\u4e14\u4ed6\u4eec\u81ea\u52a8\u9009\u62e9\u6700\u4f18\u7684I\/O\u590d\u7528\u673a\u5236\uff0c\u7528\u6237\u53ea\u9700\u8c03\u7528\u63a5\u53e3\u5373\u53ef\u3002\u8bf4\u5230\u8fd9\u91cc\u53c8\u5f97\u8bf4\u8bf42\u4e2a\u8bbe\u8ba1\u6a21\u5f0f\uff0c<strong>Reactor<\/strong>\u00a0and\u00a0<strong>Proactor\u3002<\/strong>\u6709\u4e00\u7bc7\u7ecf\u5178\u6587\u7ae0<a href=\"http:\/\/www.artima.com\/articles\/io_design_patterns.html\">http:\/\/www.artima.com\/articles\/io_design_patterns.html<\/a>\u503c\u5f97\u9605\u8bfb\uff0cLibevent\u662f<strong>Reactor<\/strong>\u6a21\u578b\uff0cACE\u63d0\u4f9b<strong>Proactor<\/strong>\u6a21\u578b\u3002\u5b9e\u9645\u90fd\u662f\u5bf9\u5404\u79cdI\/O\u590d\u7528\u673a\u5236\u7684\u5c01\u88c5\u3002<\/p>\n<h1><strong>Java nio\u5305\u662f\u4ec0\u4e48I\/O\u673a\u5236\uff1f<\/strong><\/h1>\n<p>\u6211\u66fe\u5929\u771f\u7684\u8ba4\u4e3ajava nio\u5c01\u88c5\u7684\u662fIOCP\u3002\u3002\u73b0\u5728\u53ef\u4ee5\u786e\u5b9a\uff0c\u76ee\u524d\u7684java\u672c\u8d28\u662fselect()\u6a21\u578b\uff0c\u53ef\u4ee5\u68c0\u67e5\/jre\/bin\/nio.dll\u5f97\u77e5\u3002\u81f3\u4e8ejava\u670d\u52a1\u5668\u4e3a\u4ec0\u4e48\u6548\u7387\u8fd8\u4e0d\u9519\u3002\u3002\u6211\u4e5f\u4e0d\u5f97\u800c\u77e5\uff0c\u53ef\u80fd\u662f\u8bbe\u8ba1\u5f97\u6bd4\u8f83\u597d\u5427\u3002\u3002-_-\u3002<\/p>\n<p>=====================\u5206\u5272\u7ebf==================================<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u603b\u7ed3\u4e00\u4e9b\u91cd\u70b9\uff1a<\/span><\/strong><\/p>\n<ol>\n<li>\u53ea\u6709IOCP\u662fasynchronous I\/O\uff0c\u5176\u4ed6\u673a\u5236\u6216\u591a\u6216\u5c11\u90fd\u4f1a\u6709\u4e00\u70b9\u963b\u585e\u3002<\/li>\n<li>select\u4f4e\u6548\u662f\u56e0\u4e3a\u6bcf\u6b21\u5b83\u90fd\u9700\u8981\u8f6e\u8be2\u3002\u4f46\u4f4e\u6548\u4e5f\u662f\u76f8\u5bf9\u7684\uff0c\u89c6\u60c5\u51b5\u800c\u5b9a\uff0c\u4e5f\u53ef\u901a\u8fc7\u826f\u597d\u7684\u8bbe\u8ba1\u6539\u5584<\/li>\n<li>epoll, kqueue\u662fReacor\u6a21\u5f0f\uff0cIOCP\u662fProactor\u6a21\u5f0f\u3002<\/li>\n<li>java nio\u5305\u662fselect\u6a21\u578b\u3002\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\uff0c\u4ecb\u7ecd\u51e0\u79cd\u5e38\u89c1\u7684I\/O\u6a21\u578b\u53ca\u5176\u533a\u522b\uff0c\u5982\u4e0b\uff1a blocking I\/O non &hellip; <a href=\"https:\/\/blog.rexdf.org\/ja\/2012\/07\/%e5%86%8d%e8%b0%88select-iocp-epollkqueue%e5%8f%8a%e5%90%84%e7%a7%8dio%e5%a4%8d%e7%94%a8%e6%9c%ba%e5%88%b6\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[19],"tags":[99],"class_list":["post-1152","post","type-post","status-publish","format-standard","hentry","category-site-build","tag-99"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/posts\/1152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/comments?post=1152"}],"version-history":[{"count":0,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/posts\/1152\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/media?parent=1152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/categories?post=1152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/tags?post=1152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}