{"id":19341,"date":"2024-10-24T10:42:04","date_gmt":"2024-10-24T02:42:04","guid":{"rendered":"https:\/\/www.yunshan.net\/blog\/?p=19341"},"modified":"2024-10-24T10:42:04","modified_gmt":"2024-10-24T02:42:04","slug":"ebpf-%e9%9b%b6%e4%be%b5%e6%89%b0%e5%88%86%e5%b8%83%e5%bc%8f%e8%bf%bd%e8%b8%aa-3-%e5%88%86%e9%92%9f%e9%94%81%e5%ae%9a-java-%e7%a8%8b%e5%ba%8f-i-o-%e7%ba%bf%e7%a8%8b%e9%98%bb%e5%a1%9e","status":"publish","type":"post","link":"https:\/\/www.yunshan.net\/blog\/archives\/19341.html","title":{"rendered":"eBPF \u96f6\u4fb5\u6270\u5206\u5e03\u5f0f\u8ffd\u8e2a 3 \u5206\u949f\u9501\u5b9a Java \u7a0b\u5e8f I\/O \u7ebf\u7a0b\u963b\u585e"},"content":{"rendered":"\n\t\t\t\t<![CDATA[\n<p>\u6458\u8981\uff1aI\/O \u7ebf\u7a0b\u963b\u585e\u662fJava \u7a0b\u5e8f\u7ecf\u5e38\u51fa\u73b0\u7684\u95ee\u9898\u4e4b\u4e00\uff0c\u6b64\u7c7b\u6545\u969c\u53d1\u751f\u65f6 Java \u7a0b\u5e8f\u7684\u8bf7\u6c42\u3001\u54cd\u5e94\u5728 I\/O \u7ebf\u7a0b\u5411\u64cd\u4f5c\u7cfb\u7edf Socket Buffer \u8bfb\/\u5199\u8fc7\u7a0b\u4e2d\u53d1\u751f\u963b\u585e\uff0c\u7531\u4e8e\u5728\u4e1a\u52a1\u4ee3\u7801\u63d2\u6869\u65e0\u6cd5\u89c2\u6d4b\u5230 I\/O \u7ebf\u7a0b\u7684\u5de5\u4f5c\u60c5\u51b5\u548c\u6027\u80fd\u8868\u73b0\uff0c\u56e0\u800c\u5bfc\u81f4\u6545\u969c\u975e\u5e38\u9690\u853d\u548c\u96be\u4ee5\u8bca\u65ad\u5b9a\u4f4d\u3002\u901a\u8fc7\u672c\u7bc7\u6848\u4f8b\u60a8\u5c06\u4e86\u89e3\u5230\uff0c\u67d0\u94f6\u884c\u7684\u5f00\u53d1\u5de5\u7a0b\u5e08\u5982\u4f55\u4f7f\u7528 eBPF \u6280\u672f\u5e26\u6765\u7684\u96f6\u4fb5\u6270\u8ffd\u8e2a\u80fd\u529b\uff0c\u5728\u67d0\u6b21\u5206\u5e03\u5f0f\u6838\u5fc3\u4ea4\u6613\u7cfb\u7edf\u4e0a\u7ebf\u4fe1\u521b\u5e73\u53f0\u7684\u975e\u529f\u80fd\u6d4b\u8bd5\uff08\u6027\u80fd\u538b\u6d4b\uff09\u6545\u969c\u8bca\u65ad\u4e2d\uff0c\u7528 3 \u5206\u949f\u65f6\u95f4\u9501\u5b9a Java \u7a0b\u5e8f I\/O \u7ebf\u7a0b\u963b\u585e\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>01\uff5c\u6545\u969c\u80cc\u666f<\/strong><\/h2>\n\n\n\n<p>\u8fd1\u671f\uff0c<strong>\u67d0\u94f6\u884c<\/strong>\u7684<strong>\u5206\u5e03\u5f0f\u6838\u5fc3\u4ea4\u6613\u7cfb\u7edf<\/strong>&nbsp;XX \u4e2d\u5fc3\u4e1a\u52a1\u6309\u8ba1\u5212\u5373\u5c06\u4e0a\u7ebf<strong>\u534e\u4e3a\u4fe1\u521b\u4e91<\/strong>\uff0c\u4f46\u5728\u4e0a\u7ebf\u524d\u7684\u975e\u529f\u80fd\u6d4b\u8bd5\uff08\u6027\u80fd\u538b\u6d4b\uff09\u8fc7\u7a0b\u4e2d\uff0c<strong>\u4e1a\u52a1\u54cd\u5e94\u65f6\u5ef6\u4e0d\u5b9a\u65f6\u52a3\u5316<\/strong>\uff0c\u539f\u56e0\u4e0d\u660e\u3002<\/p>\n\n\n\n<p>XX \u4e2d\u5fc3\u7684\u4e1a\u52a1\u7a0b\u5e8f\u4f7f\u7528 Java \u8bed\u8a00\u5f00\u53d1\uff08SOFARPC \u6846\u67b6\uff09\uff0c\u91c7\u7528 Netty \u4f5c\u4e3a\u7f51\u7edc\u6846\u67b6\uff0c\u8be5\u4e1a\u52a1\u6d41\u7a0b\u6d89\u53ca&nbsp;<code>Client<\/code>\u3001<code>Gateway<\/code>\u3001<code>App-1<\/code>\u3001<code>App-2<\/code>\uff0c\u7aef\u5230\u7aef\u4e1a\u52a1\u8bbf\u95ee\u8def\u5f84\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>1\uff09<code>Client<\/code>&nbsp;\u4f7f\u7528 SOFARPC \u534f\u8bae\u8bbf\u95ee&nbsp;<code>Gateway<\/code>&nbsp;\u7684\u63a5\u53e3\uff1b<\/li><li>2\uff09<code>Gateway<\/code>&nbsp;\u7ecf\u8fc7\u4e03\u5c42\u8d1f\u8f7d\u5747\u8861\u5c06 SOFARPC \u534f\u8bae\u7684 Request \u8f6c\u53d1\u81f3\u67d0\u4e2a&nbsp;<code>App-1<\/code>\uff1b<\/li><li>3\uff09<code>App-1<\/code>&nbsp;\u8bbf\u95ee&nbsp;<code>App-2<\/code>\u3002<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.yunshan.net\/blog\/wp-content\/uploads\/2024\/10\/01-3-1024x643.png\" alt=\"\" class=\"wp-image-19342\"\/><figcaption>\u4e1a\u52a1\u6d41\u7a0b\u53ca DeepFlow \u89c2\u6d4b\u70b9<\/figcaption><\/figure>\n\n\n\n<p>DeepFlow \u901a\u8fc7 eBPF \u4ee5<strong>\u96f6\u4fb5\u6270<\/strong>\u7684\u65b9\u5f0f\u5bf9<strong>\u6bcf\u4e00\u6b21\u8bf7\u6c42<\/strong>\u7ecf\u8fc7<strong>\u6bcf\u4e00\u4e2a\u4f4d\u7f6e<\/strong>\u65f6\uff08 \u89c2\u6d4b\u70b9 1~8 \uff09\u7684\u6027\u80fd\u8fdb\u884c<strong>\u5168\u94fe\u8def<\/strong>\u91c7\u96c6\u548c\u89c2\u6d4b\uff0c\u6574\u4e2a\u8fc7\u7a0b\u5bf9\u5e94\u7528\u7a0b\u5e8f<strong>\u65e0\u9700\u642c\u8fd0\u6216\u6ce8\u5165\u4ee3\u7801<\/strong>\uff0c\u4e5f<strong>\u65e0\u9700\u4efb\u4f55\u91cd\u542f\u64cd\u4f5c<\/strong>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>02\uff5c\u6545\u969c\u8bca\u65ad<\/strong><\/h2>\n\n\n\n<p>\u5728 DeepFlow \u53ef\u89c2\u6d4b\u6027\u5e73\u53f0\u4f7f\u7528 \u201c<strong>5W \u65b9\u6cd5<\/strong>\u201d \u5bf9\u6545\u969c\u5feb\u901f\u8bca\u65ad\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.yunshan.net\/blog\/wp-content\/uploads\/2024\/10\/02-2-1024x489.png\" alt=\"\" class=\"wp-image-19343\"\/><figcaption>\u6545\u969c\u8bca\u65ad\u7684 \u201c5W \u65b9\u6cd5\u201d<\/figcaption><\/figure>\n\n\n\n<p>\u4ec0\u4e48\u662f \u201c<strong>5W \u65b9\u6cd5<\/strong>\u201d\uff1f<\/p>\n\n\n\n<p>\u4ece\u5b8f\u89c2\u5230\u5fae\u89c2\u6709\u5e8f\u8c03\u9605\u53ef\u89c2\u6d4b\u6027\u6570\u636e\uff0c\u9010\u6b65\u56de\u7b54\u5982\u4e0b 5 \u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u5feb\u901f\u3001\u6709\u6548\u8bca\u65ad\u51fa\u95ee\u9898\u6839\u56e0\uff0c\u79f0\u4e4b\u4e3a\u201c<strong>5W \u65b9\u6cd5<\/strong>\u201d\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Who<\/strong>&nbsp;is in trouble?<\/li><li><strong>When<\/strong>&nbsp;is it in trouble?<\/li><li><strong>Which<\/strong>&nbsp;request is in trouble?<\/li><li><strong>Where<\/strong>&nbsp;is the root position?<\/li><li><strong>What<\/strong>&nbsp;is the root cause?<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong> 1. \u786e\u5b9a\u9996\u4e2a\u89c2\u6d4b\u5bf9\u8c61<\/strong><\/h3>\n\n\n\n<p>\u6545\u969c\u8bca\u65ad\u7684<strong>\u7b2c\u4e00\u6b65<\/strong>\uff0c\u9996\u5148\u8981\u56de\u7b54 \u201c<strong>Who is in trouble<\/strong>\u201d \u7684\u95ee\u9898\uff0c\u4ece\u800c\u786e\u5b9a\u9996\u4e2a\u89c2\u6d4b\u7684\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p>\u6b64\u6b21\u6027\u80fd\u538b\u6d4b\u7684\u6545\u969c\u8bca\u65ad\u573a\u666f\u4e2d\uff0c\u5df2\u660e\u786e\u77e5\u9053&nbsp;<code>Gateway \u2014\u2014&gt; App-1<\/code>&nbsp;\u8def\u5f84\u7684\u54cd\u5e94\u65f6\u5ef6\u5b58\u5728\u5f02\u5e38\uff0c\u56e0\u6b64\u5c06\u5176\u4f5c\u4e3a\u9996\u4e2a\u89c2\u6d4b\u5bf9\u8c61\uff0c\u5728 DeepFlow \u7684\u300c\u8ffd\u8e2a\u300d-\u300c\u8def\u5f84\u5206\u6790\u300d\u529f\u80fd\u5165\u53e3\u68c0\u7d22\u8be5\u8def\u5f84\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.yunshan.net\/blog\/wp-content\/uploads\/2024\/10\/03-2-1024x500.png\" alt=\"\" class=\"wp-image-19344\"\/><figcaption>Who is in trouble?<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong> 2. RED \u6307\u6807\u76d1\u63a7\uff0c\u627e\u51fa\u65f6\u95f4\u70b9<\/strong><\/h3>\n\n\n\n<p>\u6545\u969c\u8bca\u65ad\u7684<strong>\u7b2c\u4e8c\u6b65<\/strong>\uff0c\u8981\u56de\u7b54 \u201c<strong>When is it in trouble<\/strong>\u201d \u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u6253\u5f00&nbsp;<code>Gateway \u2014\u2014&gt; App-1<\/code>&nbsp;\u8def\u5f84\u7684\u300c\u53f3\u6ed1\u7a97\u300d\uff0c\u5728\u5176\u4e2d\u89c2\u6d4b RED \u6307\u6807\uff08\u8bf7\u6c42\u91cf\u3001\u9519\u8bef\u7387\u3001\u54cd\u5e94\u65f6\u5ef6\uff09\u3002<\/p>\n\n\n\n<p>\u7531\u4e8e\u5206\u5e03\u5f0f\u6838\u5fc3\u7cfb\u7edf\u7684\u4e1a\u52a1\u7b49\u7ea7\u975e\u5e38\u91cd\u8981\uff0c\u56e0\u6b64<strong>\u9009\u62e9<\/strong>\u89c2\u6d4b\u54cd\u5e94\u65f6\u5ef6\u6307\u6807\u4e2d\u7684\u201c<strong>\u6700\u5927\u65f6\u5ef6<\/strong>\u201d\uff0c\u5e76<strong>\u627e\u51fa\u95ee\u9898\u53d1\u751f\u65f6\u95f4\u70b9<\/strong>\u3002<\/p>\n\n\n\n<p>\u901a\u8fc7\u5206\u6790\u8be5\u8def\u5f84\u7684\u6700\u5927\u65f6\u5ef6\uff0c\u6211\u4eec\u53d1\u73b0\u5728\u538b\u6d4b\u9636\u6bb5\u5468\u671f\u6027\u51fa\u73b0\u6162\u54cd\u5e94\uff08\u5927\u4e8e 2 \u79d2\uff09\uff0c\u4e8e\u662f\u6211\u4eec\u53ef\u4ee5\u5c06\u53f3\u6ed1\u7a97\u7684\u89c2\u6d4b\u65f6\u95f4\u8303\u56f4\u7f29\u5c0f\u5230\u95ee\u9898\u65f6\u6bb5\uff0820:20~21:00\uff09\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.yunshan.net\/blog\/wp-content\/uploads\/2024\/10\/04-2-1024x544.png\" alt=\"\" class=\"wp-image-19345\"\/><figcaption>When is it in trouble?<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong> 3. \u8c03\u7528\u65e5\u5fd7\u68c0\u7d22\uff0c\u627e\u51fa\u6162\u54cd\u5e94<\/strong><\/h3>\n\n\n\n<p>\u5f53\u786e\u5b9a\u95ee\u9898\u53d1\u751f\u65f6\u95f4\u6bb5\u4e4b\u540e\uff0c<strong>\u7b2c\u4e09\u6b65<\/strong>\u4fbf\u8981\u56de\u7b54 \u201c<strong>Which request is in trouble<\/strong>\u201d \u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u5728\u300c\u53f3\u6ed1\u7a97\u300d\u7684\u300c\u8c03\u7528\u65e5\u5fd7\u300d\u4e2d\u8fc7\u6ee4\u6216\u6392\u5e8f\uff0c\u5728\u95ee\u9898\u65f6\u6bb5\u627e\u5230\u5341\u4f59\u6b21\u6162\u54cd\u5e94\u8bf7\u6c42\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.yunshan.net\/blog\/wp-content\/uploads\/2024\/10\/05-1-1024x566.png\" alt=\"\" class=\"wp-image-19346\"\/><figcaption>Which request is in trouble?<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong> 4. \u8c03\u7528\u94fe\u8ffd\u8e2a\uff0c\u627e\u51fa\u6839\u56e0\u4f4d\u7f6e<\/strong><\/h3>\n\n\n\n<p>\u627e\u5230\u6162\u54cd\u5e94\u7684\u8bf7\u6c42\u5217\u8868\u540e\uff0c<strong>\u7b2c\u56db\u6b65<\/strong>\u4fbf\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528\u94fe\u8ffd\u8e2a\uff0c\u56de\u7b54 \u201c<strong>Where is the root position<\/strong>\u201d \u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u9009\u53d6\u5176\u4e2d\u4e00\u6b21\u7ea6 2s \u7684\u6162\u54cd\u5e94\u8bf7\u6c42\u505a\u300c\u8c03\u7528\u94fe\u8ffd\u8e2a\u300d\uff0c\u7ecf\u8fc7\u8ffd\u8e2a\u53d1\u73b0\u5728<code>\u89c2\u6d4b\u70b9 8<\/code>&nbsp;\u7684\u5de6\u4fa7\u5b58\u5728\u7ea6 2s \u7684\u7a7a\u7f3a\uff0c\u8bf4\u660e\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>\u89c2\u6d4b\u70b9 7<\/code>\uff08<code>App-2<\/code>&nbsp;\u7684 Pod \u7f51\u5361\uff09\u5df2\u53ca\u65f6\u6536\u5230 Request\uff1b<\/li><li><code>\u89c2\u6d4b\u70b9 8<\/code>\uff08<code>App-2<\/code>&nbsp;\u7684\u5e94\u7528\u8fdb\u7a0b\uff09\u7b49\u5f85\u7ea6 2s \u624d\u53d1\u8d77&nbsp;<code>read()<\/code>&nbsp;\u8bfb\u53d6\u8be5\u6b21 Request\u3002<\/li><\/ul>\n\n\n\n<p>\u56e0\u6b64\uff0c\u6839\u56e0\u4f4d\u7f6e\u662f&nbsp;<code>App-2<\/code>&nbsp;\u7684\u5e94\u7528\u8fdb\u7a0b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.yunshan.net\/blog\/wp-content\/uploads\/2024\/10\/06-1-1024x784.png\" alt=\"\" class=\"wp-image-19347\"\/><figcaption>Where is the root position?<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong> 5. \u6839\u56e0\u5206\u6790<\/strong><\/h3>\n\n\n\n<p><strong>\u7b2c\u4e94\u6b65<\/strong>\uff0c\u5bf9\u6839\u56e0\u4f4d\u7f6e\u8fdb\u884c\u5206\u6790\uff0c\u56de\u7b54 \u201c<strong>What is the root cause<\/strong>\u201d \u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u4e3a\u4ec0\u4e48&nbsp;<code>App-2<\/code>&nbsp;\u5728\u7f51\u5361\u5df2\u6536\u5230 Request \u540e\u7ea6 2s \u624d\u53d1\u8d77&nbsp;<code>read()<\/code>&nbsp;\u7684 Syscall\uff1f<\/p>\n\n\n\n<p>\u7b54\u6848\u5f88\u7b80\u5355\uff1a<strong>Java \u7a0b\u5e8f Netty \u7684 I\/O \u7ebf\u7a0b\u7e41\u5fd9<\/strong>\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.yunshan.net\/blog\/wp-content\/uploads\/2024\/10\/07-1-1024x771.png\" alt=\"\" class=\"wp-image-19348\"\/><figcaption>What is the root cause?<\/figcaption><\/figure>\n\n\n\n<p>Java \u7a0b\u5e8f\u4f7f\u7528 Netty \u7f51\u7edc\u6846\u67b6\u65f6\uff0c\u5f53\u591a\u8def Client \u53d1\u8d77\u8fde\u63a5\uff08TCP Connection\uff09\u6ce8\u518c\uff0cNetty \u7684 BossGroup \u4f1a\u5728 I\/O \u7ebf\u7a0b\u6c60\uff08\u5373 Woker Group\uff09\u4e2d\u9009\u62e9\u4e00\u4e2a I\/O \u7ebf\u7a0b\uff08Worker EventLoop\uff09\u8d1f\u8d23 TCP \u5efa\u8fde\u5904\u7406\uff08\u4e09\u6b21\u63e1\u624b\uff09\uff0c\u63a5\u6536\u5e94\u7528\u8bf7\u6c42\uff0c\u53d1\u9001\u5e94\u7528\u54cd\u5e94\uff0c\u56e0\u6b64 I\/O \u7ebf\u7a0b\u6c60\u4e2d\u7684\u4e00\u4e2a I\/O \u7ebf\u7a0b\u4f1a\u88ab\u591a\u4e2a TCP \u8fde\u63a5\u6240\u590d\u7528\u3002<\/p>\n\n\n\n<p>\u56e0\u6b64\uff0c\u867d\u7136 Netty \u7684 NIO \u901a\u4fe1\u6a21\u578b\u5f88\u597d\u7684\u89e3\u51b3\u4e86\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u7684\u4e1a\u52a1\u5904\u7406\u6027\u80fd\uff0c\u5e76\u901a\u8fc7 I\/O \u7ebf\u7a0b\u6c60\u5f88\u597d\u7684\u63a7\u5236\u4e86\u9ad8\u5e76\u53d1\u91cf\u5bf9\u7ebf\u7a0b\u8d44\u6e90\u7684\u6d88\u8017\uff0c\u4f46 Netty \u9700\u8981<strong>\u663e\u5f0f\u914d\u7f6e<\/strong>\u3001<strong>\u660e\u786e\u9650\u5236<\/strong>&nbsp;I\/O \u7ebf\u7a0b\u6570\u91cf\uff08\u9ed8\u8ba4\u53d6\u503c\uff1a2 * CPU \u6838\u6570\uff09\uff0c\u5728\u77ac\u65f6\u8bf7\u6c42\u91cf\u5927\u7684\u573a\u666f\u4e0b&nbsp;<strong>I\/O \u7ebf\u7a0b\u4ecd\u7136\u5b58\u5728\u62e5\u585e\u98ce\u9669<\/strong>\uff0c\u5f53\u67d0\u4e2a I\/O \u7ebf\u7a0b\u8d1f\u8d23\u7684 TCP \u8fde\u63a5\u51fa\u73b0\u5927\u5e76\u53d1\u65f6\uff0c\u6709\u53ef\u80fd\u53d1\u751f Request \u5230\u8fbe Socket \u7684 recv buffer \u540e\u4e0d\u80fd\u88ab I\/O \u7ebf\u7a0b\u53ca\u65f6 read \u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong> 6. \u4fee\u590d\u65b9\u6848\u53ca\u9a8c\u8bc1<\/strong><\/h3>\n\n\n\n<p>\u9501\u5b9a\u6545\u969c\u6839\u56e0\u662f\u201c<strong>Netty \u7684 I\/O \u7ebf\u7a0b\u963b\u585e<\/strong>\u201d\u540e\uff0c\u5f00\u53d1\u4eba\u5458\u5728 JVM \u4e2d\u4fee\u6539\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u53c2\u6570\uff1a<code>java -XX:ActiveProcessorCount<\/code>\uff0c\u5c06\u53d6\u503c\u8c03\u6574\u4e3a \u5b9e\u9645 CPU \u6838\u6570 \u7684 2 \u500d\uff0c\u8fbe\u5230&nbsp;<strong>I\/O \u7ebf\u7a0b\u8d85\u5206<\/strong>\u7684\u6548\u679c\uff08Netty \u4e2d I\/O \u7ebf\u7a0b\u6570\u91cf\u9ed8\u8ba4\u53d6\u503c&nbsp;<code>2 * ActiveProcessorCount<\/code>\uff0c\u6b64\u65f6\u7b49\u4e8e&nbsp;<code>4 * \u5b9e\u9645 CPU \u6838\u6570<\/code>\uff09\u3002<\/p>\n\n\n\n<p>\u901a\u8fc7\u8c03\u6574&nbsp;<code>ActiveProcessorCount<\/code>&nbsp;\u53c2\u6570\uff0c\u5c06\u5e94\u7528\u7a0b\u5e8f I\/O \u7ebf\u7a0b\u6570\u91cf\u63d0\u5347\u5230\u539f\u6765\u7684 2 \u500d\u4e4b\u540e\uff0c\u7ecf\u8fc7\u6301\u7eed\u538b\u6d4b\u9a8c\u8bc1\uff0c\u95ee\u9898\u89e3\u51b3\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u5b9e\u9645\u751f\u4ea7\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u5e94\u7528\u7a0b\u5e8f\u7684\u7279\u6027\uff08I\/O \u5bc6\u96c6\u578b\u3001CPU \u5bc6\u96c6\u578b\uff09\u6765\u81ea\u5b9a\u4e49\u7ebf\u7a0b\u6570\u91cf\uff0c\u4ee5\u8fbe\u5230\u66f4\u597d\u7684\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u3002\u5bf9\u9ad8\u5ea6 I\/O \u5bc6\u96c6\u578b\u5e94\u7528\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u589e\u52a0 I\/O \u7ebf\u7a0b\u6570\u91cf\uff1b\u5bf9\u9ad8\u5ea6\u8ba1\u7b97\u5bc6\u96c6\u578b\u5e94\u7528\u7a0b\u5e8f\uff0c\u53ef\u51cf\u5c11 I\/O \u7ebf\u7a0b\u6570\u91cf\u3002<\/p><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>03\uff5c\u603b\u7ed3<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.yunshan.net\/blog\/wp-content\/uploads\/2024\/10\/08-1-1024x701.png\" alt=\"\" class=\"wp-image-19349\"\/><figcaption>DeepFlow Observability vs Monitoring<\/figcaption><\/figure>\n\n\n\n<p>\u4ece\u8be5\u6848\u4f8b\u4e2d\u6211\u4eec\u4e0d\u96be\u53d1\u73b0\uff0c\u5728\u4f20\u7edf NPM \u76d1\u63a7\u548c APM \u76d1\u63a7\u4f53\u7cfb\u4e0b\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u3001\u5e94\u7528\u7a0b\u5e8f\u5747<strong>\u5b58\u5728\u5927\u8303\u56f4\u7684\u76f2\u533a<\/strong>\uff0c\u5bfc\u81f4<strong>\u6545\u969c\u5b9a\u4f4d\u6781\u5176\u56f0\u96be<\/strong>\uff0c\u7ecf\u5e38\u53d1\u751f APM \u3001NPM \u5448\u73b0\u7684\u670d\u52a1\u6027\u80fd\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\uff0c\u4ece NPM \u76d1\u63a7\u660e\u663e\u770b\u5230\u670d\u52a1\u7aef\u5e94\u7528\u7a0b\u5e8f\u54cd\u5e94\u6162\uff0c\u4f46\u4ece APM \u76d1\u63a7\u5374\u8ba4\u4e3a\u6240\u6709\u8bf7\u6c42\u7684\u54cd\u5e94\u6027\u80fd\u6307\u6807\u5747\u6b63\u5e38\uff0c\u56e0\u800c\u6545\u969c\u8bca\u65ad\u4e2d\u7684<strong>\u8fb9\u754c\u4e0d\u6e05<\/strong>\uff0c<strong>\u6765\u56de\u62c9\u952f<\/strong>\uff0c<strong>\u751a\u81f3\u4e92\u76f8\u6307\u8d23<\/strong>\u975e\u5e38\u666e\u904d\u3002<\/p>\n\n\n\n<p>DeepFlow \u901a\u8fc7 eBPF \u6280\u672f\u5b9e\u73b0\u7684\u96f6\u4fb5\u6270\uff08<strong>Zero-Code<\/strong>\uff09\u7684\u5206\u5e03\u5f0f\u8ffd\u8e2a\uff0c\u5b9e\u73b0\u4e86\u4efb\u610f\u4e00\u6b21\u5e94\u7528\u8bf7\u6c42\uff08<strong>Any Request<\/strong>\uff09\u4ece\u7269\u7406\u7f51\u7edc\u5230\u5bb9\u5668\u7f51\u7edc\u3001\u64cd\u4f5c\u7cfb\u7edf\u3001\u5e94\u7528\u8fdb\u7a0b\u7684\u5168\u6280\u672f\u6808\uff08<strong>Full-Stack<\/strong>\uff09\u3001\u7aef\u5230\u7aef\uff08<strong>Real End-End<\/strong>\uff09\u8ffd\u8e2a\u80fd\u529b\uff0c\u6253\u901a\u4e86\u5e94\u7528\u8fd0\u7ef4\u3001\u7cfb\u7edf\u8fd0\u7ef4\u3001\u7f51\u7edc\u8fd0\u7ef4\u7684\u6280\u672f\u6808\u8fb9\u754c\uff0c\u6784\u5efa\u7edf\u4e00\u7684\u8fd0\u7ef4\u89c2\u6d4b\u6570\u636e\u6e56\uff0c\u4ece\u800c\u5c06\u6545\u969c\u8bca\u65ad\u6548\u7387\u63d0\u5347\u5230 3 \u5206\u949f\u4ee5\u5185\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>04\uff5c\u6280\u672f Tip\u2014\u2014Netty \u7f51\u7edc\u6846\u67b6\u6570\u636e\u5305\u8bfb\u53d6\u8fc7\u7a0b<\/strong><\/h2>\n\n\n\n<p>Netty \u7f51\u7edc\u6846\u67b6\u4f7f\u7528 OS Kernel \u7684 epoll \u673a\u5236\u5728\u5185\u6838\u7a7a\u95f4\u3001\u7528\u6237\u7a7a\u95f4\u4e4b\u95f4\u8bfb\/\u5199\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48 Netty I\/O \u7ebf\u7a0b\u5982\u4f55\u4e0e OS Kernel \u4ea4\u4e92\u5e76\u83b7\u53d6\u901a\u4fe1\u5bf9\u7aef\u53d1\u6765\u7684 Request \u6570\u636e\u5305\u5462\uff1f<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.yunshan.net\/blog\/wp-content\/uploads\/2024\/10\/09-1-1024x438.png\" alt=\"\" class=\"wp-image-19350\"\/><figcaption>Workflow of Netty<\/figcaption><\/figure>\n\n\n\n<p>\u53ef\u4ee5\u901a\u4fd7\u7684\u63cf\u8ff0\u4e3a\u5982\u4e0b\u8fc7\u7a0b\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u9996\u5148\uff0cNetty \u7684&nbsp;<code>Worker EventLoop<\/code>\uff08<code>I\/O \u7ebf\u7a0b<\/code>\uff09\u8c03\u7528 Kernel \u4e2d&nbsp;<code>epoll<\/code>&nbsp;\u7684&nbsp;<code>epoll_wait()<\/code>&nbsp;\u65b9\u6cd5\uff0c\u5e76\u8fdb\u5165\u963b\u585e\u72b6\u6001\uff0c\u7b49\u5f85&nbsp;<code>epoll<\/code>&nbsp;\u7684\u901a\u77e5\uff1b<\/li><li>\u5f53\u7f51\u5361\u63a5\u6536\u5230 Request \u6570\u636e\u5305\u540e\uff0c\u901a\u8fc7\u786c\u4e2d\u65ad\u901a\u77e5 Kernel\uff0cKernel \u5904\u7406\u6570\u636e\u5305\u5e76\u653e\u5165 Socket \u7684&nbsp;<code>recv buffer<\/code>;<\/li><li>\u7136\u540e\uff0c<code>epoll<\/code>&nbsp;\u76d1\u6d4b\u5230 Socket \u7684&nbsp;<code>recv buffer<\/code>&nbsp;\u6709\u6570\u636e\u5305\u5230\u8fbe\u540e\uff0c\u5c06\u53ef\u8bfb\u7684 Socket \u5217\u5165\u5c31\u7eea\u7684\u4e8b\u4ef6\u5217\u8868\uff1b<\/li><li>\u518d\u7136\u540e\uff0c<code>Worker EventLoop<\/code>&nbsp;\u5728&nbsp;<code>epoll_wait<\/code>&nbsp;\u4e0a\u88ab\u5524\u9192\uff0c\u5e76\u8fd4\u56de\u5c31\u7eea\u7684\u4e8b\u4ef6\u5217\u8868;<\/li><li>\u6700\u540e\uff0c<code>Worker EventLoop<\/code>&nbsp;\u8c03\u7528&nbsp;<code>read()<\/code>&nbsp;\u65b9\u6cd5\u4ece\u64cd\u4f5c\u7cfb\u7edf\u7684&nbsp;<code>recv buffer<\/code>&nbsp;\u4e2d\u8bfb\u53d6 Request \u6570\u636e\u5305\u3002<\/li><\/ol>\n\n\n\n<p>\u81f3\u6b64\uff0cNetty \u5b8c\u6210\u4e00\u6b21\u4ece Kernel \u7684 Socket \u8bfb\u53d6\u6570\u636e\u7684\u5b8c\u6574\u8fc7\u7a0b\uff0c\u5982\u679c&nbsp;<code>Worker EventLoop<\/code>&nbsp;\u6ca1\u6709\u5176\u4ed6\u9700\u8981\u8bfb\/\u5199\u7684\u6570\u636e\uff0c\u5219\u518d\u6b21\u56de\u5230\u7b2c 1 \u6b65\uff0c\u8c03\u7528&nbsp;<code>epoll<\/code>&nbsp;\u7684&nbsp;<code>epoll_wait()<\/code>&nbsp;\u65b9\u6cd5\uff0c\u8fdb\u5165\u963b\u585e\u72b6\u6001\uff0c\u7b49\u5f85\u4e0b\u4e00\u6b21\u6570\u636e\u5305\u5230\u8fbe\u540e\u7684&nbsp;<code>epoll<\/code>&nbsp;\u901a\u77e5\uff0c\u5faa\u73af\u5f80\u590d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>05\uff5c\u4ec0\u4e48\u662f DeepFlow<\/strong><\/h2>\n\n\n\n<p>DeepFlow \u662f\u4e91\u6749\u7f51\u7edc\u5f00\u53d1\u7684\u4e00\u6b3e\u53ef\u89c2\u6d4b\u6027\u4ea7\u54c1\uff0c\u65e8\u5728\u4e3a\u590d\u6742\u7684<strong>\u4e91\u539f\u751f<\/strong>\u53ca&nbsp;<strong>AI<\/strong>&nbsp;\u5e94\u7528\u63d0\u4f9b\u6df1\u5ea6\u53ef\u89c2\u6d4b\u6027\u3002DeepFlow \u57fa\u4e8e&nbsp;<code>eBPF<\/code>&nbsp;\u5b9e\u73b0\u4e86\u5e94\u7528\u6027\u80fd\u6307\u6807\u3001\u5206\u5e03\u5f0f\u8ffd\u8e2a\u3001\u6301\u7eed\u6027\u80fd\u5256\u6790\u7b49\u89c2\u6d4b\u4fe1\u53f7\u7684<strong>\u96f6\u4fb5\u6270<\/strong>\uff08<code>Zero Code<\/code>\uff09\u91c7\u96c6\uff0c\u5e76\u7ed3\u5408<strong>\u667a\u80fd\u6807\u7b7e<\/strong>\uff08<code>SmartEncoding<\/code>\uff09\u6280\u672f\u5b9e\u73b0\u4e86\u6240\u6709\u89c2\u6d4b\u4fe1\u53f7\u7684<strong>\u5168\u6808<\/strong>\uff08<code>Full Stack<\/code>\uff09\u5173\u8054\u548c\u9ad8\u6548\u5b58\u53d6\u3002\u4f7f\u7528 DeepFlow\uff0c\u53ef\u4ee5\u8ba9\u4e91\u539f\u751f\u53ca AI \u5e94\u7528\u81ea\u52a8\u5177\u6709\u6df1\u5ea6\u53ef\u89c2\u6d4b\u6027\uff0c\u4ece\u800c\u6d88\u9664\u5f00\u53d1\u8005\u4e0d\u65ad\u63d2\u6869\u7684\u6c89\u91cd\u8d1f\u62c5\uff0c\u5e76\u4e3a DevOps\/SRE \u56e2\u961f\u63d0\u4f9b\u4ece\u4ee3\u7801\u5230\u57fa\u7840\u8bbe\u65bd\u7684\u76d1\u63a7\u53ca\u8bca\u65ad\u80fd\u529b\u3002<\/p>\n\n\n\n<p>GitHub \u5730\u5740\uff1ahttps:\/\/github.com\/deepflowio\/deepflow<\/p>\n\n\n\n<p>\u8bbf\u95ee&nbsp;<strong>DeepFlow Demo<\/strong><sup>[1]<\/sup>\uff0c\u4f53\u9a8c\u96f6\u4fb5\u6270\u3001\u5168\u6808\u7684\u53ef\u89c2\u6d4b\u6027\u3002<\/p>\n\n\n\n<p><strong>\u53c2\u8003\u8d44\u6599\uff1a<\/strong>[1] DeepFlow Demo: <em>https:\/\/deepflow.io\/docs\/zh\/ce-install\/overview\/<\/em><\/p>\n]]>\t\t","protected":false},"excerpt":{"rendered":"<p>\t\t\t\t<![CDATA[I\/O \u7ebf\u7a0b\u963b\u585e\u662fJava \u7a0b\u5e8f\u7ecf\u5e38\u51fa\u73b0\u7684\u95ee\u9898\u4e4b\u4e00\uff0c\u6b64\u7c7b\u6545\u969c\u53d1\u751f\u65f6 Java \u7a0b\u5e8f\u7684\u8bf7\u6c42\u3001\u54cd\u5e94\u5728 I\/O \u7ebf\u7a0b\u5411\u64cd\u4f5c\u7cfb\u7edf Socket Buffer \u8bfb\/\u5199\u8fc7\u7a0b\u4e2d\u53d1\u751f\u963b\u585e\uff0c\u7531\u4e8e\u5728\u4e1a\u52a1\u4ee3\u7801\u63d2\u6869\u65e0\u6cd5\u89c2\u6d4b\u5230 I\/O \u7ebf\u7a0b\u7684\u5de5\u4f5c\u60c5\u51b5\u548c\u6027\u80fd\u8868\u73b0\uff0c\u56e0\u800c\u5bfc\u81f4\u6545\u969c\u975e\u5e38\u9690\u853d\u548c\u96be\u4ee5\u8bca\u65ad\u5b9a\u4f4d\u3002\u901a\u8fc7\u672c\u7bc7\u6848\u4f8b\u60a8\u5c06\u4e86\u89e3\u5230\uff0c\u67d0\u94f6\u884c\u7684\u5f00\u53d1\u5de5\u7a0b\u5e08\u5982\u4f55\u4f7f\u7528 eBPF \u6280\u672f\u5e26\u6765\u7684\u96f6\u4fb5\u6270\u8ffd\u8e2a\u80fd\u529b\uff0c\u5728\u67d0\u6b21\u5206\u5e03\u5f0f\u6838\u5fc3\u4ea4\u6613\u7cfb\u7edf\u4e0a\u7ebf\u4fe1\u521b\u5e73\u53f0\u7684\u975e\u529f\u80fd\u6d4b\u8bd5\uff08\u6027\u80fd\u538b\u6d4b\uff09\u6545\u969c\u8bca\u65ad\u4e2d\uff0c\u7528 3 \u5206\u949f\u65f6\u95f4\u9501\u5b9a Java \u7a0b\u5e8f I\/O \u7ebf\u7a0b\u963b\u585e\u3002]]>\t\t<\/p>\n","protected":false},"author":5,"featured_media":19352,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,17],"tags":[20,21,22,28,101,102],"class_list":["post-19341","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ys-news","category-case","tag-deepflow","tag-ebpf","tag-i-o-","tag-java","tag-101","tag-102"],"_links":{"self":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts\/19341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/comments?post=19341"}],"version-history":[{"count":0,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts\/19341\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/media?parent=19341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/categories?post=19341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/tags?post=19341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}