{"id":16558,"date":"2024-11-18T08:30:30","date_gmt":"2024-11-18T00:30:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/16558\/"},"modified":"2024-11-18T08:30:30","modified_gmt":"2024-11-18T00:30:30","slug":"linux-%e8%bf%90%e7%bb%b4%e6%95%85%e9%9a%9c%e6%8e%92%e6%9f%a5%e6%80%9d%e8%b7%af%ef%bc%8c%e6%9c%89%e8%bf%99%e7%af%87%e6%96%87%e7%ab%a0%e5%b0%b1%e5%a4%9f%e4%ba%86","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/16558\/","title":{"rendered":"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~"},"content":{"rendered":"<p>  <\/p>\n<h2><span>1.&nbsp;\u80cc\u666f<\/span><\/h2>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u6709\u65f6\u5019\u4f1a\u9047\u5230\u4e00\u4e9b\u7591\u96be\u6742\u75c7\uff0c\u5e76\u4e14\u76d1\u63a7\u63d2\u4ef6\u5e76\u4e0d\u80fd\u4e00\u773c\u7acb\u9a6c\u53d1\u73b0\u95ee\u9898\u7684\u6839\u6e90\u3002\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u767b\u5f55\u670d\u52a1\u5668\u8fdb\u4e00\u6b65\u6df1\u5165\u5206\u6790\u95ee\u9898\u7684\u6839\u6e90\u3002\u90a3\u4e48\u5206\u6790\u95ee\u9898\u9700\u8981\u6709\u4e00\u5b9a\u7684\u6280\u672f\u7ecf\u9a8c\u79ef\u7d2f\uff0c\u5e76\u4e14\u6709\u4e9b\u95ee\u9898\u6d89\u53ca\u5230\u7684\u9886\u57df\u975e\u5e38\u5e7f\uff0c\u624d\u80fd\u5b9a\u4f4d\u5230\u95ee\u9898\u3002\u6240\u4ee5\uff0c\u5206\u6790\u95ee\u9898\u548c\u8e29\u5751\u662f\u975e\u5e38\u953b\u70bc\u4e00\u4e2a\u4eba\u7684\u6210\u957f\u548c\u63d0\u5347\u81ea\u6211\u80fd\u529b\u3002\u5982\u679c\u6211\u4eec\u6709\u4e00\u5957\u597d\u7684\u5206\u6790\u5de5\u5177\uff0c\u90a3\u5c06\u662f\u4e8b\u534a\u529f\u500d\uff0c\u80fd\u591f\u5e2e\u52a9\u5927\u5bb6\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\uff0c\u8282\u7701\u5927\u5bb6\u5f88\u591a\u65f6\u95f4\u505a\u66f4\u6df1\u5165\u7684\u4e8b\u60c5\u3002<\/span><\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/b489c2b0903dbe6941a6aa1683f4eb5f-0.png\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe\" \/><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\"><\/span><\/p>\n<h2><span>2. \u8bf4\u660e<\/span><\/h2>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u5404\u79cd\u95ee\u9898\u5b9a\u4f4d\u7684\u5de5\u5177\u4ee5\u53ca\u4f1a\u7ed3\u5408\u6848\u4f8b\u5206\u6790\u95ee\u9898\u3002<\/span><\/p>\n<h2><span>3. \u5206\u6790\u95ee\u9898\u7684\u65b9\u6cd5\u8bba<\/span><\/h2>\n<p><span style=\"font-size: 15px\">\u5957\u75285W2H\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u51fa\u6027\u80fd\u5206\u6790\u7684\u51e0\u4e2a\u95ee\u9898<\/span>  <\/p>\n<ul>\n<li>  <span>What-\u73b0\u8c61\u662f\u4ec0\u4e48\u6837\u7684<\/span> <\/li>\n<li>  <span>When-\u4ec0\u4e48\u65f6\u5019\u53d1\u751f<\/span> <\/li>\n<li>  <span>Why-\u4e3a\u4ec0\u4e48\u4f1a\u53d1\u751f<\/span> <\/li>\n<li>  <span>Where-\u54ea\u4e2a\u5730\u65b9\u53d1\u751f\u7684\u95ee\u9898<\/span> <\/li>\n<li>  <span>How much-\u8017\u8d39\u4e86\u591a\u5c11\u8d44\u6e90<\/span> <\/li>\n<li>  <span>How to do-\u600e\u4e48\u89e3\u51b3\u95ee\u9898<\/span> <\/li>\n<\/ul>\n<h2><span>4. cpu<\/span><\/h2>\n<h3><span>4.1 \u8bf4\u660e<\/span><\/h3>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u9488\u5bf9\u5e94\u7528\u7a0b\u5e8f\uff0c\u6211\u4eec\u901a\u5e38\u5173\u6ce8\u7684\u662f\u5185\u6838CPU\u8c03\u5ea6\u5668\u529f\u80fd\u548c\u6027\u80fd\u3002<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u7ebf\u7a0b\u7684\u72b6\u6001\u5206\u6790\u4e3b\u8981\u662f\u5206\u6790\u7ebf\u7a0b\u7684\u65f6\u95f4\u7528\u5728\u4ec0\u4e48\u5730\u65b9\uff0c\u800c\u7ebf\u7a0b\u72b6\u6001\u7684\u5206\u7c7b\u4e00\u822c\u5206\u4e3a\uff1a<\/span><\/p>\n<ol>\n<li>\n<p style=\"margin-bottom: 1.2em !important\"><span>on-CPU\uff1a\u6267\u884c\u4e2d\uff0c\u6267\u884c\u4e2d\u7684\u65f6\u95f4\u901a\u5e38\u53c8\u5206\u4e3a\u7528\u6237\u6001\u65f6\u95f4user\u548c\u7cfb\u7edf\u6001\u65f6\u95f4sys\u3002<\/span><\/p>\n<\/li>\n<li>\n<p style=\"margin-bottom: 1.2em !important\"><span>off-CPU\uff1a\u7b49\u5f85\u4e0b\u4e00\u8f6e\u4e0aCPU\uff0c\u6216\u8005\u7b49\u5f85I\/O\u3001\u9501\u3001\u6362\u9875\u7b49\u7b49\uff0c\u5176\u72b6\u6001\u53ef\u4ee5\u7ec6\u5206\u4e3a\u53ef\u6267\u884c\u3001\u533f\u540d\u6362\u9875\u3001\u7761\u7720\u3001\u9501\u3001\u7a7a\u95f2\u7b49\u72b6\u6001\u3002<\/span><\/p>\n<\/li>\n<\/ol>\n<p><span style=\"font-size: 15px\">\u5982\u679c\u5927\u91cf\u65f6\u95f4\u82b1\u5728CPU\u4e0a\uff0c\u5bf9CPU\u7684\u5256\u6790\u80fd\u591f\u8fc5\u901f\u89e3\u91ca\u539f\u56e0\uff1b\u5982\u679c\u7cfb\u7edf\u65f6\u95f4\u5927\u91cf\u5904\u4e8eoff-cpu\u72b6\u6001\uff0c\u5b9a\u4f4d\u95ee\u9898\u5c31\u4f1a\u8d39\u65f6\u5f88\u591a\u3002\u4f46\u662f\u4ecd\u7136\u9700\u8981\u6e05\u695a\u4e00\u4e9b\u6982\u5ff5\uff1a<\/span>  <\/p>\n<ul>\n<li>  <span>\u5904\u7406\u5668<\/span> <\/li>\n<li>  <span>\u6838<\/span> <\/li>\n<li>  <span>\u786c\u4ef6\u7ebf\u7a0b<\/span> <\/li>\n<li>  <span>CPU\u5185\u5b58\u7f13\u5b58<\/span> <\/li>\n<li>  <span>\u65f6\u949f\u9891\u7387<\/span> <\/li>\n<li>  <span>\u6bcf\u6307\u4ee4\u5468\u671f\u6570CPI\u548c\u6bcf\u5468\u671f\u6307\u4ee4\u6570IPC<\/span> <\/li>\n<li>  <span>CPU\u6307\u4ee4<\/span> <\/li>\n<li>  <span>\u4f7f\u7528\u7387<\/span> <\/li>\n<li>  <span>\u7528\u6237\u65f6\u95f4\uff0f\u5185\u6838\u65f6\u95f4<\/span> <\/li>\n<li>  <span>\u8c03\u5ea6\u5668<\/span> <\/li>\n<li>  <span>\u8fd0\u884c\u961f\u5217<\/span> <\/li>\n<li>  <span>\u62a2\u5360<\/span> <\/li>\n<li>  <span>\u591a\u8fdb\u7a0b<\/span> <\/li>\n<li>  <span>\u591a\u7ebf\u7a0b<\/span> <\/li>\n<li>  <span>\u5b57\u957f<\/span> <\/li>\n<\/ul>\n<h3><span>4.2 \u5206\u6790\u5de5\u5177<\/span><\/h3>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/b489c2b0903dbe6941a6aa1683f4eb5f-1.jpg\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe1\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe1\" \/><\/p>\n<p><span style=\"font-size: 15px\">\u8bf4\u660e:<\/span>  <\/p>\n<ul>\n<li>  <span>uptime\uff0cvmstat\uff0cmpstat\uff0ctop\uff0cpidstat \u53ea\u80fd\u67e5\u8be2\u5230cpu\u53ca\u8d1f\u8f7d\u7684\u7684\u4f7f\u7528\u60c5\u51b5\u3002<\/span> <\/li>\n<li>  <span>perf\u53ef\u4ee5\u8ddf\u7740\u5230\u8fdb\u7a0b\u5185\u90e8\u5177\u4f53\u51fd\u6570\u8017\u65f6\u60c5\u51b5\uff0c\u5e76\u4e14\u53ef\u4ee5\u6307\u5b9a\u5185\u6838\u51fd\u6570\u8fdb\u884c\u7edf\u8ba1\uff0c\u6307\u54ea\u6253\u54ea\u3002<\/span> <\/li>\n<\/ul>\n<h3>4.3 \u4f7f\u7528\u65b9\u5f0f<\/h3>\n<pre>\/\/\u67e5\u770b\u7cfb\u7edfcpu\u4f7f\u7528\u60c5\u51b5top\n\/\/\u67e5\u770b\u6240\u6709cpu\u6838\u4fe1\u606fmpstat&nbsp;-P&nbsp;ALL&nbsp;1\n\/\/\u67e5\u770bcpu\u4f7f\u7528\u60c5\u51b5\u4ee5\u53ca\u5e73\u5747\u8d1f\u8f7dvmstat&nbsp;1\n\/\/\u8fdb\u7a0bcpu\u7684\u7edf\u8ba1\u4fe1\u606fpidstat&nbsp;-u&nbsp;1&nbsp;-p&nbsp;pid\n\/\/\u8ddf\u8e2a\u8fdb\u7a0b\u5185\u90e8\u51fd\u6570\u7ea7cpu\u4f7f\u7528\u60c5\u51b5&nbsp;perf&nbsp;top&nbsp;-p&nbsp;pid&nbsp;-e&nbsp;cpu-clock<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<h2><span>5. \u5185\u5b58<\/span><\/h2>\n<h3><span>5.1 \u8bf4\u660e<\/span><\/h3>\n<p><span style=\"font-size: 15px\">\u5185\u5b58\u662f\u4e3a\u63d0\u9ad8\u6548\u7387\u800c\u751f\uff0c\u5b9e\u9645\u5206\u6790\u95ee\u9898\u7684\u65f6\u5019\uff0c\u5185\u5b58\u51fa\u73b0\u95ee\u9898\u53ef\u80fd\u4e0d\u53ea\u662f\u5f71\u54cd\u6027\u80fd\uff0c\u800c\u662f\u5f71\u54cd\u670d\u52a1\u6216\u8005\u5f15\u8d77\u5176\u4ed6\u95ee\u9898\u3002\u540c\u6837\u5bf9\u4e8e\u5185\u5b58\u6709\u4e9b\u6982\u5ff5\u9700\u8981\u6e05\u695a\uff1a<\/span>   <\/p>\n<pre>\u725b\u903c\u554a\uff01\u63a5\u79c1\u6d3b\u5fc5\u5907\u7684&nbsp;N&nbsp;\u4e2a\u5f00\u6e90\u9879\u76ee\uff01\u8d76\u5feb\u6536\u85cf<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236<br \/>\n<span style=\"font-size: 15px\"><\/span>  <\/p>\n<ul>\n<li>  <span>\u4e3b\u5b58<\/span> <\/li>\n<li>  <span>\u865a\u62df\u5185\u5b58<\/span> <\/li>\n<li>  <span>\u5e38\u9a7b\u5185\u5b58<\/span> <\/li>\n<li>  <span>\u5730\u5740\u7a7a\u95f4<\/span> <\/li>\n<li>  <span>OOM<\/span> <\/li>\n<li>  <span>\u9875\u7f13\u5b58<\/span> <\/li>\n<li>  <span>\u7f3a\u9875<\/span> <\/li>\n<li>  <span>\u6362\u9875<\/span> <\/li>\n<li>  <span>\u4ea4\u6362\u7a7a\u95f4<\/span> <\/li>\n<li>  <span>\u4ea4\u6362<\/span> <\/li>\n<li>  <span>\u7528\u6237\u5206\u914d\u5668libc\u3001glibc\u3001libmalloc\u548cmtmalloc<\/span> <\/li>\n<li>  <span>LINUX\u5185\u6838\u7ea7SLUB\u5206\u914d\u5668<\/span> <\/li>\n<\/ul>\n<h3><span>5.2 \u5206\u6790\u5de5\u5177<\/span><\/h3>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/b489c2b0903dbe6941a6aa1683f4eb5f-2.jpg\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe2\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe2\" \/><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u8bf4\u660e\uff1a<\/span><\/p>\n<ul>\n<li>\n<p style=\"line-height: 1.75em\"><span>free\uff0cvmstat\uff0ctop\uff0cpidstat\uff0cpmap\u53ea\u80fd\u7edf\u8ba1\u5185\u5b58\u4fe1\u606f\u4ee5\u53ca\u8fdb\u7a0b\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3002<\/span><\/p>\n<\/li>\n<li>\n<p><span>valgrind \u53ef\u4ee5\u5206\u6790\u5185\u5b58\u6cc4\u6f0f\u95ee\u9898\u3002<\/span><\/p>\n<\/li>\n<li>\n<p><span>dtrace \u52a8\u6001\u8ddf\u8e2a\u3002\u9700\u8981\u5bf9\u5185\u6838\u51fd\u6570\u6709\u5f88\u6df1\u5165\u7684\u4e86\u89e3\uff0c\u901a\u8fc7D\u8bed\u8a00\u7f16\u5199\u811a\u672c\u5b8c\u6210\u8ddf\u8e2a\u3002<\/span><\/p>\n<\/li>\n<\/ul>\n<h3><span>5.3 \u4f7f\u7528\u65b9\u5f0f<\/span><\/h3>\n<pre>\/\/\u67e5\u770b\u7cfb\u7edf\u5185\u5b58\u4f7f\u7528\u60c5\u51b5free&nbsp;-m\/\/\u865a\u62df\u5185\u5b58\u7edf\u8ba1\u4fe1\u606fvmstat&nbsp;1\/\/\u67e5\u770b\u7cfb\u7edf\u5185\u5b58\u60c5\u51b5top\/\/1s\u91c7\u96c6\u5468\u671f\uff0c\u83b7\u53d6\u5185\u5b58\u7684\u7edf\u8ba1\u4fe1\u606fpidstat&nbsp;-p&nbsp;pid&nbsp;-r&nbsp;1\/\/\u67e5\u770b\u8fdb\u7a0b\u7684\u5185\u5b58\u6620\u50cf\u4fe1\u606fpmap&nbsp;-d&nbsp;pid\/\/\u68c0\u6d4b\u7a0b\u5e8f\u5185\u5b58\u95ee\u9898valgrind&nbsp;--tool=memcheck&nbsp;--leak-check=full&nbsp;--log-file=.\/log.txt&nbsp;&nbsp;.\/\u7a0b\u5e8f\u540d<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<h2><span>6. \u78c1\u76d8IO<\/span><\/h2>\n<h3><span>6.1 \u8bf4\u660e<\/span><\/h3>\n<p><span style=\"font-size: 15px\">\u78c1\u76d8\u901a\u5e38\u662f\u8ba1\u7b97\u673a\u6700\u6162\u7684\u5b50\u7cfb\u7edf\uff0c\u4e5f\u662f\u6700\u5bb9\u6613\u51fa\u73b0\u6027\u80fd\u74f6\u9888\u7684\u5730\u65b9\uff0c\u56e0\u4e3a\u78c1\u76d8\u79bb CPU \u8ddd\u79bb\u6700\u8fdc\u800c\u4e14 CPU \u8bbf\u95ee\u78c1\u76d8\u8981\u6d89\u53ca\u5230\u673a\u68b0\u64cd\u4f5c\uff0c\u6bd4\u5982\u8f6c\u8f74\u3001\u5bfb\u8f68\u7b49\u3002\u8bbf\u95ee\u786c\u76d8\u548c\u8bbf\u95ee\u5185\u5b58\u4e4b\u95f4\u7684\u901f\u5ea6\u5dee\u522b\u662f\u4ee5\u6570\u91cf\u7ea7\u6765\u8ba1\u7b97\u7684\uff0c\u5c31\u50cf1\u5929\u548c1\u5206\u949f\u7684\u5dee\u522b\u4e00\u6837\u3002\u8981\u76d1\u6d4b IO \u6027\u80fd\uff0c\u6709\u5fc5\u8981\u4e86\u89e3\u4e00\u4e0b\u57fa\u672c\u539f\u7406\u548c Linux \u662f\u5982\u4f55\u5904\u7406\u786c\u76d8\u548c\u5185\u5b58\u4e4b\u95f4\u7684 IO \u7684\u3002<\/span>  <\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u5728\u7406\u89e3\u78c1\u76d8IO\u4e4b\u524d\uff0c\u540c\u6837\u6211\u4eec\u9700\u8981\u7406\u89e3\u4e00\u4e9b\u6982\u5ff5\uff0c\u4f8b\u5982\uff1a<\/span><\/p>\n<ul>\n<li>  <span>\u6587\u4ef6\u7cfb\u7edf<\/span> <\/li>\n<li>  <span>VFS<\/span> <\/li>\n<li>  <span>\u6587\u4ef6\u7cfb\u7edf\u7f13\u5b58<\/span> <\/li>\n<li>  <span>\u9875\u7f13\u5b58page cache<\/span> <\/li>\n<li>  <span>\u7f13\u51b2\u533a\u9ad8\u901f\u7f13\u5b58buffer cache<\/span> <\/li>\n<li>  <span>\u76ee\u5f55\u7f13\u5b58<\/span> <\/li>\n<li>  <span>inode<\/span> <\/li>\n<li>  <span>inode\u7f13\u5b58<\/span> <\/li>\n<li>  <span>noop\u8c03\u7528\u7b56\u7565<\/span> <\/li>\n<\/ul>\n<h3><span>6.2 \u5206\u6790\u5de5\u5177<\/span><\/h3>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/6f771f36bd197fd0d2dc0bc64886ffea-3.png\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe3\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe3\" \/><\/p>\n<h3><span>6.3 \u4f7f\u7528\u65b9\u5f0f<\/span><\/h3>\n<pre>\/\/\u67e5\u770b\u7cfb\u7edfio\u4fe1\u606fiotop\/\/\u7edf\u8ba1io\u8be6\u7ec6\u4fe1\u606fiostat&nbsp;-d&nbsp;-x&nbsp;-k&nbsp;1&nbsp;10\/\/\u67e5\u770b\u8fdb\u7a0b\u7ea7io\u7684\u4fe1\u606fpidstat&nbsp;-d&nbsp;1&nbsp;-p&nbsp;&nbsp;pid\/\/\u67e5\u770b\u7cfb\u7edfIO\u7684\u8bf7\u6c42\uff0c\u6bd4\u5982\u53ef\u4ee5\u5728\u53d1\u73b0\u7cfb\u7edfIO\u5f02\u5e38\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u8be5\u547d\u4ee4\u8fdb\u884c\u8c03\u67e5\uff0c\u5c31\u80fd\u6307\u5b9a\u5230\u5e95\u662f\u4ec0\u4e48\u539f\u56e0\u5bfc\u81f4\u7684IO\u5f02\u5e38perf&nbsp;record&nbsp;-e&nbsp;block:block_rq_issue&nbsp;-ag^Cperf&nbsp;report<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<h2><span>7. \u7f51\u7edc<\/span><\/h2>\n<h3><span>7.1 \u8bf4\u660e<\/span><\/h3>\n<p><span style=\"font-size: 15px\">\u7f51\u7edc\u7684\u76d1\u6d4b\u662f\u6240\u6709 Linux \u5b50\u7cfb\u7edf\u91cc\u9762\u6700\u590d\u6742\u7684\uff0c\u6709\u592a\u591a\u7684\u56e0\u7d20\u5728\u91cc\u9762\uff0c\u6bd4\u5982\uff1a\u5ef6\u8fdf\u3001\u963b\u585e\u3001\u51b2\u7a81\u3001\u4e22\u5305\u7b49\uff0c\u66f4\u7cdf\u7684\u662f\u4e0e Linux \u4e3b\u673a\u76f8\u8fde\u7684\u8def\u7531\u5668\u3001\u4ea4\u6362\u673a\u3001\u65e0\u7ebf\u4fe1\u53f7\u90fd\u4f1a\u5f71\u54cd\u5230\u6574\u4f53\u7f51\u7edc\u5e76\u4e14\u5f88\u96be\u5224\u65ad\u662f\u56e0\u4e3a Linux \u7f51\u7edc\u5b50\u7cfb\u7edf\u7684\u95ee\u9898\u8fd8\u662f\u522b\u7684\u8bbe\u5907\u7684\u95ee\u9898\uff0c\u589e\u52a0\u4e86\u76d1\u6d4b\u548c\u5224\u65ad\u7684\u590d\u6742\u5ea6\u3002\u73b0\u5728\u6211\u4eec\u4f7f\u7528\u7684\u6240\u6709\u7f51\u5361\u90fd\u79f0\u4e3a\u81ea\u9002\u5e94\u7f51\u5361\uff0c\u610f\u601d\u662f\u8bf4\u80fd\u6839\u636e\u7f51\u7edc\u4e0a\u7684\u4e0d\u540c\u7f51\u7edc\u8bbe\u5907\u5bfc\u81f4\u7684\u4e0d\u540c\u7f51\u7edc\u901f\u5ea6\u548c\u5de5\u4f5c\u6a21\u5f0f\u8fdb\u884c\u81ea\u52a8\u8c03\u6574\u3002<\/span>  <\/p>\n<h3><span>7.2 \u5206\u6790\u5de5\u5177<\/span><\/h3>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/6f771f36bd197fd0d2dc0bc64886ffea-4.jpg\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe4\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe4\" \/><\/p>\n<h3>7.3 \u4f7f\u7528\u65b9\u5f0f<\/h3>\n<pre>\/\/\u663e\u793a\u7f51\u7edc\u7edf\u8ba1\u4fe1\u606fnetstat&nbsp;-s\/\/\u663e\u793a\u5f53\u524dUDP\u8fde\u63a5\u72b6\u51b5netstat&nbsp;-nu\/\/\u663e\u793aUDP\u7aef\u53e3\u53f7\u7684\u4f7f\u7528\u60c5\u51b5netstat&nbsp;-apu\/\/\u7edf\u8ba1\u673a\u5668\u4e2d\u7f51\u7edc\u8fde\u63a5\u5404\u4e2a\u72b6\u6001\u4e2a\u6570netstat&nbsp;-a&nbsp;|&nbsp;awk&nbsp;'\/^tcp\/&nbsp;{++S[$NF]}&nbsp;END&nbsp;{for(a&nbsp;in&nbsp;S)&nbsp;print&nbsp;a,&nbsp;S[a]}'\/\/\u663e\u793aTCP\u8fde\u63a5ss&nbsp;-t&nbsp;-a\/\/\u663e\u793asockets\u6458\u8981\u4fe1\u606fss&nbsp;-s\/\/\u663e\u793a\u6240\u6709udp&nbsp;socketsss&nbsp;-u&nbsp;-a\/\/tcp,etcp\u72b6\u6001sar&nbsp;-n&nbsp;TCP,ETCP&nbsp;1\/\/\u67e5\u770b\u7f51\u7edcIOsar&nbsp;-n&nbsp;DEV&nbsp;1\/\/\u6293\u5305\u4ee5\u5305\u4e3a\u5355\u4f4d\u8fdb\u884c\u8f93\u51fatcpdump&nbsp;-i&nbsp;eth1&nbsp;host&nbsp;192.168.1.1&nbsp;and&nbsp;port&nbsp;80&nbsp;\/\/\u6293\u5305\u4ee5\u6d41\u4e3a\u5355\u4f4d\u663e\u793a\u6570\u636e\u5185\u5bb9tcpflow&nbsp;-cp&nbsp;host&nbsp;192.168.1.1<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<h2><span>8. \u7cfb\u7edf\u8d1f\u8f7d<\/span><\/h2>\n<h3><span>8.1 \u8bf4\u660e<\/span><\/h3>\n<p><span style=\"font-size: 15px\">Load \u5c31\u662f\u5bf9\u8ba1\u7b97\u673a\u5e72\u6d3b\u591a\u5c11\u7684\u5ea6\u91cf\uff08WikiPedia\uff1athe system Load is a measure of the amount of work that a compute system is doing\uff09\u7b80\u5355\u7684\u8bf4\u662f\u8fdb\u7a0b\u961f\u5217\u7684\u957f\u5ea6\u3002Load Average \u5c31\u662f\u4e00\u6bb5\u65f6\u95f4\uff081\u5206\u949f\u30015\u5206\u949f\u300115\u5206\u949f\uff09\u5185\u5e73\u5747Load\u3002<\/span>  <\/p>\n<h3><span>8.2 \u5206\u6790\u5de5\u5177<\/span><\/h3>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/6f771f36bd197fd0d2dc0bc64886ffea-5.png\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe5\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe5\" \/><\/p>\n<h3><span>8.3 \u4f7f\u7528\u65b9\u5f0f<\/span><\/h3>\n<pre>\/\/\u67e5\u770b\u8d1f\u8f7d\u60c5\u51b5uptimetopvmstat\/\/\u7edf\u8ba1\u7cfb\u7edf\u8c03\u7528\u8017\u65f6\u60c5\u51b5strace&nbsp;-c&nbsp;-p&nbsp;pid\/\/\u8ddf\u8e2a\u6307\u5b9a\u7684\u7cfb\u7edf\u64cd\u4f5c\u4f8b\u5982epoll_waitstrace&nbsp;-T&nbsp;-e&nbsp;epoll_wait&nbsp;-p&nbsp;pid\/\/\u67e5\u770b\u5185\u6838\u65e5\u5fd7\u4fe1\u606fdmesg<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<h2><span>9. \u706b\u7130\u56fe<\/span><\/h2>\n<h3><span>9.1 \u8bf4\u660e<\/span><\/h3>\n<p><span style=\"font-size: 15px\">\u706b\u7130\u56fe\uff08Flame Graph\u662f Bredan Gregg \u521b\u5efa\u7684\u4e00\u79cd\u6027\u80fd\u5206\u6790\u56fe\u8868\uff0c\u56e0\u4e3a\u5b83\u7684\u6837\u5b50\u8fd1\u4f3c ?\u800c\u5f97\u540d\u3002<\/span><br \/>\n<span style=\"font-size: 15px\">\u706b\u7130\u56fe\u4e3b\u8981\u662f\u7528\u6765\u5c55\u793a CPU\u7684\u8c03\u7528\u6808\u3002<\/span><br \/>\n<strong><span style=\"font-size: 15px\">y&nbsp;<\/span><\/strong><br \/>\n<span style=\"font-size: 15px\">\u8f74\u8868\u793a\u8c03\u7528\u6808\uff0c\u6bcf\u4e00\u5c42\u90fd\u662f\u4e00\u4e2a\u51fd\u6570\u3002\u8c03\u7528\u6808\u8d8a\u6df1\uff0c\u706b\u7130\u5c31\u8d8a\u9ad8\uff0c\u9876\u90e8\u5c31\u662f\u6b63\u5728\u6267\u884c\u7684\u51fd\u6570\uff0c\u4e0b\u65b9\u90fd\u662f\u5b83\u7684\u7236\u51fd\u6570\u3002<\/span><br \/>\n<strong><span style=\"font-size: 15px\">x&nbsp;<\/span><\/strong><br \/>\n<span style=\"font-size: 15px\">\u8f74\u8868\u793a\u62bd\u6837\u6570\uff0c\u5982\u679c\u4e00\u4e2a\u51fd\u6570\u5728 x \u8f74\u5360\u636e\u7684\u5bbd\u5ea6\u8d8a\u5bbd\uff0c\u5c31\u8868\u793a\u5b83\u88ab\u62bd\u5230\u7684\u6b21\u6570\u591a\uff0c\u5373\u6267\u884c\u7684\u65f6\u95f4\u957f\u3002\u6ce8\u610f\uff0cx \u8f74\u4e0d\u4ee3\u8868\u65f6\u95f4\uff0c\u800c\u662f\u6240\u6709\u7684\u8c03\u7528\u6808\u5408\u5e76\u540e\uff0c\u6309\u5b57\u6bcd\u987a\u5e8f\u6392\u5217\u7684\u3002<\/span><br \/>\n<span style=\"font-size: 15px\">\u706b\u7130\u56fe\u5c31\u662f\u770b\u9876\u5c42\u7684\u54ea\u4e2a\u51fd\u6570\u5360\u636e\u7684\u5bbd\u5ea6\u6700\u5927\u3002\u53ea\u8981\u6709\u201d\u5e73\u9876\u201d\uff08plateaus\uff09\uff0c\u5c31\u8868\u793a\u8be5\u51fd\u6570\u53ef\u80fd\u5b58\u5728\u6027\u80fd\u95ee\u9898\u3002\u989c\u8272\u6ca1\u6709\u7279\u6b8a\u542b\u4e49\uff0c\u56e0\u4e3a\u706b\u7130\u56fe\u8868\u793a\u7684\u662f CPU \u7684\u7e41\u5fd9\u7a0b\u5ea6\uff0c\u6240\u4ee5\u4e00\u822c\u9009\u62e9\u6696\u8272\u8c03\u3002<\/span>  <\/p>\n<p style=\"margin-bottom: 0px;letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u5e38\u89c1\u7684\u706b\u7130\u56fe\u7c7b\u578b\u6709 On-CPU\u3001Off-CPU\u3001Memory\u3001Hot\/Cold\u3001Differential\u7b49\u7b49\u3002<\/span><\/p>\n<h3>9.2 \u5b89\u88c5\u4f9d\u8d56\u5e93<\/h3>\n<pre>\/\/\u5b89\u88c5systemtap\uff0c\u9ed8\u8ba4\u7cfb\u7edf\u5df2\u5b89\u88c5yum&nbsp;install&nbsp;systemtap&nbsp;systemtap-runtime\/\/\u5185\u6838\u8c03\u8bd5\u5e93\u5fc5\u987b\u8ddf\u5185\u6838\u7248\u672c\u5bf9\u5e94\uff0c\u4f8b\u5982\uff1auname&nbsp;-r&nbsp;2.6.18-308.el5kernel-debuginfo-2.6.18-308.el5.x86_64.rpmkernel-devel-2.6.18-308.el5.x86_64.rpmkernel-debuginfo-common-2.6.18-308.el5.x86_64.rpm\/\/\u5b89\u88c5\u5185\u6838\u8c03\u8bd5\u5e93debuginfo-install&nbsp;--enablerepo=debuginfo&nbsp;search&nbsp;kerneldebuginfo-install&nbsp;--enablerepo=debuginfo&nbsp;&nbsp;search&nbsp;glibc<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<h3>9.3 \u5b89\u88c5<\/h3>\n<pre>git&nbsp;clone&nbsp;https:\/\/github.com\/lidaohang\/quick_location.gitcd&nbsp;quick_location<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<h3><span>9.4 CPU\u7ea7\u522b\u706b\u7130\u56fe<\/span><\/h3>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">cpu\u5360\u7528\u8fc7\u9ad8\uff0c\u6216\u8005\u4f7f\u7528\u7387\u63d0\u4e0d\u4e0a\u6765\uff0c\u4f60\u80fd\u5feb\u901f\u5b9a\u4f4d\u5230\u4ee3\u7801\u7684\u54ea\u5757\u6709\u95ee\u9898\u5417\uff1f<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u4e00\u822c\u7684\u505a\u6cd5\u53ef\u80fd\u5c31\u662f\u901a\u8fc7\u65e5\u5fd7\u7b49\u65b9\u5f0f\u53bb\u786e\u5b9a\u95ee\u9898\u3002\u73b0\u5728\u6211\u4eec\u6709\u4e86\u706b\u7130\u56fe\uff0c\u80fd\u591f\u975e\u5e38\u6e05\u6670\u7684\u53d1\u73b0\u54ea\u4e2a\u51fd\u6570\u5360\u7528cpu\u8fc7\u9ad8\uff0c\u6216\u8005\u8fc7\u4f4e\u5bfc\u81f4\u7684\u95ee\u9898\u3002\u53e6\u5916\uff0c\u641c\u7d22\u516c\u4f17\u53f7Linux\u5c31\u8be5\u8fd9\u6837\u5b66\u540e\u53f0\u56de\u590d\u201c\u7334\u5b50\u201d\uff0c\u83b7\u53d6\u4e00\u4efd\u60ca\u559c\u793c\u5305\u3002<\/span><\/p>\n<h4>9.4.1 on-CPU<\/h4>\n<p><span style=\"font-size: 15px\">cpu\u5360\u7528\u8fc7\u9ad8\uff0c\u6267\u884c\u4e2d\u7684\u65f6\u95f4\u901a\u5e38\u53c8\u5206\u4e3a\u7528\u6237\u6001\u65f6\u95f4user\u548c\u7cfb\u7edf\u6001\u65f6\u95f4sys\u3002<\/span><br \/>\n<span style=\"font-size: 15px\">\u4f7f\u7528\u65b9\u5f0f\uff1a<\/span>    <\/p>\n<pre>\/\/on-CPU&nbsp;usersh&nbsp;ngx_on_cpu_u.sh&nbsp;pid\/\/\u8fdb\u5165\u7ed3\u679c\u76ee\u5f55&nbsp;cd&nbsp;ngx_on_cpu_u\/\/on-CPU&nbsp;kernelsh&nbsp;ngx_on_cpu_k.sh&nbsp;pid\/\/\u8fdb\u5165\u7ed3\u679c\u76ee\u5f55&nbsp;cd&nbsp;ngx_on_cpu_k\/\/\u5f00\u4e00\u4e2a\u4e34\u65f6\u7aef\u53e3&nbsp;8088&nbsp;python&nbsp;-m&nbsp;SimpleHTTPServer&nbsp;8088\/\/\u6253\u5f00\u6d4f\u89c8\u5668\u8f93\u5165\u5730\u5740127.0.0.1:8088\/pid.svg<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236     <\/p>\n<pre>DEMO\uff1a<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236     <\/p>\n<pre>#include&nbsp;&lt;stdio.h&gt;#include&nbsp;&lt;stdlib.h&gt;\nvoid&nbsp;foo3(){&nbsp;&nbsp;}\nvoid&nbsp;foo2(){&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i;&nbsp;&nbsp;&nbsp;&nbsp;for(i=0&nbsp;;&nbsp;i&nbsp;&lt;\/stdlib.h&gt;&lt;\/stdio.h&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">DEMO\u706b\u7130\u56fe\uff1a<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/6f771f36bd197fd0d2dc0bc64886ffea-6.jpg\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe6\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe6\" \/><\/p>\n<h4>9.4.2 off-CPU<\/h4>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">cpu\u8fc7\u4f4e\uff0c\u5229\u7528\u7387\u4e0d\u9ad8\u3002\u7b49\u5f85\u4e0b\u4e00\u8f6eCPU\uff0c\u6216\u8005\u7b49\u5f85I\/O\u3001\u9501\u3001\u6362\u9875\u7b49\u7b49\uff0c\u5176\u72b6\u6001\u53ef\u4ee5\u7ec6\u5206\u4e3a\u53ef\u6267\u884c\u3001\u533f\u540d\u6362\u9875\u3001\u7761\u7720\u3001\u9501\u3001\u7a7a\u95f2\u7b49\u72b6\u6001\u3002<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u4f7f\u7528\u65b9\u5f0f\uff1a<\/span><\/p>\n<pre>\/\/&nbsp;off-CPU&nbsp;usersh&nbsp;ngx_off_cpu_u.sh&nbsp;pid\/\/\u8fdb\u5165\u7ed3\u679c\u76ee\u5f55cd&nbsp;ngx_off_cpu_u\/\/off-CPU&nbsp;kernelsh&nbsp;ngx_off_cpu_k.sh&nbsp;pid\/\/\u8fdb\u5165\u7ed3\u679c\u76ee\u5f55cd&nbsp;ngx_off_cpu_k\/\/\u5f00\u4e00\u4e2a\u4e34\u65f6\u7aef\u53e38088python&nbsp;-m&nbsp;SimpleHTTPServer&nbsp;8088\/\/\u6253\u5f00\u6d4f\u89c8\u5668\u8f93\u5165\u5730\u5740127.0.0.1:8088\/pid.svg<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u5b98\u7f51DEMO\uff1a<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/87fbc7da95277c0212c6d460a71a3ce2-7.jpg\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe7\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe7\" \/><\/p>\n<h3>9.5 \u5185\u5b58\u7ea7\u522b\u706b\u7130\u56fe<\/h3>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u5982\u679c\u7ebf\u4e0a\u7a0b\u5e8f\u51fa\u73b0\u4e86\u5185\u5b58\u6cc4\u6f0f\uff0c\u5e76\u4e14\u53ea\u5728\u7279\u5b9a\u7684\u573a\u666f\u624d\u4f1a\u51fa\u73b0\u3002\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u600e\u4e48\u529e\u5462\uff1f\u6709\u4ec0\u4e48\u597d\u7684\u65b9\u5f0f\u548c\u5de5\u5177\u80fd\u5feb\u901f\u7684\u53d1\u73b0\u4ee3\u7801\u7684\u95ee\u9898\u5462\uff1f\u540c\u6837\u5185\u5b58\u7ea7\u522b\u706b\u7130\u56fe\u5e2e\u4f60\u5feb\u901f\u5206\u6790\u95ee\u9898\u7684\u6839\u6e90\u3002<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u4f7f\u7528\u65b9\u5f0f\uff1a<\/span><\/p>\n<pre>sh&nbsp;ngx_on_memory.sh&nbsp;pid\/\/\u8fdb\u5165\u7ed3\u679c\u76ee\u5f55cd&nbsp;ngx_on_memory\/\/\u5f00\u4e00\u4e2a\u4e34\u65f6\u7aef\u53e38088python&nbsp;-m&nbsp;SimpleHTTPServer&nbsp;8088\/\/\u6253\u5f00\u6d4f\u89c8\u5668\u8f93\u5165\u5730\u5740127.0.0.1:8088\/pid.svg<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u5b98\u7f51DEMO\uff1a<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/87fbc7da95277c0212c6d460a71a3ce2-8.jpg\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe8\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe8\" \/><\/p>\n<h2><span>9.6 \u6027\u80fd\u56de\u9000-\u7ea2\u84dd\u5dee\u5206\u706b\u7130\u56fe<\/span><\/h2>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u4f60\u80fd\u5feb\u901f\u5b9a\u4f4dCPU\u6027\u80fd\u56de\u9000\u7684\u95ee\u9898\u4e48\uff1f\u5982\u679c\u4f60\u7684\u5de5\u4f5c\u73af\u5883\u975e\u5e38\u590d\u6742\u4e14\u53d8\u5316\u5feb\u901f\uff0c\u90a3\u4e48\u4f7f\u7528\u73b0\u6709\u7684\u5de5\u5177\u662f\u6765\u5b9a\u4f4d\u8fd9\u7c7b\u95ee\u9898\u662f\u5f88\u5177\u6709\u6311\u6218\u6027\u7684\u3002\u5f53\u4f60\u82b1\u6389\u6570\u5468\u65f6\u95f4\u628a\u6839\u56e0\u627e\u5230\u65f6\uff0c\u4ee3\u7801\u5df2\u7ecf\u53c8\u53d8\u66f4\u4e86\u597d\u51e0\u8f6e\uff0c\u65b0\u7684\u6027\u80fd\u95ee\u9898\u53c8\u5192\u4e86\u51fa\u6765\u3002\u4e3b\u8981\u53ef\u4ee5\u7528\u5230\u6bcf\u6b21\u6784\u5efa\u4e2d\uff0c\u6bcf\u6b21\u4e0a\u7ebf\u505a\u5bf9\u6bd4\u770b\uff0c\u5982\u679c\u635f\u5931\u4e25\u91cd\u53ef\u4ee5\u7acb\u9a6c\u89e3\u51b3\u4fee\u590d\u3002<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u901a\u8fc7\u6293\u53d6\u4e86\u4e24\u5f20\u666e\u901a\u7684\u706b\u7130\u56fe\uff0c\u7136\u540e\u8fdb\u884c\u5bf9\u6bd4\uff0c\u5e76\u5bf9\u5dee\u5f02\u90e8\u5206\u8fdb\u884c\u6807\u8272\uff1a\u7ea2\u8272\u8868\u793a\u4e0a\u5347\uff0c\u84dd\u8272\u8868\u793a\u4e0b\u964d\u3002\u5dee\u5206\u706b\u7130\u56fe\u662f\u4ee5\u5f53\u524d\uff08\u201c\u4fee\u6539\u540e\u201d\uff09\u7684profile\u6587\u4ef6\u4f5c\u4e3a\u57fa\u51c6\uff0c\u5f62\u72b6\u548c\u5927\u5c0f\u90fd\u4fdd\u6301\u4e0d\u53d8\u3002\u56e0\u6b64\u4f60\u901a\u8fc7\u8272\u5f69\u7684\u5dee\u5f02\u5c31\u80fd\u591f\u5f88\u76f4\u89c2\u7684\u627e\u5230\u5dee\u5f02\u90e8\u5206\uff0c\u4e14\u53ef\u4ee5\u770b\u51fa\u4e3a\u4ec0\u4e48\u4f1a\u6709\u8fd9\u6837\u7684\u5dee\u5f02\u3002<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u4f7f\u7528\u65b9\u5f0f\uff1a<\/span><\/p>\n<pre>cd&nbsp;quick_location\/\/\u6293\u53d6\u4ee3\u7801\u4fee\u6539\u524d\u7684profile&nbsp;1\u6587\u4ef6perf&nbsp;record&nbsp;-F&nbsp;99&nbsp;-p&nbsp;pid&nbsp;-g&nbsp;--&nbsp;sleep&nbsp;30perf&nbsp;script&nbsp;&amp;gt;&nbsp;out.stacks1\/\/\u6293\u53d6\u4ee3\u7801\u4fee\u6539\u540e\u7684profile&nbsp;2\u6587\u4ef6perf&nbsp;record&nbsp;-F&nbsp;99&nbsp;-p&nbsp;pid&nbsp;-g&nbsp;--&nbsp;sleep&nbsp;30perf&nbsp;script&nbsp;&amp;gt;&nbsp;out.stacks2\/\/\u751f\u6210\u5dee\u5206\u706b\u7130\u56fe:.\/FlameGraph\/stackcollapse-perf.pl&nbsp;..\/out.stacks1&nbsp;&amp;gt;&nbsp;out.folded1.\/FlameGraph\/stackcollapse-perf.pl&nbsp;..\/out.stacks2&nbsp;&amp;gt;&nbsp;out.folded2.\/FlameGraph\/difffolded.pl&nbsp;out.folded1&nbsp;out.folded2&nbsp;|&nbsp;.\/FlameGraph\/flamegraph.pl&nbsp;&amp;gt;&nbsp;diff2.svg<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">DEMO\uff1a<\/span><\/p>\n<pre>\/\/test.c#include&nbsp;&lt;stdio.h&gt;#include&nbsp;&lt;stdlib.h&gt;\nvoid&nbsp;foo3(){&nbsp;&nbsp;}\nvoid&nbsp;foo2(){&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;i;&nbsp;&nbsp;&nbsp;&nbsp;for(i=0&nbsp;;&nbsp;i&nbsp;#include&nbsp;&lt;stdlib.h&gt;\nvoid&nbsp;foo3(){\n}\nvoid&nbsp;foo2(){&nbsp;&nbsp;int&nbsp;i;&nbsp;&nbsp;for(i=0&nbsp;;&nbsp;i&nbsp;&lt;\/stdlib.h&gt;&lt;\/stdlib.h&gt;&lt;\/stdio.h&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">DEMO\u7ea2\u84dd\u5dee\u5206\u706b\u7130\u56fe\uff1a<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/87fbc7da95277c0212c6d460a71a3ce2-9.jpg\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe9\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe9\" \/><\/p>\n<h2>10. \u6848\u4f8b\u5206\u6790<\/h2>\n<h3>10.1 \u63a5\u5165\u5c42nginx\u96c6\u7fa4\u5f02\u5e38\u73b0\u8c61<\/h3>\n<p><span style=\"font-size: 15px\">\u901a\u8fc7\u76d1\u63a7\u63d2\u4ef6\u53d1\u73b0\u5728 2017.09.25 19 \u70b9nginx\u96c6\u7fa4\u8bf7\u6c42\u6d41\u91cf\u51fa\u73b0\u5927\u91cf\u7684499\uff0c5xx\u72b6\u6001\u7801\u3002\u5e76\u4e14\u53d1\u73b0\u673a\u5668cpu\u4f7f\u7528\u7387\u5347\u9ad8\uff0c\u76ee\u524d\u4e00\u76f4\u6301\u7eed\u4e2d\u3002\u53e6\u5916\uff0c\u641c\u7d22\u516c\u4f17\u53f7\u9876\u7ea7\u7b97\u6cd5\u540e\u53f0\u56de\u590d\u201c\u7b97\u6cd5\u201d\uff0c\u83b7\u53d6\u4e00\u4efd\u60ca\u559c\u793c\u5305\u3002<\/span>  <\/p>\n<h3>10.2 \u5206\u6790nginx\u76f8\u5173\u6307\u6807<\/h3>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">a)&nbsp;<em>**<\/em>\u5206\u6790nginx\u8bf7\u6c42\u6d41\u91cf\uff1a<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/87fbc7da95277c0212c6d460a71a3ce2-10.jpg\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe10\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe10\" \/><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u7ed3\u8bba\uff1a<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u901a\u8fc7\u4e0a\u56fe\u53d1\u73b0\u6d41\u91cf\u5e76\u6ca1\u6709\u7a81\u589e\uff0c\u53cd\u800c\u4e0b\u964d\u4e86\uff0c\u8ddf\u8bf7\u6c42\u6d41\u91cf\u7a81\u589e\u6ca1\u5173\u7cfb\u3002<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">b)&nbsp;<em>**<\/em>\u5206\u6790nginx\u54cd\u5e94\u65f6\u95f4<\/span><br \/><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/87fbc7da95277c0212c6d460a71a3ce2-11.jpg\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe11\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe11\" \/><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u7ed3\u8bba\uff1a<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u901a\u8fc7\u4e0a\u56fe\u53d1\u73b0nginx\u7684\u54cd\u5e94\u65f6\u95f4\u6709\u589e\u52a0\u53ef\u80fd\u8ddfnginx\u81ea\u8eab\u6709\u5173\u7cfb\u6216\u8005\u8ddf\u540e\u7aefupstream\u54cd\u5e94\u65f6\u95f4\u6709\u5173\u7cfb\u3002<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">c)&nbsp;<em>**<\/em>\u5206\u6790nginx upstream\u54cd\u5e94\u65f6\u95f4<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/773360b92e15f55feee12c3ea49ff2be-12.jpg\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe12\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe12\" \/><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u7ed3\u8bba\uff1a<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u901a\u8fc7\u4e0a\u56fe\u53d1\u73b0nginx upstream \u54cd\u5e94\u65f6\u95f4\u6709\u589e\u52a0\uff0c\u76ee\u524d\u731c\u6d4b\u53ef\u80fd\u540e\u7aefupstream\u54cd\u5e94\u65f6\u95f4\u62d6\u4f4fnginx\uff0c\u5bfc\u81f4nginx\u51fa\u73b0\u8bf7\u6c42\u6d41\u91cf\u5f02\u5e38\u3002<\/span><\/p>\n<h3><span>10.3 \u5206\u6790\u7cfb\u7edfcpu\u60c5\u51b5<\/span><\/h3>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">a)&nbsp;<em>**<\/em>\u901a\u8fc7top\u89c2\u5bdf\u7cfb\u7edf\u6307\u6807<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\">top<\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/773360b92e15f55feee12c3ea49ff2be-13.jpg\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe13\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe13\" \/><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u7ed3\u8bba\uff1a<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u53d1\u73b0nginx worker cpu\u6bd4\u8f83\u9ad8<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">b)&nbsp;<em>**<\/em>\u5206\u6790nginx\u8fdb\u7a0b\u5185\u90e8cpu\u60c5\u51b5<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\">perf top -p pid<\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u7ed3\u8bba\uff1a<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u53d1\u73b0\u4e3b\u8981\u5f00\u9500\u5728free,malloc,json\u89e3\u6790\u4e0a\u9762<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">10.4 \u706b\u7130\u56fe\u5206\u6790cpu<br \/>a)&nbsp;<em>**<\/em>\u751f\u6210\u7528\u6237\u6001cpu\u706b\u7130\u56fe<\/span><\/p>\n<pre>\/\/on-CPU&nbsp;usersh&nbsp;ngx_on_cpu_u.sh&nbsp;pid\/\/\u8fdb\u5165\u7ed3\u679c\u76ee\u5f55cd&nbsp;ngx_on_cpu_u\/\/\u5f00\u4e00\u4e2a\u4e34\u65f6\u7aef\u53e38088python&nbsp;-m&nbsp;SimpleHTTPServer&nbsp;8088\/\/\u6253\u5f00\u6d4f\u89c8\u5668\u8f93\u5165\u5730\u5740127.0.0.1:8088\/pid.svg<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/773360b92e15f55feee12c3ea49ff2be-14.jpg\" class=\"aligncenter\" title=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe14\" alt=\"Linux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u63d2\u56fe14\" \/><\/p>\n<p style=\"margin-bottom: 0px;letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\"><strong>\u7ed3\u8bba\uff1a<\/strong><\/span><\/p>\n<p style=\"margin-bottom: 0px;letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u53d1\u73b0\u4ee3\u7801\u91cc\u9762\u6709\u9891\u7e41\u7684\u89e3\u6790json\u64cd\u4f5c\uff0c\u5e76\u4e14\u53d1\u73b0\u8fd9\u4e2ajson\u5e93\u6027\u80fd\u4e0d\u9ad8\uff0c\u5360\u7528cpu\u633a\u9ad8\u3002<\/span><\/p>\n<h3><span>10.5 \u6848\u4f8b\u603b\u7ed3<\/span><\/h3>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\"><strong>a)&nbsp;<\/strong>\u5206\u6790\u8bf7\u6c42\u6d41\u91cf\u5f02\u5e38\uff0c\u5f97\u51fanginx upstream\u540e\u7aef\u673a\u5668\u54cd\u5e94\u65f6\u95f4\u62c9\u957f<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\"><strong>b)&nbsp;<\/strong>\u5206\u6790nginx\u8fdb\u7a0bcpu\u9ad8\uff0c\u5f97\u51fanginx\u5185\u90e8\u6a21\u5757\u4ee3\u7801\u6709\u8017\u65f6\u7684json\u89e3\u6790\u4ee5\u53ca\u5185\u5b58\u5206\u914d\u56de\u6536\u64cd\u4f5c<\/span><\/p>\n<h4><span>10.5.1 \u6df1\u5165\u5206\u6790<\/span><\/h4>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u6839\u636e\u4ee5\u4e0a\u4e24\u70b9\u95ee\u9898\u5206\u6790\u7684\u7ed3\u8bba\uff0c\u6211\u4eec\u8fdb\u4e00\u6b65\u6df1\u5165\u5206\u6790\u3002<\/span><\/p>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u540e\u7aefupstream\u54cd\u5e94\u62c9\u957f\uff0c\u6700\u591a\u53ef\u80fd\u5f71\u54cdnginx\u7684\u5904\u7406\u80fd\u529b\u3002\u4f46\u662f\u4e0d\u53ef\u80fd\u4f1a\u5f71\u54cdnginx\u5185\u90e8\u6a21\u5757\u5360\u7528\u8fc7\u591a\u7684cpu\u64cd\u4f5c\u3002\u5e76\u4e14\u5f53\u65f6\u5360\u7528cpu\u9ad8\u7684\u6a21\u5757\uff0c\u662f\u5728\u8bf7\u6c42\u7684\u65f6\u5019\u624d\u4f1a\u8d70\u7684\u903b\u8f91\u3002\u4e0d\u592a\u53ef\u80fd\u662fupstram\u540e\u7aef\u62d6\u4f4fnginx\uff0c\u4ece\u800c\u89e6\u53d1\u8fd9\u4e2acpu\u7684\u8017\u65f6\u64cd\u4f5c\u3002<\/span><\/p>\n<h3><span>10.5.2 \u89e3\u51b3\u65b9\u5f0f<\/span><\/h3>\n<p style=\"letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont,\"><span style=\"font-size: 15px\">\u9047\u5230\u8fd9\u79cd\u95ee\u9898\uff0c\u6211\u4eec\u4f18\u5148\u89e3\u51b3\u5df2\u77e5\u7684\uff0c\u5e76\u4e14\u975e\u5e38\u660e\u786e\u7684\u95ee\u9898\u3002\u90a3\u5c31\u662fcpu\u9ad8\u7684\u95ee\u9898\u3002\u89e3\u51b3\u65b9\u5f0f\u5148\u964d\u7ea7\u5173\u95ed\u5360\u7528cpu\u8fc7\u9ad8\u7684\u6a21\u5757\uff0c\u7136\u540e\u8fdb\u884c\u89c2\u5bdf\u3002\u7ecf\u8fc7\u964d\u7ea7\u5173\u95ed\u8be5\u6a21\u5757cpu\u964d\u4e0b\u6765\u4e86\uff0c\u5e76\u4e14nginx\u8bf7\u6c42\u6d41\u91cf\u4e5f\u6b63\u5e38\u4e86\u3002\u4e4b\u6240\u4ee5\u4f1a\u5f71\u54cdupstream\u65f6\u95f4\u62c9\u957f\uff0c\u56e0\u4e3aupstream\u540e\u7aef\u7684\u670d\u52a1\u8c03\u7528\u7684\u63a5\u53e3\u53ef\u80fd\u662f\u4e2a\u73af\u8def\u518d\u6b21\u8d70\u56de\u5230nginx\u3002<\/span><\/p>\n<h2>11.\u53c2\u8003\u8d44\u6599<\/h2>\n<ul>\n<li>\n<p><span>http:\/\/www.brendangregg.com\/index.html<\/span><\/p>\n<\/li>\n<li>\n<p><span>http:\/\/www.brendangregg.com\/FlameGraphs\/cpuflamegraphs.html<\/span><\/p>\n<\/li>\n<li>\n<p><span>http:\/\/www.brendangregg.com\/FlameGraphs\/memoryflamegraphs.html<\/span><\/p>\n<\/li>\n<li>\n<p><span>http:\/\/www.brendangregg.com\/FlameGraphs\/offcpuflamegraphs.html<\/span><\/p>\n<\/li>\n<li>\n<p><span>http:\/\/www.brendangregg.com\/blog\/2014-11-09\/differential-flame-graphs.html<\/span><\/p>\n<\/li>\n<li>\n<p><span>https:\/\/github.com\/openresty\/openresty-systemtap-toolkit<\/span><\/p>\n<\/li>\n<li>\n<p><span>https:\/\/github.com\/brendangregg\/FlameGraph<\/span><\/p>\n<\/li>\n<li>  <span>https:\/\/www.slideshare.net\/brendangregg\/blazing-performance-with-flame-graphs<\/span> <\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fLinux \u8fd0\u7ef4\u6545\u969c\u6392\u67e5\u601d\u8def\uff0c\u6709\u8fd9\u7bc7\u6587\u7ae0\u5c31\u591f\u4e86~\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.&nbsp;\u80cc\u666f \u6709\u65f6\u5019\u4f1a\u9047\u5230\u4e00\u4e9b\u7591\u96be\u6742\u75c7\uff0c\u5e76\u4e14\u76d1\u63a7\u63d2\u4ef6\u5e76\u4e0d\u80fd\u4e00\u773c\u7acb\u9a6c\u53d1\u73b0\u95ee\u9898\u7684\u6839\u6e90\u3002\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u767b\u5f55\u670d\u52a1\u5668\u8fdb\u4e00\u6b65\u6df1\u5165\u5206\u6790\u95ee\u9898\u7684\u6839\u6e90\u3002\u90a3\u4e48\u5206\u6790\u95ee\u9898\u9700\u8981\u6709\u4e00\u5b9a\u7684\u6280\u672f\u7ecf\u9a8c\u79ef\u7d2f\uff0c\u5e76\u4e14\u6709\u4e9b\u95ee\u9898\u6d89\u53ca\u5230\u7684\u9886\u57df\u975e\u5e38\u5e7f\uff0c\u624d\u80fd\u5b9a\u4f4d\u5230\u95ee\u9898\u3002\u6240\u4ee5\uff0c\u5206\u6790\u95ee\u9898\u548c\u8e29\u5751\u662f\u975e\u5e38\u953b\u70bc\u4e00\u4e2a\u4eba\u7684\u6210\u957f\u548c\u63d0\u5347\u81ea\u6211\u80fd\u529b\u3002\u5982\u679c\u6211\u4eec\u6709\u4e00\u5957\u597d\u7684\u5206\u6790\u5de5\u5177\uff0c\u90a3\u5c06\u662f\u4e8b\u534a\u529f\u500d\uff0c\u80fd\u591f\u5e2e\u52a9\u5927\u5bb6\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\uff0c\u8282\u7701\u5927\u5bb6\u5f88\u591a\u65f6\u95f4\u505a\u66f4\u6df1\u5165\u7684\u4e8b\u60c5\u3002 2. \u8bf4\u660e \u672c\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u5404\u79cd\u95ee\u9898\u5b9a\u4f4d\u7684\u5de5\u5177\u4ee5\u53ca\u4f1a\u7ed3\u5408\u6848\u4f8b\u5206\u6790\u95ee\u9898\u3002 3. \u5206\u6790\u95ee\u9898\u7684\u65b9\u6cd5\u8bba \u5957\u75285W2H\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u51fa\u6027\u80fd\u5206\u6790\u7684\u51e0\u4e2a\u95ee\u9898 What-\u73b0\u8c61\u662f\u4ec0\u4e48\u6837\u7684 When-\u4ec0\u4e48\u65f6\u5019\u53d1\u751f Why-\u4e3a\u4ec0\u4e48\u4f1a\u53d1\u751f Where-\u54ea\u4e2a\u5730\u65b9\u53d1\u751f\u7684\u95ee\u9898 How much-\u8017\u8d39\u4e86\u591a\u5c11\u8d44\u6e90 How to do-\u600e\u4e48\u89e3\u51b3\u95ee\u9898 4. cpu 4.1 \u8bf4\u660e \u9488\u5bf9\u5e94\u7528\u7a0b\u5e8f\uff0c\u6211\u4eec\u901a\u5e38\u5173\u6ce8\u7684\u662f\u5185\u6838CPU\u8c03\u5ea6\u5668\u529f\u80fd\u548c\u6027\u80fd\u3002 \u7ebf\u7a0b\u7684\u72b6\u6001\u5206\u6790\u4e3b\u8981\u662f\u5206\u6790\u7ebf\u7a0b\u7684\u65f6\u95f4\u7528\u5728\u4ec0\u4e48\u5730\u65b9\uff0c\u800c\u7ebf\u7a0b\u72b6\u6001\u7684\u5206\u7c7b\u4e00\u822c\u5206\u4e3a\uff1a on-CPU\uff1a\u6267\u884c\u4e2d\uff0c\u6267\u884c\u4e2d\u7684\u65f6\u95f4\u901a\u5e38\u53c8\u5206\u4e3a\u7528\u6237\u6001\u65f6\u95f4user\u548c\u7cfb\u7edf\u6001\u65f6\u95f4sys\u3002 off-CPU\uff1a\u7b49\u5f85\u4e0b\u4e00\u8f6e\u4e0aCPU\uff0c\u6216\u8005\u7b49\u5f85I\/O\u3001\u9501\u3001\u6362\u9875\u7b49\u7b49\uff0c\u5176\u72b6\u6001\u53ef\u4ee5\u7ec6\u5206\u4e3a\u53ef\u6267\u884c\u3001\u533f\u540d\u6362\u9875\u3001\u7761\u7720\u3001\u9501\u3001\u7a7a\u95f2\u7b49\u72b6\u6001\u3002 \u5982\u679c\u5927\u91cf\u65f6\u95f4\u82b1\u5728CPU\u4e0a\uff0c\u5bf9CPU\u7684\u5256\u6790\u80fd\u591f\u8fc5\u901f\u89e3\u91ca\u539f\u56e0\uff1b\u5982\u679c\u7cfb\u7edf\u65f6\u95f4\u5927\u91cf\u5904\u4e8eoff-cpu\u72b6\u6001\uff0c\u5b9a\u4f4d\u95ee\u9898\u5c31\u4f1a\u8d39\u65f6\u5f88\u591a\u3002\u4f46\u662f\u4ecd\u7136\u9700\u8981\u6e05\u695a\u4e00\u4e9b\u6982\u5ff5\uff1a \u5904\u7406\u5668 \u6838 \u786c\u4ef6\u7ebf\u7a0b CPU\u5185\u5b58\u7f13\u5b58 \u65f6\u949f\u9891\u7387 \u6bcf\u6307\u4ee4\u5468\u671f\u6570CPI\u548c\u6bcf\u5468\u671f\u6307\u4ee4\u6570IPC CPU\u6307\u4ee4 \u4f7f\u7528\u7387 \u7528\u6237\u65f6\u95f4\uff0f\u5185\u6838\u65f6\u95f4 \u8c03\u5ea6\u5668 \u8fd0\u884c\u961f\u5217 \u62a2\u5360 \u591a\u8fdb\u7a0b \u591a\u7ebf\u7a0b \u5b57\u957f 4.2 \u5206\u6790\u5de5\u5177 \u8bf4\u660e: uptime\uff0cvmstat\uff0cmpstat\uff0ctop\uff0cpidstat \u53ea\u80fd\u67e5\u8be2\u5230cpu\u53ca\u8d1f\u8f7d\u7684\u7684\u4f7f\u7528\u60c5\u51b5\u3002 perf\u53ef\u4ee5\u8ddf\u7740\u5230\u8fdb\u7a0b\u5185\u90e8\u5177\u4f53\u51fd\u6570\u8017\u65f6\u60c5\u51b5\uff0c\u5e76\u4e14\u53ef\u4ee5\u6307\u5b9a\u5185\u6838\u51fd\u6570\u8fdb\u884c\u7edf\u8ba1\uff0c\u6307\u54ea\u6253\u54ea\u3002 4.3 \u4f7f\u7528\u65b9\u5f0f \/\/\u67e5\u770b\u7cfb\u7edfcpu\u4f7f\u7528\u60c5\u51b5top \/\/\u67e5\u770b\u6240\u6709cpu\u6838\u4fe1\u606fmpstat&nbsp;-P&nbsp;ALL&nbsp;1 \/\/\u67e5\u770bcpu\u4f7f\u7528\u60c5\u51b5\u4ee5\u53ca\u5e73\u5747\u8d1f\u8f7dvmstat&nbsp;1 \/\/\u8fdb\u7a0bcpu\u7684\u7edf\u8ba1\u4fe1\u606fpidstat&nbsp;-u&nbsp;1&nbsp;-p&nbsp;pid \/\/\u8ddf\u8e2a\u8fdb\u7a0b\u5185\u90e8\u51fd\u6570\u7ea7cpu\u4f7f\u7528\u60c5\u51b5&nbsp;perf&nbsp;top&nbsp;-p&nbsp;pid&nbsp;-e&nbsp;cpu-clock \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-16558","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/16558","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=16558"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/16558\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=16558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=16558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=16558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}