{"id":155469,"date":"2020-09-01T19:30:23","date_gmt":"2020-09-01T11:30:23","guid":{"rendered":"http:\/\/4563.org\/?p=155469"},"modified":"2020-09-01T19:30:23","modified_gmt":"2020-09-01T11:30:23","slug":"%e6%9c%89%e6%b2%a1%e6%8e%a7%e5%88%b6%e7%a8%8b%e5%ba%8f-cpu-%e4%bd%bf%e7%94%a8%e7%9a%84%e5%bc%80%e6%ba%90%e9%a1%b9%e7%9b%ae%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=155469","title":{"rendered":"\u6709\u6ca1\u63a7\u5236\u7a0b\u5e8f cpu \u4f7f\u7528\u7684\u5f00\u6e90\u9879\u76ee\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6709\u6ca1\u63a7\u5236\u7a0b\u5e8f cpu \u4f7f\u7528\u7684\u5f00\u6e90\u9879\u76ee\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : 52coder <\/span>  <span><i><\/i> 5<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6709\u6ca1\u63a7\u5236\u7a0b\u5e8f cpu \u4f7f\u7528\u7684\u5f00\u6e90\u9879\u76ee\uff1f\u6211\u76ee\u524d\u5728 github \u4e0a\u5c31\u627e\u5230\u4e00\u4e2a 7 8 \u5e74\u6ca1\u7ef4\u62a4\u7684\u9879\u76ee cpulimit\uff0c\u5927\u81f4\u4f7f\u7528\u65b9\u6cd5\uff1a .\/cpulimit &#8211;limit 30 process_name .\/process_name \u5927\u6982\u770b\u4e86\u4e0b\u4ee3\u7801\uff0c\u5f53 cpu \u8d85\u8fc7\u540e\u4f1a\u53d1\u9001 stop\uff0csleep \u4e00\u6bb5\u65f6\u95f4\u540e\u53d1\u9001 cont \u4fe1\u53f7\uff0c\u4ee3\u7801\u5927\u81f4\u6402\u4e86\u4e00\u773c\uff0c\u53d1\u73b0\u4e24\u4e2a\u5927 bug.\uff08 fork \u4e86\u4e2a\u4ed3\u5e93\uff0c\u5730\u5740 https:\/\/github.com\/52coder\/cpulimit \uff09<\/p>\n<p>\u4e00\u4e2a\u662f ifdef \u548c if defined \u641e\u6df7\u4e86\uff0c\u53e6\u4e00\u4e2a\u662f kill \u672c\u6765\u662f\u8981\u4f20\u9012\u8fdb\u7a0b\u53f7\uff0c\u7ed3\u679c\u7528\u4e86-1 \uff1f \u60f3\u95ee\u4e0b\u5927\u5bb6\uff0c\u6709\u6ca1\u6709\u66f4\u597d\u7684\u9009\u62e9\uff0c\u6700\u597d\u662f c\/c++\u5b9e\u73b0\u3002\u8fd9\u4e2a cpulimit \u4e0d\u6562\u7528\u5440\uff0c\u6211\u8fd9\u4e48\u83dc\u90fd\u80fd\u53d1\u73b0 bug\uff0c\u8bf4\u660e\u95ee\u9898\u6709\u70b9\u591a\u5440\uff0c      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>15<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3293781\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : liberty1900 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e2a\u53eb throttle \u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293782\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : billlee <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e2a\u9879\u76ee\u53eb Linux, \u529f\u80fd\u53eb cgroup.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293783\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : codehz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Linux \u7684\u8bdd\uff0c\u53ef\u4ee5\u8bd5\u8bd5\u81ea\u5e26\u7684 cgroup,\u901a\u8fc7\u63a7\u5236 cpu \u6838\u5fc3\u5206\u914d\uff0c\u65f6\u95f4\u7247\u5206\u914d\u6765\u9650\u5236\u6700\u5927 cpu \u4f7f\u7528\u91cf                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293784\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 52coder <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @billlee \u591a\u8c22\u5927\u4f6c\uff0c\u732e\u4e11\u4e86\uff0c\u6211\u641c\u4e86\u4e0b\uff0ccgroup \u6b63\u662f\u6211\u8981\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293785\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 52coder <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @codehz \u611f\u8c22\u63a8\u8350\uff0c\u6211\u7814\u7a76\u4e0b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293786\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : vk42 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0a cgroup \u6b63\u89e3\uff0c\u4e0d\u8fc7 lz \u627e\u5230\u7684\u4e24\u4e2a\u201dbug\u201c\u770b\u8d77\u6765\u5e76\u4e0d\u662f bug\uff1a<br \/>ifdef \u548c if defined \u5927\u591a\u6570\u60c5\u51b5\u4e0b\u662f\u7b49\u4ef7\u7684\uff0c\u4e0d\u77e5\u9053\u4f60\u8bf4\u7684\u641e\u6df7\u662f\u4ec0\u4e48\u610f\u601d<br \/>kill \u7684-1 \u5e94\u8be5\u662f signum\uff0c1 \u5bf9\u5e94 SIGHUP\uff0c\u4e5f\u5c31\u662f\u6302\u8d77\u8fdb\u7a0b\u2026\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293787\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wevsty <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Windows \u7684\u8bdd\u53ef\u4ee5\u901a\u8fc7 job \u6765\u9650\u5236 CPU \u4f7f\u7528\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u9650\u5236\u8fd0\u884c\u518d\u67d0\u4e00\u4e2a\u6838\u5fc3\u7684\u65b9\u5f0f\u6765\u9650\u5236 CPU \u3002<br \/>Linux \u7684\u8bdd cgroup \u662f\u6b63\u89e3\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u6050\u6015\u4e3b\u627e\u5230\u7684\u90fd\u4e0d\u662f bug\uff0c\u53cd\u5012\u662f\u4e71\u6539\u53ef\u80fd\u6539\u51fa bug \u4e86\u3002<\/p>\n<p>@vk42 <br \/>\u8fd9\u91cc\u7684 kill \u4e0d\u662f\u547d\u4ee4\u884c\u7684 kill \u800c\u662f\u6307 kill().<\/p>\n<p>pid \u4e3a-1 \u65f6\u4f1a\u7ed9\u9664\u4e86 init \u4ee5\u5916\u7684\u6240\u6709\u6709\u6743\u9650\u8bbf\u95ee\u7684\u8fdb\u7a0b\u90fd\u53d1\u9001\u4e00\u904d\u6307\u5b9a\u7684\u4fe1\u53f7\u3002<br \/>\u6587\u6863\u5199\u7684\u5f88\u6e05\u695a\uff1a<\/p>\n<p>If pid equals -1, then sig is sent to every process for which the calling process has permission to send signals, except for process 1 (init).                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293788\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 52coder <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @vk42 #ifdef A|| B \u5c31\u662f\u9519\u7684\uff0cifdef \u53ea\u80fd\u4e00\u4e2a\u6761\u4ef6\uff0cif defined \u624d\u53ef\u4ee5\u591a\u4e2a\u6761\u4ef6<br \/>kill() -1 \u7684\u8bdd\u662f\u7fa4\u53d1\uff0cman kill \u91cc\u6709 wevsty \u91cc\u7684\u8bc4\u8bba\u6709\uff0c\u53ef\u4ee5\u770b\u4e0b\u6211\u4ed3\u5e93\u91cc\u5012\u6570\u7b2c\u4e8c\u6b21\u63d0\u4ea4                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293789\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : js8510 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5047\u8bbe\u4f60\u90e8\u7f72\u7684\u7a0b\u5e8f\u662f\u4e00\u4e2a service\uff0c\u5e38\u89c1\u7684\u505a\u6cd5\u662f cgroup \u7136\u540e service \u672c\u8eab\u5b9e\u73b0\u4e00\u4e9b monitor demon. Cgroup \u7528\u6765\u8bbe\u5b9a\u4e0a\u9650\uff0c\u6bd4\u5982 cpu, mem, network I\/O etc. Monitor demon \u7528\u6765 monitor queue size, processing etc \u7136\u540e\u52a8\u6001\u7684 export \u7ed9 load balancer, elastic capacity managing service etc. \u5982\u679c\u662f\u9762\u5411\u7528\u6237\u7684\u524d\u7aef\u8f6f\u4ef6\uff0c\u786e\u5b9e\u4e0d\u592a\u6e05\u695a\u5e38\u89c1\u7684\u505a\u6cd5\u3002docker \u6216\u7c7b\u4f3c\u7684 container \u5176\u5b9e\u591a\u6570\u672c\u8d28\u4e5f\u662f\u901a\u8fc7 cgroup \u9650\u5236\u8d44\u6e90\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293790\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 52coder <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @js8510 \u5ba2\u6237\u670d\u52a1\u5668\u4e2d\u6ca1\u6709 cgroup \u600e\u4e48\u7834?                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293791\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 52coder <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @liberty1900 \u540e\u7aef\u5b9e\u73b0\uff0c\u4f60\u8bf4\u7684\u8fd9\u4e2a\u5e94\u8be5\u662f js \u7684\uff0c\u641e\u4e0d\u901a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293792\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : js8510 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u7a81\u7136\u60f3\u5230\u3002\u6700\u7b80\u5355\u5e94\u6025\u7684\u65b9\u6cd5\uff0c\u5e94\u8be5\u53ef\u4ee5\u7528 nice \u9650\u5236\u4f60 process \u7684 priority. \u8fd9\u6837 unix like \u90fd\u80af\u5b9a\u6709\u3002 \u5bf9\u4e8e window \u5e94\u8be5\u6709\u7c7b\u4f3c\u7684\u4e1c\u897f\u3002 \u7136\u540e\u542f\u52a8\u7684\u65f6\u5019\u7ed9\u4f60\u7684\u5e94\u7528\u4e00\u4e2a shell script wrapper \u5e94\u8be5\u5c31\u53ef\u4ee5\u9650\u5236 cpu                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293793\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : js8510 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5176\u5b9e\u6211\u4e0d\u662f\u5f88\u80fd\u7406\u89e3\uff0c\u5982\u679c\u662f unixlike \u7684\u73af\u5883\u3002\u3002\u6ca1\u6709\uff0c\u4f60\u4e3a\u4ec0\u4e0d\u80fd\u88c5\u4e00\u4e0b\u3002\u3002\u5199\u90e8\u7f72\u811a\u672c\u7684\u65f6\u5019\u628a\uff0c \u6ca1\u6709 cgroup \u4f60\u5c31\u88c5\u4e00\u4e0b\u3002\u3002\u5185\u7f51\u4f60\u5c31\u548c\u5e94\u7528\u672c\u8eab\u4e00\u8d77\u6253\u5305\u3002\u6216\u8bb8\u4f60\u5de5\u4f5c\u8981\u6c42\u6bd4\u8f83\u7279\u6b8a\u5427\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293794\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : iceheart <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             ControlGroup \u662f\u5185\u6838\u529f\u80fd\uff0c2.6.24 \u4ee5\u4e0a\u5185\u6838\u5f00\u59cb\u63d0\u4f9b\uff0c\u5927\u6982\u6709 12 \u5e74\u5386\u53f2\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3293795\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 52coder <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @js8510 \u6211\u53f8\u4ea7\u54c1\u975e\u5e38\u53e6\u7c7b\uff0c\u652f\u6301\u7684\u7cfb\u7edf\u4ece centos5 \u5230 centos8\uff0c\u67b6\u6784\u652f\u6301 x86-64 aarch64 mips64,\u5982\u679c\u6709\u6e90\u7801\uff0c\u4ea4\u53c9\u7f16\u8bd1\u5565\u7684\uff0c\u57fa\u672c\u4e0a\u4e0d\u7528\u592a\u8d39\u5fc3\uff0c\u5982\u679c\u548c\u5e94\u7528\u6253\u4e00\u8d77\u5c31\u975e\u5e38\u96be\u53d7\u5440                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u6ca1\u63a7\u5236\u7a0b\u5e8f cpu \u4f7f\u7528\u7684\u5f00\u6e90\u9879&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/155469"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=155469"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/155469\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=155469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=155469"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=155469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}