{"id":3227,"date":"2024-09-29T10:18:07","date_gmt":"2024-09-29T02:18:07","guid":{"rendered":"https:\/\/maofun.com\/?p=3227"},"modified":"2024-09-29T10:18:08","modified_gmt":"2024-09-29T02:18:08","slug":"%e6%9c%8d%e5%8a%a1%e5%99%a8%e8%8e%ab%e5%90%8d%e7%9a%84%e5%86%85%e5%ad%98%e9%ab%98%e5%8d%a0%e7%94%a8-%e5%af%bc%e8%87%b4-mysql-%e5%81%9c%e6%ad%a2%e8%bf%90%e8%a1%8c%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/maofun.com\/3227.html","title":{"rendered":"\u670d\u52a1\u5668\u83ab\u540d\u7684\u5185\u5b58\u9ad8\u5360\u7528 \u5bfc\u81f4 MySQL \u505c\u6b62\u8fd0\u884c\u95ee\u9898"},"content":{"rendered":"<p>\u8fd9\u95ee\u9898\u662f\u5e74\u540e\u5f00\u59cb\u51fa\u73b0\u7684\uff0c\u670d\u52a1\u5668\u5185\u5b58\u5360\u7528\u8d8a\u6765\u8d8a\u9ad8\uff0c\u4e00\u5ea6\u8fbe\u523090%\uff0c\u6700\u540e MySQL \u90fd\u505c\u6b62\u8fd0\u884c\u4e86\u3002\u8d34\u5427\u7b7e\u5230\u7684\u6570\u636e\u5e93\u7528\u6237 ID \u8fd9\u4e00\u9879\u4e5f\u4e22\u5931\u4e86\uff0c\u5bfc\u81f4\u65e0\u6cd5\u7b7e\u5230\uff0c\u65ad\u7b7e\u4e86\u597d\u4e9b\u5929\uff0c\u88ab\u63d0\u9192\u624d\u53d1\u73b0\uff0c\u8981\u6328\u6253\u7684\u3002\u5e78\u597d\u8bbe\u7f6e\u4e86\u81ea\u52a8\u5907\u4efd\uff0c\u628a\u6570\u636e\u6062\u590d\uff0c\u7136\u540e\u63d0\u9ad8\u4e86\u7b7e\u5230\u9891\u7387\uff0c\u6ca1\u60f3\u5230\u540e\u8fb9\u53cd\u590d\u51fa\u73b0\u4e86\u51e0\u6b21\uff0c\u4e0d\u5f97\u4e0d\u91cd\u89c6\u3002<\/p>\n<p id=\"FirstImg\" align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3228\" src=\"https:\/\/maofun.com\/wp-content\/uploads\/2024\/09\/memory-and-mysql-boom.jpg\" alt=\"\u670d\u52a1\u5668\u83ab\u540d\u7684\u5185\u5b58\u9ad8\u5360\u7528 \u5bfc\u81f4 MySQL \u505c\u6b62\u8fd0\u884c\u95ee\u9898\" width=\"778\" height=\"444\" srcset=\"https:\/\/maofun.com\/wp-content\/uploads\/2024\/09\/memory-and-mysql-boom.jpg 778w, https:\/\/maofun.com\/wp-content\/uploads\/2024\/09\/memory-and-mysql-boom-300x171.jpg 300w, https:\/\/maofun.com\/wp-content\/uploads\/2024\/09\/memory-and-mysql-boom-768x438.jpg 768w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/ alt=\"\u670d\u52a1\u5668\u83ab\u540d\u7684\u5185\u5b58\u9ad8\u5360\u7528 \u5bfc\u81f4 MySQL \u505c\u6b62\u8fd0\u884c\u95ee\u9898 - \u7b2c1\u5f20\u56fe\u7247\" title=\"\u670d\u52a1\u5668\u83ab\u540d\u7684\u5185\u5b58\u9ad8\u5360\u7528 \u5bfc\u81f4 MySQL \u505c\u6b62\u8fd0\u884c\u95ee\u9898 - \u7b2c1\u5f20\u56fe\u7247 | \u732b\u996d\" ><\/p>\n<p>\u51fa\u73b0\u4e86\u51e0\u6b21\u5c31\u4e0d\u662f\u5076\u7136\u4e86\uff0c\u6700\u540e\u6bcf\u6b21\u90fd\u98d9\u523085%\uff0c\u53ea\u80fd\u91cd\u542f\u670d\u52a1\u5668\u89e3\u51b3\u3002\u7b2c\u4e00\u6b21\u51fa\u73b0\u65f6\u4ee5\u4e3a\u662f MySQL \u6570\u636e\u5e93\u7684\u81ea\u8eab\u95ee\u9898\uff0c\u53ef\u80fd\u56e0\u670d\u52a1\u5668\u5185\u5b58\u5c0f\u800c\u5d29\u6e83\uff0c\u5b9e\u96451.8G \u7684\u8fd0\u884c\u5185\u5b58\u4e0d\u5927\u4e0d\u5c0f\u7684\u3002\u67e5\u4e86\u6570\u636e\u5e93\u65e5\u5fd7\u53d1\u73b0\u6570\u636e\u5e93\u56e0\u5206\u914d\u5185\u5b58\u4e0d\u8db3\u800c\u542f\u52a8\u5931\u8d25\uff0c\u7528 top \u547d\u4ee4\u4e5f\u67e5\u4e86\u4e0b\uff0c\u5185\u5b58\u9ad8\u5360\u7528\u7684\u524d 20 \u6709 MySQL\uff0c\u662f\u4e2a\u5927\u5934\uff0c\u4e8e\u662f\u6dfb\u52a0\u4e86 2G \u7684 Swap \u865a\u62df\u5185\u5b58\uff0c\u518d\u6dfb\u52a0\u4e86\u6570\u636e\u5e93\u8fdb\u7a0b\u5b88\u62a4\uff0c\u8ba1\u5212\u4efb\u52a1\u6bcf5\u5206\u949f\u8fd0\u884c\u4e00\u6b21\uff0c\u68c0\u6d4b\u5230 MySQL \u4e0d\u8fd0\u884c\u4e86\u5c31\u91cd\u65b0\u542f\u52a8\u3002<\/p>\n<pre><code class=\"hljs ruby\">pgrep -x mysqld &amp;&gt; <span class=\"hljs-regexp\">\/dev\/null<\/span>\r\n<span class=\"hljs-keyword\">if<\/span> [ $? -ne <span class=\"hljs-number\">0<\/span> ];<span class=\"hljs-keyword\">then<\/span>\r\n        bash \/www\/server\/panel\/script\/rememory.sh   \r\n        \/etc\/init.d\/mysqld start      \r\nfi\r\n<\/code><\/pre>\n<p>\u7ed3\u679c\u8fc7\u4e86\u4e9b\u5929\u95ee\u9898\u4f9d\u65e7\u51fa\u73b0\u4e86\uff0c4G \u5185\u5b58\u4e5f\u4e0d\u591f\u8017\u3002\u8fd9\u5c31\u6709\u70b9\u83ab\u540d\u5176\u5999\u7684\uff0c\u4e4b\u524d\u4e00\u76f4\u8fd0\u884c\u597d\u51e0\u5e74\u7a33\u5982\u72d7\u7684\uff0c\u600e\u4e48\u7a81\u7136\u5c31\u8fd9\u6837\u5462\uff1f\u56de\u60f3\u4e00\u4e0b\u81ea\u5df1\u7684\u64cd\u4f5c\uff0c\u9664\u4e86\u5347\u7ea7\u9ad8\u7248\u672c\u5b9d\u5854\u9762\u677f\u597d\u50cf\u5c31\u6ca1\u4e86\uff0c\u5347\u4e2a\u5927\u7248\u672c\u5e94\u8be5\u4e0d\u4f1a\u7a81\u7136\u5360\u7528\u98d9\u5347\u5427\uff0c\u67e5\u8fdb\u7a0b\u770b\u9762\u677f\u5360\u7528\u4e5f\u624d\u51e0\u5341 MB \uff0c\u5230\u8bba\u575b\u4e5f\u6ca1\u89c1\u6709\u4eba\u53cd\u9988\uff0c\u8bf4\u660e\u4e0d\u662f\u8fd9\u4e2a\u539f\u56e0\u3002<\/p>\n<p>\u6700\u540e\u7528 ps \u547d\u4ee4\u4ed4\u7ec6\u67e5\u770b\u4e86\u6240\u6709\u8fdb\u7a0b\uff0c\u7ec8\u4e8e\u53d1\u73b0\u4e86\u95ee\u9898\u7684\u6e90\u5934\uff0c\u662f\u8d34\u5427\u7b7e\u5230\u7684\u5b9a\u65f6\u4efb\u52a1\u548c php-fpm \u3002\u5982\u679c\u9700\u8981\u4e0d\u95f4\u65ad\u5730\u81ea\u52a8\u7b7e\u5230\uff0c\u90a3\u5c31\u5f97\u4e0d\u505c\u5730\u8bbf\u95ee\u6267\u884c\u7b7e\u5230\u7684 do.php \u9875\u9762\u3002\u8fdb\u7a0b\u4e2d\u53d1\u73b0\u4e86\u51e0\u5341\u4e2a\u6b63\u5728\u8fd0\u884c\u7684 do.php \u548cphp-fpm \u8fdb\u7a0b\u3002<\/p>\n<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3229\" src=\"https:\/\/maofun.com\/wp-content\/uploads\/2024\/09\/memory-and-mysql-boom03.jpg\" alt=\"\u670d\u52a1\u5668\u83ab\u540d\u7684\u5185\u5b58\u9ad8\u5360\u7528 \u5bfc\u81f4 MySQL \u505c\u6b62\u8fd0\u884c\u95ee\u9898\" width=\"798\" height=\"371\" srcset=\"https:\/\/maofun.com\/wp-content\/uploads\/2024\/09\/memory-and-mysql-boom03.jpg 798w, https:\/\/maofun.com\/wp-content\/uploads\/2024\/09\/memory-and-mysql-boom03-300x139.jpg 300w, https:\/\/maofun.com\/wp-content\/uploads\/2024\/09\/memory-and-mysql-boom03-768x357.jpg 768w\" sizes=\"(max-width: 798px) 100vw, 798px\" \/ alt=\"\u670d\u52a1\u5668\u83ab\u540d\u7684\u5185\u5b58\u9ad8\u5360\u7528 \u5bfc\u81f4 MySQL \u505c\u6b62\u8fd0\u884c\u95ee\u9898 - \u7b2c2\u5f20\u56fe\u7247\" title=\"\u670d\u52a1\u5668\u83ab\u540d\u7684\u5185\u5b58\u9ad8\u5360\u7528 \u5bfc\u81f4 MySQL \u505c\u6b62\u8fd0\u884c\u95ee\u9898 - \u7b2c2\u5f20\u56fe\u7247 | \u732b\u996d\" ><\/p>\n<p>\u539f\u6765\u8bbe\u7f6e\u7684\u662f\u4e00\u5206\u949f\u6267\u884c\u4e00\u6b21\u7684 crontab \uff0c\u540e\u6765\u4f3c\u4e4e\u662f\u5acc\u7b7e\u5230\u592a\u6162\uff0c\u6211\u5c31\u5c31\u6309\u7740\u67e5\u5230\u7684\u65b9\u6cd5\u6539\u4e3a 10 \u79d2\u6267\u884c\u7b7e\u5230\u4e00\u6b21\uff1a<\/p>\n<pre><code class=\"hljs sql\">php \/www\/wwwroot\/qiandao\/do.php    \r\n<span class=\"hljs-keyword\">sleep<\/span> <span class=\"hljs-number\">10<\/span>; \r\nphp \/www\/wwwroot\/qiandao\/do.php\r\n<span class=\"hljs-keyword\">sleep<\/span> <span class=\"hljs-number\">20<\/span>; \r\nphp \/www\/wwwroot\/qiandao\/do.php\r\n<span class=\"hljs-keyword\">sleep<\/span> <span class=\"hljs-number\">30<\/span>; \r\nphp \/www\/wwwroot\/qiandao\/do.php \r\n<span class=\"hljs-keyword\">sleep<\/span> <span class=\"hljs-number\">40<\/span>; \r\nphp \/www\/wwwroot\/qiandao\/do.php\r\n<span class=\"hljs-keyword\">sleep<\/span> <span class=\"hljs-number\">50<\/span>;\r\nphp \/www\/wwwroot\/qiandao\/do.php\r\n<\/code><\/pre>\n<p>\u9762\u677f\u63d0\u4f9b\u7684\u8ba1\u5212\u4efb\u52a1\u529f\u80fd\u6700\u5c0f\u53ea\u80fd N \u5206\u949f\u6267\u884c\uff0c\u5c31\u67e5\u4e86\u4e0b\uff0c\u4e86\u89e3\u5230\u53ef\u4ee5\u7528 sleep \u6765\u5b9e\u73b0\u3002\u867d\u7136\u77e5\u9053\u5728 C++ \u7a0b\u5e8f\u4e2d\u957f\u65f6\u95f4\u5ef6\u8fdf\u4e0d\u80fd\u7528 sleep \uff0c\u90fd\u662f\u7528\u4e0d\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u5047\u6b7b\u963b\u585e\u7684\u5b9a\u65f6\u5668\uff0c\u4f46\u5728\u8fd9\u8ba1\u5212\u4efb\u52a1\u4e2dPHP\u7528\u5e94\u8be5\u6ca1\u95ee\u9898\u5427\uff1f\u8fd8\u662f to young to simple \u4e86\uff0c\u53bb\u9664 sleep \uff0c\u6539\u56de\u4e00\u5206\u949f\u6267\u884c\u4e00\u6b21\uff0c\u91cd\u542f\u670d\u52a1\u5668\uff0c\u518d\u4e5f\u6ca1\u51fa\u73b0\u5185\u5b58\u7206\u6ee1\u7684\u95ee\u9898\u4e86\uff0c\u56de\u5230\u4e86\u4ee5\u524d\u6b63\u5e38\u5360\u7528\u5185\u5b5860%\u5de6\u53f3\u3002<\/p>\n<p>\u6700\u5f00\u59cb\u53ea\u7528\u4e86 top \u67e5\u5185\u5b58\u9ad8\u5360\u7528\u7684\u524d 20 \u8fdb\u7a0b\uff0c\u6240\u4ee5\u6ca1\u53d1\u73b0\u662f do.php \u548c php-fpm \u7684\u539f\u56e0\u3002\u4e00\u4e2a\u8fdb\u7a0b\u53ea\u5360\u4e86\u4e0d\u5230 9 mb \uff0c\u867d\u7136PHP\u7ba1\u7406\u4e2d\u9650\u5236\u4e86 php-fpm \u6700\u5927\u5b50\u8fdb\u7a0b\u6570\u662f50\u4e2a\uff0c\u4f46\u523050\u4e2a\u540e\uff0cdo.php \u8fdb\u7a0b\u4e5f\u8fbe\u5230 50 \uff0c\u4e24\u4e2a\u52a0\u8d77\u6765\u5360\u7528\u5c31\u98d9\u5230 900 MB \u4e86\uff0c\u59a5\u59a5\u5730\u7206\u6ee1\u3002<\/p>\n<p>\u6b63\u5e38\u6211\u7684\u7f51\u7ad9 PHP \u9700\u6c42 \u662f\u4e0d\u4f1a\u4ea7\u751f\u51e0\u5341\u4e2a\u8fdb\u7a0b\u7684\uff0c\u662f\u4f7f\u7528 sleep \u5bfc\u81f4\u4e86\u8fd9\u4e2a\u95ee\u9898\u3002\u539f\u56e0\u5927\u6982\u662f\u91c7\u7528 FPM \u7ba1\u7406 PHP \u8fdb\u7a0b\uff0c\u7531\u4e8e sleep \u5bfc\u81f4\u963b\u585e\u7b49\u5f85\uff0cFPM \u5b9e\u9645\u5206\u914d\u4e86\u8fc7\u591a\u5b50\u8fdb\u7a0b\uff0c\u7136\u540e\u6211\u7684 PHP \u5e76\u53d1\u65b9\u6848\u662f\u8bbe\u7f6e\u7684 2G \uff0c\u95ee\u9898\u5c31\u8fd9\u4e48\u4ea7\u751f\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u95ee\u9898\u662f\u5e74\u540e\u5f00\u59cb\u51fa\u73b0\u7684\uff0c\u670d\u52a1\u5668\u5185\u5b58\u5360\u7528\u8d8a\u6765\u8d8a\u9ad8\uff0c\u4e00\u5ea6\u8fbe\u523090%\uff0c\u6700\u540e MySQL \u90fd\u505c\u6b62\u8fd0\u884c\u4e86\u3002\u8d34\u5427\u7b7e\u5230\u7684\u6570\u636e\u5e93\u7528\u6237 ID \u8fd9\u4e00\u9879\u4e5f\u4e22\u5931\u4e86\uff0c\u5bfc\u81f4\u65e0\u6cd5\u7b7e\u5230\uff0c\u65ad\u7b7e\u4e86\u597d\u4e9b\u5929\uff0c\u88ab\u63d0\u9192\u624d\u53d1\u73b0\uff0c\u8981\u6328\u6253\u7684\u3002\u5e78\u597d\u8bbe\u7f6e\u4e86\u81ea\u52a8\u5907\u4efd\uff0c\u628a\u6570\u636e\u6062\u590d\uff0c\u7136\u540e\u63d0\u9ad8\u4e86\u7b7e\u5230\u9891\u7387\uff0c\u6ca1\u60f3\u5230\u540e\u8fb9\u53cd\u590d\u51fa\u73b0\u4e86\u51e0\u6b21\uff0c\u4e0d\u5f97\u4e0d\u91cd\u89c6\u3002 \u51fa\u73b0\u4e86\u51e0\u6b21\u5c31\u4e0d\u662f\u5076\u7136\u4e86\uff0c\u6700\u540e\u6bcf\u6b21\u90fd\u98d9\u523085%\uff0c\u53ea\u80fd\u91cd\u542f\u670d\u52a1\u5668\u89e3\u51b3\u3002\u7b2c\u4e00\u6b21\u51fa\u73b0\u65f6\u4ee5\u4e3a\u662f MySQL \u6570\u636e\u5e93\u7684\u81ea\u8eab\u95ee\u9898\uff0c\u53ef\u80fd\u56e0\u670d\u52a1\u5668\u5185\u5b58\u5c0f\u800c\u5d29\u6e83\uff0c\u5b9e\u96451.8G \u7684\u8fd0\u884c\u5185\u5b58\u4e0d\u5927\u4e0d\u5c0f\u7684\u3002\u67e5\u4e86\u6570\u636e\u5e93\u65e5\u5fd7\u53d1\u73b0\u6570\u636e\u5e93\u56e0\u5206\u914d\u5185\u5b58\u4e0d\u8db3\u800c\u542f\u52a8\u5931\u8d25\uff0c\u7528 top \u547d\u4ee4\u4e5f\u67e5\u4e86\u4e0b\uff0c\u5185\u5b58\u9ad8\u5360\u7528\u7684\u524d 20 \u6709 MySQL\uff0c\u662f\u4e2a\u5927\u5934\uff0c\u4e8e\u662f\u6dfb\u52a0\u4e86 2&#8230;&#8230;<span class=\"read-more\"> <a href=\"https:\/\/maofun.com\/3227.html\"><\/p>\n<p>\u7ee7\u7eed\u9605\u8bfb&raquo;&raquo;&raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/maofun.com\/wp-json\/wp\/v2\/posts\/3227"}],"collection":[{"href":"https:\/\/maofun.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/maofun.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/maofun.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/maofun.com\/wp-json\/wp\/v2\/comments?post=3227"}],"version-history":[{"count":0,"href":"https:\/\/maofun.com\/wp-json\/wp\/v2\/posts\/3227\/revisions"}],"wp:attachment":[{"href":"https:\/\/maofun.com\/wp-json\/wp\/v2\/media?parent=3227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/maofun.com\/wp-json\/wp\/v2\/categories?post=3227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/maofun.com\/wp-json\/wp\/v2\/tags?post=3227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}