{"id":2896,"date":"2019-02-27T20:35:08","date_gmt":"2019-02-27T12:35:08","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=2896"},"modified":"2019-02-27T20:35:08","modified_gmt":"2019-02-27T12:35:08","slug":"gonet-2%e6%a1%86%e6%9e%b6","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/2896","title":{"rendered":"gonet\/2\u6846\u67b6"},"content":{"rendered":"<p>\u7f51\u5740\uff1a<a href=\"http:\/\/gonet2.github.io\/\">http:\/\/gonet2.github.io\/<\/a><\/p>\n<h1><\/h1>\n<h1 id=\"section\">\u6b22\u8fce\u4f7f\u7528<\/h1>\n<p><a href=\"https:\/\/github.com\/gonet2\">gonet\/2<\/a>\u662f\u65b0\u4e00\u4ee3\u6e38\u620f\u670d\u52a1\u5668\u9aa8\u67b6\uff0c\u57fa\u4e8e<a href=\"http:\/\/golang.org\/\">go\u8bed\u8a00<\/a>\u5f00\u53d1\uff0c\u91c7\u7528\u4e86\u5148\u8fdb\u7684<a href=\"http:\/\/http2.github.io\/\">http\/2<\/a>\u4f5c\u4e3a\u670d\u52a1\u5668\u7aef\u4e3b\u8981\u901a\u4fe1\u534f\u8bae\uff0c\u4ee5<a href=\"http:\/\/martinfowler.com\/articles\/microservices.html\">microservice<\/a>\u4f5c\u4e3a\u4e3b\u8981\u601d\u60f3\u8fdb\u884c\u67b6\u6784\uff0c\u91c7\u7528<a href=\"https:\/\/www.docker.com\/\">docker<\/a>\u4f5c\u4e3a\u670d\u52a1\u53d1\u5e03\u624b\u6bb5\u3002\u76f8\u6bd4\u7b2c\u4e00\u4ee3<a href=\"http:\/\/github.com\/xtaci\/gonet\">gonet<\/a>\uff0c\u57fa\u7840\u6280\u672f\u9009\u578b\u66f4\u52a0\u5148\u8fdb\uff0c\u7ed3\u6784\u66f4\u52a0\u6e05\u6670\u6613\u8bfb\u53ef\u6269\u5c55\u3002<\/p>\n<h2 id=\"section-1\">\u76f8\u5173\u6587\u6863<\/h2>\n<ol>\n<li><a href=\"https:\/\/github.com\/gonet2\/doc\/blob\/master\/INSTALL.md\">INSTALL.md<\/a>\u00a0\u2013 \u5b89\u88c5<\/li>\n<li><a href=\"https:\/\/github.com\/gonet2\/doc\/blob\/master\/CICD.md\">CICD.md<\/a>\u00a0\u2013 \u6301\u7eed\u96c6\u6210\u4e0e\u6301\u7eed\u90e8\u7f72<\/li>\n<\/ol>\n<h2 id=\"microservice\">\u4e3a\u4ec0\u4e48\u7528microservice\u67b6\u6784?<\/h2>\n<p>\u4e1a\u52a1\u5206\u79bb\u662f\u6e38\u620f\u670d\u52a1\u5668\u67b6\u6784\u7684\u57fa\u672c\u601d\u8def\uff0c\u901a\u8fc7\u804c\u80fd\u5212\u5206\uff0c\u80fd\u591f\u66f4\u52a0\u5408\u7406\u7684\u8c03\u914d\u670d\u52a1\u5668\u8d44\u6e90\u3002 \u8d44\u6e90\u7684\u5927\u5206\u7c7b\u5305\u62ec\uff0cIO,CPU,MEM,BANDWIDTH, \u4f8b\u5982\u5e38\u89c1\u7684\u60c5\u666f\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">IO: \u5982: \u6570\u636e\u5e93\uff0c\u6587\u4ef6\u670d\u52a1\uff0c\u6d88\u8017\u5927\u91cf\u8bfb\u5199        \r\nCPU: \u5982: \u6e38\u620f\u903b\u8f91\uff0c\u6d88\u8017\u5927\u91cf\u6307\u4ee4        \r\nMEM: \u5982: \u5206\u8bcd\uff0c\u6392\u540d\uff0cpubsub\uff0c \u6d88\u8017\u5927\u91cf\u5185\u5b58   \r\nBANDWIDTH: \u5185\u7f51\u5e26\u5bbd\u9ad8\uff0c\u5916\u7f51\u5e26\u5bbd\u4f4e\uff0c\u7269\u7406\u4e0a\u8d8a\u63a5\u8fd1\u7684\uff0c\u4f20\u8f93\u901f\u5ea6\u8d8a\u9ad8<\/pre>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><\/pre>\n<\/div>\n<p>\u73a9\u5bb6\u5bf9\u6bcf\u79cd\u670d\u52a1\u7684\u8bf7\u6c42\u91cf\u6709<strong>\u5de8\u5927\u7684\u4e0d\u540c<\/strong>\uff0c\u6bd4\u5982\u903b\u8f91\u8bf7\u6c42100\u6b21\uff0c\u5206\u8bcd\u8bf7\u6c421\u6b21\uff0c\u6240\u4ee5\uff0c\u6ca1\u6709\u5fc5\u89811:1\u914d\u7f6e\u8d44\u6e90\uff0c\u901a\u8fc7microservice\u65b9\u5f0f\u5206\u79bb\u670d\u52a1\uff0c\u53ef\u4ee5\u6839\u636e\u4e1a\u52a1\u4f7f\u7528\u60c5\u51b5\uff0c\u6309\u9700\u914d\u7f6e\u670d\u52a1\u5668\u8d44\u6e90\u3002\u5f53\u670d\u52a1\u5bb9\u91cf\u589e\u957f\uff0c\u5982\u679c\u5728monolithic\u7684\u67b6\u6784\u4e0a\u505a\uff0c\u5373\u5168\u90e8\u670d\u52a1\u63c9\u5728\u4e00\u8d77\u6210\u4e00\u4e2a\u5927\u8fdb\u7a0b\uff0c\u4f1a\u4e25\u91cd\u6d6a\u8d39\u8d44\u6e90\uff0c\u6bd4\u5982\u5927\u91cf\u5185\u5b58\u88ab\u6781\u5c11\u88ab\u4f7f\u7528\u7684\u6a21\u5757\u5360\u7528, \u66f4\u4e25\u91cd\u7684\u95ee\u9898\u662f\uff0c\u5355\u53f0\u670d\u52a1\u5668\u7684\u8d44\u6e90\u4e0d\u662f\u65e0\u9650\u5236\u7684\uff0c\u867d\u7136\u76ee\u524d\u9876\u7ea7\u914d\u7f6e\u7684\u670d\u52a1\u5668\u53ef\u4ee5\u5b89\u88c5\u9ad8\u8fbe96GB\u7684\u5185\u5b58\uff0c\u4f46\u4e5f\u6781\u5176\u6602\u8d35\uff0c\u90e8\u7f72\u91cf\u5927\u7684\u65f6\u5019\uff0c\u4ea7\u751f\u7684\u8d39\u7528\u4e5f\u4e0d\u5bb9\u5c0f\u89d1\u3002<\/p>\n<h2 id=\"http2\">\u4e3a\u4ec0\u4e48\u9009HTTP\/2?<\/h2>\n<p>\u4e3a\u4e86\u628a\u6240\u6709\u7684\u670d\u52a1\u4e32\u8d77\u6765\uff0c\u5fc5\u987b\u6ee1\u8db3\u7684\u6761\u4ef6\u6709\uff1a<br \/>\n1. \u652f\u6301\u4e00\u5143RPC\u8c03\u7528 (\u4e00\u822c\u7684\u8bf7\u6c42\/\u5e94\u7b54\u6a21\u5f0f\uff0c\u7c7b\u4f3c\u4e8e\u51fd\u6570\u8c03\u7528)<br \/>\n2. \u652f\u6301\u670d\u52a1\u5668\u63a8\u9001\uff08\u4f8b\u5982pubsub\u670d\u52a1\uff0c\u5f02\u6b65\u901a\u77e5\uff09<br \/>\n3. \u652f\u6301\u53cc\u5411\u6d41\u4f20\u9012 (\u7f51\u5173\u900f\u4f20\u8bbe\u5907\u6570\u636e\u5305\u5230\u540e\u7aef\uff0c\u540e\u7aef\u5e94\u7b54\u6570\u636e\u7ecf\u8fc7\u7f51\u5173\u8fd4\u56de\u5230\u8bbe\u5907)<\/p>\n<p>\u6211\u4eec\u6682\u4e0d\u60f3\u81ea\u5df1\u8bbe\u8ba1<a href=\"https:\/\/en.wikipedia.org\/wiki\/Remote_procedure_call\">RPC<\/a>\uff0c\u4e00\u662f\u76ee\u524dRPC\u7e41\u591a\uff0c\u6ca1\u5fc5\u8981\u91cd\u65b0\u53d1\u660e\u8f6e\u5b50\uff0c\u4e8c\u662f\u4f5c\u4e3a\u5f00\u6e90\u9879\u76ee\uff0c\u5e94\u5145\u5206\u878d\u5165\u793e\u533a\uff0c\u5229\u7528\u73b0\u6709\u8d44\u6e90\u3002\u6211\u4eec\u53d1\u73b0\u76ee\u524dhttp\/2(rfc7540)\u6ee1\u8db3\u4ee5\u4e0a\u6240\u6709\u6761\u4ef6\uff0cgoogle\u63a8\u51fa\u7684<a href=\"http:\/\/grpc.io\/\">gRPC<\/a>\u5c31\u662f\u4e00\u4e2a\u57fa\u4e8ehttp\/2\u7684RPC\u5b9e\u73b0\uff0c\u5f53\u524d\u67b6\u6784\u4e2d\uff0c\u6240\u6709\u7684\u670d\u52a1(microservice)\u5168\u90e8\u901a\u8fc7gRPC\u8fde\u63a5\u5728\u4e00\u8d77\u3002 http\/2\u652f\u6301stream multiplex\uff0c\u5373\u53ef\u4ee5\u5728\u540c\u4e00\u6761TCP\u8fde\u63a5\u4e0a\uff0c\u4f20\u8f93\u591a\u4e2astream(1:N)\uff0cstream\u6982\u5ff5\u80fd\u591f\u975e\u5e38\u76f4\u89c2\u76841:1\u6620\u5c04\u73a9\u5bb6\u53cc\u5411\u6570\u636e\u6d41\u3002<\/p>\n<p>(<strong>\u8bf7\u7279\u522b\u6ce8\u610f\u4e00\u70b9:<\/strong>\u00a0HTTP\/2\u4ec5\u7528\u4e8e\u670d\u52a1\u5668\u5404\u4e2a\u670d\u52a1\u95f4\u7684\u5185\u90e8\u901a\u4fe1\uff0c\u548c\u5ba2\u6237\u7aef\u7684\u901a\u4fe1\u662f\u81ea\u5b9a\u4e49\u534f\u8bae\uff0c\u4f4d\u4e8e\uff1ahttps:\/\/github.com\/gonet2\/tools\/tree\/master\/proto_scripts)<\/p>\n<p>\u9644: HTTP\/2 \u5e27\u5c01\u88c5<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">+-----------------------------------------------+\r\n|                 Length (24)                   |\r\n+---------------+---------------+---------------+\r\n|   Type (8)    |   Flags (8)   |\r\n+-+-------------+---------------+-------------------------------+\r\n|R|                 Stream Identifier (31)                      |\r\n+=+=============================================================+\r\n|                   Frame Payload (0...)                      ...\r\n+---------------------------------------------------------------+\r\n\r\n                      Figure 1: Frame Layout<\/pre>\n<h2 id=\"section-2\">\u57fa\u672c\u670d\u52a1\u6a21\u578b<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">             +\r\n             |\r\n             |\r\n             +----&gt; game1\r\n             |\r\nagent1+------&gt;\r\n             |\r\n             +----&gt; game2\r\n             |                +\r\nagent2+------&gt;                +-----&gt; snowflake\r\n             |                |\r\n             +----&gt; game3+----&gt;\r\n             |                |\r\n             |                +-----&gt; chat\r\n             ++               |\r\n                              +-----&gt; rank\r\n                              +<\/pre>\n<p>\u4f7f\u7528\u65b9\u5f0f\u5047\u5b9a\u4e3a\uff1a<\/p>\n<ol>\n<li>\u524d\u7aef\u7528\u4e24\u4e2a\u90e8\u7f72\u5728\u4e0d\u540c\u7269\u7406\u670d\u52a1\u5668\u4e0a\u7684agent\u670d\u52a1\u63a5\u5165\uff0c\u65e0\u72b6\u6001\uff0c\u5ba2\u6237\u7aef\u968f\u673a\u8bbf\u95ee\u4efb\u610f\u4e00\u53f0agent\u63a5\u5165\uff0c\u6bd4\u5982\u4f7f\u7528DNS round-robin\u65b9\u5f0f\u8fde\u63a5\u3002<\/li>\n<li>agent\u548cauth\u914d\u5408\u5904\u7406\u5b8c\u9274\u6743\u7b49\u5de5\u4f5c\u540e\uff0c\u6570\u636e\u5305\u900f\u4f20\u8fdb\u5165game\u8fdb\u884c\u903b\u8f91\u5904\u7406\u3002\u5982\u679c\u6709\u591a\u53f0game\u670d\u52a1\u5668\uff0c\u90a3\u4e48\u7528\u6237\u9700\u8981\u6307\u5b9a\u4e00\u4e2a\u6620\u5c04\u5173\u7cfb(userid-&gt;server_id)\uff0c\u7528\u6765\u5c06\u73a9\u5bb6\u56fa\u5b9a\u8054\u5165\u67d0\u53f0game\u670d\u52a1\u5668\u3002<\/li>\n<li>game\u548c\u5404\u4e2a\u72ec\u7acbservice\u901a\u4fe1\uff0c\u914d\u5408\u5904\u7406\u903b\u8f91\u3002service\u5982\u679c\u662f\u65e0\u72b6\u6001\u7684\uff0c\u9ed8\u8ba4\u91c7\u7528round-robin\u65b9\u5f0f\u8bf7\u6c42\u670d\u52a1\uff0c\u5982\u679c\u662f\u5e26\u72b6\u6001\u7684\uff0c\u5219\u6839\u636e\u6807\u8bc6\u8054\u5165\u6307\u5b9a\u670d\u52a1\u5668\u3002<\/li>\n<\/ol>\n<p>\u5177\u4f53\u7684\u670d\u52a1\u63cf\u8ff0\u4ee5\u53ca\u4f7f\u7528\u6848\u4f8b\uff0c\u8bf7\u8fdb\u5165\u5404\u4e2a\u76ee\u5f55\u4e2d\u9605\u8bfb\u3002<\/p>\n<h2 id=\"gonet2\">\u5b9e\u9645\u9879\u76ee\u4e2d\u600e\u4e48\u4f7f\u7528gonet\/2?<\/h2>\n<p>clone\u4e0b\u6765\u6162\u6162\u6539\uff0c\u4e0d\u63d0\u4f9b\u63d2\u4ef6\u63a5\u53e3\u5f0f\u7684\u53ef\u5347\u7ea7\u6a21\u5757\uff0cgonet\/2\u53ea\u63d0\u4f9b\u5173\u952e\u901a\u8def\u548cdemo\uff0c\u6211\u4e0d\u60f3\u505a\u4e00\u4e2a\u4fb5\u5165\u5f0f\u7684\u9aa8\u67b6\uff0c\u53ea\u60f3\u5728\u67b6\u6784\u5c42\u9762\u63d0\u4f9b\u4e00\u4e2a\u6211\u8ba4\u4e3a\u6bd4\u8f83\u4f18\u79c0\u7684\u601d\u8def\u5e76\u5728\u6b64\u57fa\u7840\u4e0a\u52aa\u529b\u505a\u5230\u6574\u4f53\u6700\u4f18\u3002<\/p>\n<h2 id=\"section-3\">\u6a21\u5757\u5212\u5206<\/h2>\n<p>\u8fdb\u5165\u6bcf\u4e2a\u670d\u52a1\u9605\u8bfb\u5bf9\u5e94\u6587\u6863<br \/>\n1.\u00a0<a href=\"https:\/\/github.com\/gonet2\/agent\">agent<\/a>: \u7f51\u5173<br \/>\n2.\u00a0<a href=\"https:\/\/github.com\/gonet2\/game\">game<\/a>: \u6e38\u620f\u903b\u8f91<br \/>\n3.\u00a0<a href=\"https:\/\/github.com\/gonet2\/snowflake\">snowflake<\/a>: UUID\u53d1\u751f\u5668<\/p>\n<h2 id=\"section-4\">\u6a21\u5757\u8bbe\u8ba1\u7ea6\u5b9a<\/h2>\n<ol>\n<li><strong>\u96f6<\/strong>\u914d\u7f6e\uff0c\u914d\u7f6e\u96c6\u4e2d\u5316\u5230coordinator(etcd\/consul)\uff0c\u5373\uff1a\/etc distributed\u6982\u5ff5\u3002<\/li>\n<li><strong>\u7406\u8bba\u4e0a<\/strong>\uff0c\u552f\u4e00\u53ef\u80fd\u9700\u8981\u7684\u914d\u7f6e\u4e3aETCD_HOST\u73af\u5883\u53d8\u91cf\uff0c\u7528\u4e8e\u6307\u5b9aETCD\u5730\u5740\u3002<\/li>\n<li>\u5176\u4ed6\u6a21\u5757\u7279\u5b9a\u7684\u53c2\u6570(SERVER_ID\u4ec0\u4e48\u7684)\uff0c\u4e5f\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u6307\u5b9a\uff0cdocker\u80fd\u65b9\u4fbf\u7684\u8bbe\u5b9a\u3002<\/li>\n<\/ol>\n<h2 id=\"section-5\">\u65e5\u5fd7\u5206\u6790\u6a21\u578b<\/h2>\n<p><img decoding=\"async\" src=\"http:\/\/gonet2.github.io\/log.png\" alt=\"loganalyticmodel\" \/><\/p>\n<p>\u65e5\u5fd7\u5206\u6790\u662f\u901a\u5f80\u6570\u636e\u9a71\u52a8\u7684\u5173\u952e\u6b65\u9aa4\uff0c\u5185\u5bb9\u8fc7\u4e8e\u5e9e\u5927\uff0c\u6682\u7559\u7ec4\u5efa\u56fe\u4e8e\u6b64\uff0c\u6709\u673a\u4f1a\u518d\u8be6\u8c08\u3002<\/p>\n<h2 id=\"section-6\">\u57fa\u7840\u8bbe\u65bd<\/h2>\n<p><img decoding=\"async\" src=\"http:\/\/gonet2.github.io\/design.png\" alt=\"design\" \/><\/p>\n<p>\u672f\u8bed\uff1a<\/p>\n<ol>\n<li>coordinator \u2013 zk, etcd\u8fd9\u79cd\u5206\u5e03\u5f0f\u4e00\u81f4\u6027\u670d\u52a1\u3002<\/li>\n<li>message backbone \u2013 \u670d\u52a1\u5668\u4ef6\u6d88\u606f\u603b\u7ebf\uff0c\u901a\u5e38\u4e3apub\/sub\u6a21\u5f0f\uff0c\u6570\u636e\u5bc6\u96c6\u3002<\/li>\n<\/ol>\n<p>\u57fa\u7840\u8bbe\u65bd\u662f\u7528\u4e8e\u652f\u6491\u6574\u4e2a\u67b6\u6784\u7684\u57fa\u77f3\u3002<\/p>\n<h2 id=\"section-7\">\u793e\u533a<\/h2>\n<p>QQ\u7fa4: 459420581<\/p>\n<h2 id=\"section-8\">\u94fe\u63a5<\/h2>\n<ul>\n<li><a href=\"https:\/\/github.com\/en\/libunity\">gonet\/2 unity \u5ba2\u6237\u7aef\u7f51\u7edc\u5e93<\/a>\u00a0\u2013 by ycs<\/li>\n<li><a href=\"http:\/\/blog.csdn.net\/q26335804\/article\/category\/5726691\">Gonet2\u6e38\u620f\u670d\u52a1\u5668\u6846\u67b6\u89e3\u6790<\/a>\u00a0\u2013 by \u9ad8<\/li>\n<li><a href=\"https:\/\/github.com\/tenywen\/share\">grpc,nsq\u7b49\u6e90\u7801\u5206\u6790<\/a>\u00a0\u2013 by tenywen<\/li>\n<li>[Protobuf\u5b89\u88c5] (http:\/\/ivecode.blog.163.com\/blog\/static\/22094902020156225235159\/) \u2013 by __IveCode<\/li>\n<\/ul>\n<p>PS. \u611f\u8c22\u70ed\u5fc3\u7f51\u53cb\u5bf9\u6e90\u7801\u7684\u89e3\u8bfb<\/p>\n<h2 id=\"section-9\">\u8d44\u6599<\/h2>\n<ul>\n<li>protobuf: https:\/\/github.com\/google\/protobuf<\/li>\n<li>protobuf golang plugin: https:\/\/github.com\/golang\/protobuf<\/li>\n<li>grpc: http:\/\/grpc.io<\/li>\n<li>http\/2: http:\/\/http2.github.io\/<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u7f51\u5740\uff1ahttp:\/\/gonet2.git<\/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":[],"tags":[122],"class_list":["post-2896","post","type-post","status-publish","format-standard","hentry","tag-06-godocker"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/2896","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=2896"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/2896\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=2896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=2896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=2896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}