{"id":1220,"date":"2018-10-26T12:44:21","date_gmt":"2018-10-26T12:44:21","guid":{"rendered":""},"modified":"2018-10-26T20:44:45","modified_gmt":"2018-10-26T12:44:45","slug":"sentinel%e6%89%a9%e5%b1%95%e6%80%a7%e8%ae%be%e8%ae%a1%e6%9c%ba%e5%88%b6%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"http:\/\/www.szryc.com\/?p=1220","title":{"rendered":"Sentinel\u6269\u5c55\u6027\u8bbe\u8ba1\u673a\u5236\u5206\u6790"},"content":{"rendered":"
\n\t\u3000\u3000Senti<\/u>nel \u63d0\u4f9b\u591a\u6837\u7684 SPI<\/u> \u63a5\u53e3\u7528\u4e8e\u63d0\u4f9b\u6269\u5c55\u7684\u80fd\u529b\u3002\u7528\u6237\u53ef\u4ee5\u5728\u7528\u540c\u4e00\u4e2a sentinel-core \u7684\u57fa\u7840\u4e0a\u81ea\u884c\u6269\u5c55\u63a5\u53e3\u5b9e\u73b0\uff0c\u4ece\u800c\u53ef\u4ee5\u65b9\u4fbf\u5730\u7ed9 Sentinel \u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u903b\u8f91\u3002 \u521d\u59cb\u5316\u903b\u8f91\u6269\u5c55\u673a\u5236 \u4e3a\u4e86\u7edf\u4e00\u521d\u59cb\u5316\u7684\u6d41\u7a0b\uff0c\u6211\u4eec\u62bd\u8c61\u51fa\u4e86 InitFunc \u63a5\u53e3\u4ee3\u8868 Sentinel \u7684\u4e00\u4e9b\u521d\u59cb\u5316\u903b\u8f91\uff0c\u5982\uff1a \u6ce8\u518c\u52a8\u6001\u89c4\u5219\u6e90\uff08\u793a\u4f8b\uff09 \u6ce8\u518c StatisticSlot \u56de\u8c03\u51fd\u6570\uff08\u793a\u4f8b\uff09 \u542f\u52a8 Command Cente<\/u>r \u521d\u59cb\u5316\u5fc3\u8df3\u53d1\u9001 \u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6ce8\u89e3\u8bbe\u7f6e InitFunc \u6267\u884c\u7684\u4f18\u5148\u7ea7\u3002<\/p>\n
\n\t\u3000\u3000Sentinel \u63d0\u4f9b\u591a\u6837\u7684 SPI \u63a5\u53e3\u7528\u4e8e\u63d0\u4f9b\u6269\u5c55\u7684\u80fd\u529b\u3002\u7528\u6237\u53ef\u4ee5\u5728\u7528\u540c\u4e00\u4e2a sentinel-core \u7684\u57fa\u7840\u4e0a\u81ea\u884c\u6269\u5c55\u63a5\u53e3\u5b9e\u73b0\uff0c\u4ece\u800c\u53ef\u4ee5\u65b9\u4fbf\u5730\u7ed9 Sentinel \u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u903b\u8f91\u3002<\/p>\n
\n\t\u3000\u3000\u521d\u59cb\u5316\u903b\u8f91\u6269\u5c55\u673a\u5236<\/p>\n
\n\t\u3000\u3000\u4e3a\u4e86\u7edf\u4e00\u521d\u59cb\u5316\u7684\u6d41\u7a0b\uff0c\u6211\u4eec\u62bd\u8c61\u51fa\u4e86 InitFunc \u63a5\u53e3\u4ee3\u8868 Sentinel \u7684\u4e00\u4e9b\u521d\u59cb\u5316\u903b\u8f91\uff0c\u5982\uff1a<\/p>\n
\n\t\u3000\u3000\u6ce8\u518c\u52a8\u6001\u89c4\u5219\u6e90\uff08\u793a\u4f8b\uff09<\/p>\n
\n\t\u3000\u3000\u6ce8\u518c StatisticSlot \u56de\u8c03\u51fd\u6570\uff08\u793a\u4f8b\uff09<\/p>\n
\n\t\u3000\u3000\u542f\u52a8 Command Center<\/p>\n
\n\t\u3000\u3000\u521d\u59cb\u5316\u5fc3\u8df3\u53d1\u9001<\/p>\n
\n\t\u3000\u3000\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6ce8\u89e3\u8bbe\u7f6e InitFunc \u6267\u884c\u7684\u4f18\u5148\u7ea7\u3002\u5f53\u5e94\u7528\u9996\u6b21\u8bbf\u95ee\u8d44\u6e90\u65f6\uff0c\u6ce8\u518c\u7684\u521d\u59cb\u5316\u51fd\u6570\u4f1a\u4f9d\u6b21\u6267\u884c\u3002\u82e5\u5e0c\u671b\u624b\u52a8\u63d0\u524d\u89e6\u53d1\u521d\u59cb\u5316\uff0c\u53ef\u4ee5\u5728\u76f8\u5e94\u7684\u4f4d\u7f6e\uff08\u5982 Spring Bean\uff09\u8c03\u7528 InitExecutor.doInit\uff08\uff09 \u51fd\u6570\uff0c\u91cd\u590d\u8c03\u7528\u53ea\u4f1a\u6267\u884c\u4e00\u6b21\u3002<\/p>\n
\n\t\u3000\u3000Slot Chai<\/u>n \u6269\u5c55\u673a\u5236<\/p>\n
\n\t\u3000\u3000Sentinel \u5185\u90e8\u662f\u901a\u8fc7\u4e00\u7cfb\u5217\u7684 slot \u7ec4\u6210\u7684 slot chain \u6765\u5b8c\u6210\u5404\u79cd\u529f\u80fd\u7684\uff0c\u5305\u62ec\u6784\u5efa\u8c03\u7528\u94fe\u3001\u8c03\u7528\u6570\u636e\u7edf\u8ba1\u3001\u89c4\u5219\u68c0\u67e5\u7b49\u3002\u5404\u4e2a slot \u4e4b\u95f4\u7684\u987a\u5e8f\u975e\u5e38\u91cd\u8981\u3002Sentinel \u5c06 SlotChainBuilder \u4f5c\u4e3a SPI \u63a5\u53e3\u8fdb\u884c\u6269\u5c55\uff0c\u4f7f\u5f97 Slot Chain \u5177\u5907\u4e86\u6269\u5c55\u7684\u80fd\u529b\u3002\u7528\u6237\u53ef\u4ee5\u81ea\u884c\u52a0\u5165\u81ea\u5b9a\u4e49\u7684 slot \u5e76\u7f16\u6392 slot \u95f4\u7684\u987a\u5e8f\uff0c\u4ece\u800c\u53ef\u4ee5\u7ed9 Sentinel \u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u529f\u80fd\u3002<\/p>\n
\n\t\u3000\u3000<\/p>\n
\n\t\u3000\u3000\u6bd4\u5982\u6211\u4eec\u60f3\u8981\u5728\u8bf7\u6c42 pass \u540e\u8bb0\u5f55\u5f53\u524d\u7684 context \u548c\u8d44\u6e90\u4fe1\u606f\uff0c\u5219\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684 slot\uff1a<\/p>\n
\n\t\u3000\u3000<\/p>\n
\n\t\u3000\u3000\u7136\u540e\u5b9e\u73b0\u4e00\u4e2a SlotChainBuilder\uff0c\u53ef\u4ee5\u5728 DefaultSlotChainBuilder \u7684\u57fa\u7840\u4e0a\u5c06\u6211\u4eec\u65b0\u7684 slot \u6dfb\u52a0\u5230\u94fe\u7684\u5c3e\u90e8\uff08\u5f53\u7136\u4e5f\u53ef\u4ee5\u4e0d\u7528 DefaultSlotChainBuilder\uff0c\u81ea\u7531\u7ec4\u5408\u73b0\u6709\u7684 slot\uff09\uff1a<\/p>\n
\n\t\u3000\u3000<\/p>\n
\n\t\u3000\u3000\u6700\u540e\u5728 resources\/META-INF\/services \u76ee\u5f55\u4e0b\u7684 SPI \u914d\u7f6e\u6587\u4ef6 com.alibaba.csp.sentinel.slotchain.SlotChainBuilder \u4e2d\u6dfb\u52a0\u4e0a\u5b9e\u73b0\u7684 SlotChainBuilder \u7684\u7c7b\u540d\u5373\u53ef\u751f\u6548\uff1a<\/p>\n
\n\t\u3000\u3000# Custom slot chain builder<\/p>\n
\n\t\u3000\u3000com.alibaba.csp.sentinel.demo.slot.DemoSlotChainBuilder<\/p>\n
\n\t\u3000\u3000Sentinel \u7684\u70ed\u70b9\u9650\u6d41\u6a21\u5757\u5c31\u662f\u5229\u7528\u4e86 Slot Chain \u7684\u6269\u5c55\u673a\u5236\u6765\u5c06\u70ed\u70b9\u9650\u6d41\u529f\u80fd\u6dfb\u52a0\u5230\u539f\u6709\u7684\u529f\u80fd\u94fe\u4e2d\u3002<\/p>\n
\n\t\u3000\u3000StatisticSlot Callback<\/p>\n
\n\t\u3000\u3000\u4e4b\u524d StatisticSlot \u91cc\u9762\u5305\u542b\u4e86\u592a\u591a\u7684\u903b\u8f91\uff0c\u50cf\u666e\u901a QPS \u548c \u70ed\u70b9\u53c2\u6570 QPS \u7684 addPass\/addBlock \u7b49\u903b\u8f91\u7edf\u8ba1\u90fd\u5728 StatisticSlot \u91cc\u9762\uff0c\u5404\u4e2a\u903b\u8f91\u90fd\u6742\u7cc5\u5728\u4e00\u8d77\uff0c\u4e0d\u5229\u4e8e\u6269\u5c55\u3002\u56e0\u6b64\u6709\u5fc5\u8981\u4e3a StatisticSlot \u62bd\u8c61\u51fa\u4e00\u7cfb\u5217\u7684 callback\uff0c\u4ece\u800c\u4f7f StatisticSlot \u5177\u5907\u57fa\u672c\u7684\u6269\u5c55\u80fd\u529b\uff0c\u5e76\u5c06\u4e00\u7cfb\u5217\u7684\u903b\u8f91\u4ece StatisticSlot \u89e3\u8026\u51fa\u6765\uff0c\u66f4\u4e3a\u6e05\u6670\u3002\u76ee\u524d Sentinel \u63d0\u4f9b\u4e86\u4e24\u79cd callback\uff1a<\/p>\n
\n\t\u3000\u3000ProcessorS<\/u>lotEntryCallback\uff1a\u5305\u542b onPass \u548c onBlocked \u4e24\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5206\u522b\u5bf9\u5e94\u8bf7\u6c42\u901a\u8fc7 StatisticSlot \u548c\u8bf7\u6c42\u88ab blocked \u7684\u65f6\u5019\u6267\u884c\u3002<\/p>\n
\n\t\u3000\u3000ProcessorSlotExitCallback\uff1a\u5305\u542b onExit \u56de\u8c03\u51fd\u6570\uff0c\u5f53\u8bf7\u6c42\u7ecf StatisticSlot exit \u7684\u65f6\u5019\u6267\u884c\u3002<\/p>\n
\n\t\u3000\u3000\u7528\u6237\u53ea\u9700\u5c06\u5b9e\u73b0\u7684 callback \u6ce8\u518c\u5230 StatisticSlotCallbackRegistry \u5373\u53ef\u751f\u6548\u3002<\/p>\n
\n\t\u3000\u3000\u52a8\u6001\u89c4\u5219\u6e90<\/p>\n
\n\t\u3000\u3000Sentinel \u7684 \u52a8\u6001\u89c4\u5219\u6570\u636e\u6e90 \u7528\u4e8e\u4ece\u5916\u90e8\u7684\u5b58\u50a8\u4e2d\u8bfb\u53d6\u53ca\u5199\u5165\u89c4\u5219\u3002Sentinel \u5c06\u52a8\u6001\u89c4\u5219\u6570\u636e\u6e90\u5212\u5206\u4e3a\u4e24\u79cd\u7c7b\u578b\uff1a\u8bfb\u6570\u636e\u6e90\uff08ReadableDataSource\uff09\u548c\u5199\u6570\u636e\u6e90\uff08WritableDataSource\uff09\uff0c\u4ece\u800c\u4f7f\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u6e90\u804c\u8d23\u66f4\u52a0\u6e05\u6670\uff1a<\/p>\n
\n\t\u3000\u3000\u8bfb\u6570\u636e\u6e90\u4ec5\u8d1f\u8d23\u76d1\u542c\u6216\u8f6e\u8be2\u8bfb\u53d6\u8fdc\u7a0b\u5b58\u50a8\u7684\u53d8\u66f4\u3002<\/p>\n
\n\t\u3000\u3000\u5199\u6570\u636e\u6e90\u4ec5\u8d1f\u8d23\u5c06\u89c4\u5219\u53d8\u66f4\u5199\u5165\u5230\u89c4\u5219\u6e90\u4e2d\u3002<\/p>\n
\n\t\u3000\u3000\u6211\u4eec\u53ea\u9700\u8981\u81ea\u5df1\u5b9e\u73b0\u52a8\u6001\u89c4\u5219\u6e90\uff0c\u7136\u540e\u5c06\u5176\u6ce8\u518c\u81f3\u5bf9\u5e94\u7684 RuleManager \u4e0a\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5b9e\u65f6\u5730\u914d\u7f6e\u89c4\u5219\u5e76\u8fdb\u884c\u62c9\u53d6\/\u63a8\u9001\u4e86\u3002\u6ce8\u518c\u52a8\u6001\u89c4\u5219\u6e90\u65f6\u53ef\u4ee5\u501f\u52a9 Sentinel \u7684 InitFunc SPI \u5728\u521d\u59cb\u5316\u65f6\u81ea\u52a8\u6ce8\u518c\u3002<\/p>\n
\n\t\u3000\u3000Transport \u6269\u5c55\u673a\u5236<\/p>\n
\n\t\u3000\u3000CommandCenter \u53ef\u6269\u5c55\uff1a\u7528\u6237\u53ef\u4ee5\u7528\u4e0d\u540c\u7684\u7f51\u7edc\u534f\u8bae\u6216\u4e0d\u540c\u7684\u5e93\u6765\u5b9e\u73b0 Transport API Server\u3002<\/p>\n
\n\t\u3000\u3000HeartbeatSender \u53ef\u6269\u5c55\uff1a\u7528\u6237\u53ef\u4ee5\u7528\u4e0d\u540c\u7684\u7f51\u7edc\u534f\u8bae\u548c\u5fc3\u8df3\u7b56\u7565\u6765\u5b9e\u73b0\u5fc3\u8df3\u53d1\u9001\uff08\u4e0a\u62a5\u5230\u63a7\u5236\u53f0\uff09\u3002<\/p>\n
\n\t\u3000\u3000CommandHandler \u53ef\u6269\u5c55\uff1a\u7528\u6237\u53ef\u4ee5\u81ea\u884c\u5b9e\u73b0 CommandHandler \u5e76\u6ce8\u518c\u5230 SPI \u914d\u7f6e\u6587\u4ef6\u4e2d\u6765\u4e3a CommandCenter \u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u547d\u4ee4\u3002<\/p>\n
\n\t\u3000\u3000\u4f5c\u8005\uff1a\u4e91\u6816\u793e\u533a \u4e2d\u95f4\u4ef6\u5c0f\u54e5<\/p>\n","protected":false},"excerpt":{"rendered":"
Sen ti nel \u63d0\u4f9b\u591a\u6837\u7684 S PI \u63a5\u53e3\u7528\u4e8e\u63d0\u4f9b\u6269\u5c55\u7684\u80fd\u529b\u3002\u7528\u6237\u53ef\u4ee5\u5728\u7528\u540c\u4e00\u4e2a sentinel-core \u7684\u57fa\u7840\u4e0a\u81ea\u884c\u6269\u5c55\u63a5\u53e3\u5b9e\u73b0\uff0c\u4ece\u800c\u53ef\u4ee5\u65b9\u4fbf\u5730\u7ed9 Sentinel \u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u903b\u8f91\u3002 \u521d\u59cb\u5316\u903b\u8f91\u6269\u5c55\u673a\u5236 \u4e3a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"_links":{"self":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts\/1220"}],"collection":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1220"}],"version-history":[{"count":0,"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts\/1220\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1220"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}