{"id":1547,"date":"2024-05-08T14:08:36","date_gmt":"2024-05-08T06:08:36","guid":{"rendered":"http:\/\/oneai.eu.org\/?p=1547"},"modified":"2024-05-08T14:08:36","modified_gmt":"2024-05-08T06:08:36","slug":"centos-cpulimit-%e5%ae%89%e8%a3%85%e4%b8%8e%e6%a1%88%e4%be%8b%ef%bc%8c%e9%99%90%e5%88%b6cpu%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/oneai.eu.org\/?p=1547","title":{"rendered":"Centos cpulimit \u5b89\u88c5\u4e0e\u6848\u4f8b\uff0c\u9650\u5236CPU\u4f7f\u7528"},"content":{"rendered":"<p>Centos cpulimit \u5b89\u88c5\u4e0e\u6848\u4f8b\uff0c\u9650\u5236CPU\u4f7f\u7528<br \/>\ncpulimit \u547d\u4ee4\u7684\u5de5\u4f5c\u539f\u7406\u662f\u4e3a\u8fdb\u7a0b\u9884\u8bbe\u4e00\u4e2a cpu \u5360\u7528\u7387\u95e8\u9650\uff0c\u5e76\u5b9e\u65f6\u76d1\u63a7\u8fdb\u7a0b\u662f\u5426\u8d85\u51fa\u6b64\u95e8\u9650\uff0c\u82e5\u8d85\u51fa\u5219\u8ba9\u8be5\u8fdb\u7a0b\u6682\u505c\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u3002cpulimit \u4f7f\u7528 SIGSTOP \u548c SIGCONT \u8fd9\u4e24\u4e2a\u4fe1\u53f7\u6765\u63a7\u5236\u8fdb\u7a0b\u3002\u5b83\u4e0d\u4f1a\u4fee\u6539\u8fdb\u7a0b\u7684 nice \u503c\uff0c\u800c\u662f\u901a\u8fc7\u76d1\u63a7\u8fdb\u7a0b\u7684 cpu \u5360\u7528\u7387\u6765\u505a\u51fa\u52a8\u6001\u8c03\u6574\u3002<\/p>\n<p>cpulimit \u7684\u4f18\u52bf\u662f\u53ef\u4ee5\u63a7\u5236\u8fdb\u7a0b\u7684cpu\u4f7f\u7528\u7387\u7684\u4e0a\u9650\u503c\u3002\u4f46\u4e0e nice \u76f8\u6bd4\u4e5f\u6709\u7f3a\u70b9\uff0c\u90a3\u5c31\u662f\u5373\u4f7f cpu \u662f\u7a7a\u95f2\u7684\uff0c\u8fdb\u7a0b\u4e5f\u4e0d\u80fd\u5b8c\u5168\u4f7f\u7528\u6574\u4e2a cpu \u8d44\u6e90\u3002<\/p>\n<p>\u5728 CentOS \u4e0a\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\u6765\u5b89\u88c5\u5b83\uff1a (yum install cpulimt -y )<\/p>\n<p>wget -O cpulimit.zip <a href=\"https:\/\/github.com\/opsengine\/cpulimit\/archive\/master.zip\">https:\/\/github.com\/opsengine\/cpulimit\/archive\/master.zip<\/a><br \/>\nunzip cpulimit.zip<br \/>\ncd cpulimit-master<br \/>\nmake<br \/>\nsudo cp src\/cpulimit \/usr\/bin<br \/>\n\u4e0a\u9762\u7684\u547d\u4ee4\u884c\uff0c\u4f1a\u5148\u4ece\u4ece GitHub \u4e0a\u5c06\u6e90\u7801\u4e0b\u8f7d\u5230\u672c\u5730\uff0c\u7136\u540e\u518d\u89e3\u538b\u3001\u7f16\u8bd1\u3001\u5e76\u5b89\u88c5\u5230 \/usr\/bin \u76ee\u5f55\u4e0b\u3002<\/p>\n<p>cpulimit \u7684\u4f7f\u7528\u65b9\u5f0f\u548c nice \u547d\u4ee4\u7c7b\u4f3c\uff0c\u4f46\u662f\u9700\u8981\u7528\u6237\u4f7f\u7528 -l \u9009\u9879\u663e\u5f0f\u5730\u5b9a\u4e49\u8fdb\u7a0b\u7684 cpu \u4f7f\u7528\u7387\u4e0a\u9650\u503c\u3002\u4e3e\u4f8b\u8bf4\u660e\uff1a<\/p>\n<p>cpulimit -l 50 matho-primes 0 9999999999 &gt; \/dev\/null &amp;<br \/>\ncpulimit<\/p>\n<p>\u4ece\u4e0a\u9762\u7684\u4f8b\u5b50\u53ef\u4ee5\u770b\u51fa matho-primes \u53ea\u4f7f\u7528\u4e8650%\u7684 cpu \u8d44\u6e90\uff0c\u5269\u4f59\u7684 cpu \u65f6\u95f4\u90fd\u5728 idle\u3002<\/p>\n<p>cpulimit \u5176\u4ed6\u5b9e\u4f8b\uff1a<\/p>\n<p>cpulimit -e httpd --limit 40 #\u9650\u5236httpd\uff08\u8fdb\u7a0b\u540d\uff09\u7684cpu\u4f7f\u7528\u7387\u4e3a40%<br \/>\ncpulimit -e \/usr\/local\/bin\/httpd --limit 40<br \/>\ncpulimit -p 2960 -l 55 #\u9650\u5236pid\u4e3a2960\u7684\u8fdb\u7a0b\u7684CPU\u5360\u7528\u4e3a55%<br \/>\n\u4f7f\u7528\u5e2e\u52a9\uff1a<br \/>\nUsage: cpulimit [OPTIONS...] TARGET<br \/>\nOPTIONS<br \/>\n-l, --limit=N percentage of cpu allowed from 0 to 3200 (required)<br \/>\n-v, --verbose show control statistics<br \/>\n-z, --lazy exit if there is no target process, or if it dies<br \/>\n-i, --include-children limit also the children processes<br \/>\n-h, --help display this help and exit<br \/>\nTARGET must be exactly one of these:<br \/>\n-p, --pid=N pid of the process (implies -z)<br \/>\n-e, --exe=FILE name of the executable program file or path name<br \/>\nCOMMAND [ARGS] run this command and limit it (implies -z)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Centos cpulimit \u5b89\u88c5\u4e0e\u6848\u4f8b\uff0c\u9650\u5236CPU\u4f7f\u7528 cpulimit \u547d\u4ee4\u7684\u5de5\u4f5c\u539f\u7406\u662f\u4e3a\u8fdb\u7a0b\u9884\u8bbe\u4e00\u4e2a cpu \u5360\u7528\u7387\u95e8\u9650\uff0c\u5e76\u5b9e\u65f6\u76d1\u63a7\u8fdb\u7a0b\u662f\u5426\u8d85\u51fa\u6b64\u95e8\u9650\uff0c\u82e5\u8d85\u51fa\u5219\u8ba9\u8be5\u8fdb\u7a0b\u6682\u505c\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u3002cpulimit \u4f7f\u7528 SIGSTOP \u548c SIGCONT \u8fd9\u4e24\u4e2a\u4fe1\u53f7\u6765\u63a7\u5236\u8fdb\u7a0b\u3002\u5b83\u4e0d\u4f1a\u4fee\u6539\u8fdb\u7a0b\u7684 nice \u503c\uff0c\u800c\u662f\u901a\u8fc7\u76d1\u63a7\u8fdb\u7a0b\u7684 cpu \u5360\u7528\u7387\u6765\u505a\u51fa\u52a8\u6001\u8c03\u6574\u3002 cpulimit \u7684\u4f18\u52bf\u662f\u53ef\u4ee5\u63a7\u5236\u8fdb\u7a0b\u7684cpu\u4f7f\u7528\u7387\u7684\u4e0a\u9650\u503c\u3002\u4f46\u4e0e nice \u76f8\u6bd4\u4e5f\u6709\u7f3a\u70b9\uff0c\u90a3\u5c31\u662f\u5373\u4f7f cpu \u662f\u7a7a\u95f2\u7684\uff0c\u8fdb\u7a0b\u4e5f\u4e0d\u80fd\u5b8c\u5168\u4f7f\u7528\u6574\u4e2a cpu \u8d44\u6e90\u3002 \u5728 CentOS \u4e0a\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\u6765\u5b89\u88c5\u5b83\uff1a (yum install cpulimt -y ) wget -O cpulimit.zip https:\/\/github.com\/opsengine\/cpulimit\/archive\/master.zip unzip cpulimit.zip cd cpulimit-master make sudo cp src\/cpulimit \/usr\/bin \u4e0a\u9762\u7684\u547d\u4ee4\u884c\uff0c\u4f1a\u5148\u4ece\u4ece GitHub \u4e0a\u5c06\u6e90\u7801\u4e0b\u8f7d\u5230\u672c\u5730\uff0c\u7136\u540e\u518d\u89e3\u538b\u3001\u7f16\u8bd1\u3001\u5e76\u5b89\u88c5\u5230 \/usr\/bin \u76ee\u5f55\u4e0b\u3002 cpulimit \u7684\u4f7f\u7528\u65b9\u5f0f\u548c nice \u547d\u4ee4\u7c7b\u4f3c\uff0c\u4f46\u662f\u9700\u8981\u7528\u6237\u4f7f\u7528 -l \u9009\u9879\u663e\u5f0f\u5730\u5b9a\u4e49\u8fdb\u7a0b\u7684 cpu \u4f7f\u7528\u7387\u4e0a\u9650\u503c\u3002\u4e3e\u4f8b\u8bf4\u660e\uff1a cpulimit -l 50 matho-primes 0 9999999999 &gt; \/dev\/null &amp; cpulimit \u4ece\u4e0a\u9762\u7684\u4f8b\u5b50\u53ef\u4ee5\u770b\u51fa matho-primes \u53ea\u4f7f\u7528\u4e8650%\u7684 cpu \u8d44\u6e90\uff0c\u5269\u4f59\u7684 cpu \u65f6\u95f4\u90fd\u5728 idle\u3002 cpulimit \u5176\u4ed6\u5b9e\u4f8b\uff1a cpulimit -e httpd &#8211;limit 40 #\u9650\u5236httpd\uff08\u8fdb\u7a0b\u540d\uff09\u7684cpu\u4f7f\u7528\u7387\u4e3a40% cpulimit -e \/usr\/local\/bin\/httpd &#8211;limit 40 cpulimit -p 2960 -l 55 #\u9650\u5236pid\u4e3a2960\u7684\u8fdb\u7a0b\u7684CPU\u5360\u7528\u4e3a55% \u4f7f\u7528\u5e2e\u52a9\uff1a Usage: cpulimit [OPTIONS&#8230;] TARGET OPTIONS -l, &#8211;limit=N percentage of cpu allowed from 0 to 3200 (required) -v, &#8211;verbose show control statistics -z, &#8211;lazy exit if there is no target process, or if it dies -i, &#8211;include-children limit also the children processes -h, &#8211;help display this help and exit TARGET must be exactly one of these: -p, &#8211;pid=N pid of the process (implies -z) -e, &#8211;exe=FILE name of the executable program file or path name COMMAND [ARGS] run this command and limit it (implies -z)<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[99,87,101,80],"tags":[],"class_list":["post-1547","post","type-post","status-publish","format-standard","hentry","category-centos","category-linux","category-101","category-80"],"_links":{"self":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1547"}],"version-history":[{"count":1,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1547\/revisions"}],"predecessor-version":[{"id":1548,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1547\/revisions\/1548"}],"wp:attachment":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}