{"id":2210,"date":"2018-11-04T08:02:24","date_gmt":"2018-11-03T23:02:24","guid":{"rendered":"http:\/\/matoken.org\/blog\/?p=2210"},"modified":"2018-11-04T08:02:24","modified_gmt":"2018-11-03T23:02:24","slug":"try-cpulimit-to-limit-cpu-utilization-of-specific-process","status":"publish","type":"post","link":"https:\/\/matoken.org\/blog\/2018\/11\/04\/try-cpulimit-to-limit-cpu-utilization-of-specific-process\/","title":{"rendered":"\u7279\u5b9a\u30d7\u30ed\u30bb\u30b9\u306ecpu\u5229\u7528\u7387\u3092\u5236\u9650\u3059\u308bcpulimit\u3092\u8a66\u3059"},"content":{"rendered":"<div id=\"preamble\">\n<div class=\"sectionbody\">\n<div id=\"__asciidoctor-preview-1__\" class=\"paragraph\">\n<p>\u5148\u65e5mysqldump + xz \u5727\u7e2e\u306e\u9593\u306b <code style=\"font-family: monospace;\">pv<\/code> \u3092\u631f\u3093\u3067\u5e2f\u57df\u5236\u9650\u3092\u3057\u3066 xz \u306e\u8ca0\u8377\u3092\u4e0b\u3052\u307e\u3057\u305f\uff0e<\/p>\n<\/div>\n<div id=\"__asciidoctor-preview-2__\" class=\"ulist\">\n<ul>\n<li>\n<p><a href=\"https:\/\/matoken.org\/blog\/2018\/10\/11\/mysqldump-limit-by-pv\/\">mysqldump \u3092 pv \u3067\u5236\u9650 \u2013 matoken\u2019s meme<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<div id=\"__asciidoctor-preview-3__\" class=\"paragraph\">\n<p>\u3057\u304b\u3057\u3053\u306e\u65b9\u6cd5\u3067\u306f\u305d\u3093\u306a\u306b\u8ca0\u8377\u304c\u306a\u3044 mysqldump \u3082\u305a\u3063\u3068\u52d5\u304b\u3057\u3063\u3071\u306a\u3057\u3067 db \u306b\u3082\u3088\u308d\u3057\u304f\u7121\u3044\u3067\u3059\uff0emysqldump \u306f\u5148\u306b\u6e08\u307e\u305b\u3066 xz \u3060\u3051\u3092\u5236\u9650\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3059\uff0e<\/p>\n<\/div>\n<div id=\"__asciidoctor-preview-4__\" class=\"listingblock\">\n<div class=\"title\">before<\/div>\n<div class=\"content\">\n<pre>umask 0266 &amp;&amp; nice -n 19 ionice -c 3 \/usr\/bin\/mysqldump --defaults-file=\/mnt\/backup\/micro\/.my-backup.cnf --single-transaction --quick --all-databases --events | pv -L 128k 2&gt;\/dev\/null | nice -n 19 ionice -c 3 \/usr\/bin\/xz -9 &gt; \/mnt\/backup\/micro\/`date +\\%F_\\%T_$$`.sql.xz<\/pre>\n<\/div>\n<\/div>\n<div id=\"__asciidoctor-preview-5__\" class=\"listingblock\">\n<div class=\"title\">after<\/div>\n<div class=\"content\">\n<pre>DUMP=\"\/mnt\/backup\/micro\/`date +\\%F_\\%T_$$`.sql\"; umask 0266 &amp;&amp; nice -n 19 ionice -c 3 \/usr\/bin\/mysqldump --defaults-file=\/mnt\/backup\/micro\/.my-backup.cnf --single-transaction --quick --all-databases --events &gt; ${DUMP} &amp;&amp; pv -L 128k nice -n 19 ionice -c 3 \/usr\/bin\/xz -9 &gt; ${DUMP}.xz &amp;&amp; rm ${DUMP}<\/pre>\n<\/div>\n<\/div>\n<div id=\"__asciidoctor-preview-6__\" class=\"paragraph\">\n<p>\u4e00\u5fdc\u52d5\u304f\u3051\u3069crontab\u306a\u306e\u3067\uff11\u884c\u3067\u66f8\u3044\u3066\u3042\u3063\u3066\u898b\u306b\u304f\u3044\u3057\u3042\u307e\u308a\u3044\u3051\u3066\u306a\u3044\u3067\u3059\u306d\uff0e<br \/>\n\u305b\u3081\u3066\u30d5\u30a1\u30a4\u30eb\u306b\u5206\u3051\u305f\u307b\u3046\u304c\u826f\u3055\u305d\u3046\uff0e<\/p>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_limitcpu\">LimitCPU<\/h2>\n<div class=\"sectionbody\">\n<div id=\"__asciidoctor-preview-7__\" class=\"paragraph\">\n<p>pv\u3067\u3082\u3044\u3044\u306e\u3067\u3059\u304c\uff0ccpu\u5229\u7528\u7387\u3092\u5236\u9650\u3067\u304d\u306a\u3044\u304b\u306a\u3068\u601d\u3044\u307e\u3057\u305f\uff0exz\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u306f\u898b\u5f53\u305f\u3089\u305aLinux\u74b0\u5883\u306a\u306e\u3067 <code style=\"font-family: monospace;\">cgroups<\/code> \u3067\u5236\u9650\u3057\u3088\u3046\u304b\u3068\u3082\u601d\u3063\u305f\u306e\u3067\u3059\u304c\uff0c <code style=\"font-family: monospace;\">LimitCPU<\/code> \u3068\u3044\u3046\u3082\u306e\u3092\u898b\u3064\u3051\u307e\u3057\u305f\uff0e\u3053\u308c\u306f <code style=\"font-family: monospace;\">SIGSTOP<\/code> \u3068 <code style=\"font-family: monospace;\">SIGCONT<\/code> \u306ePOSIX\u30b7\u30b0\u30ca\u30eb\u3092\u30d7\u30ed\u30bb\u30b9\u306b\u9001\u4fe1\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u5b9f\u73fe\u3057\u3066\u3044\u308b\u306e\u3067\uff0cPOSIX\u74b0\u5883\u306a\u3089\u3069\u3053\u3067\u3082\u52d5\u304d\u305d\u3046\u306a\u306e\u3067\u3053\u3061\u3089\u3092\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\uff0e<\/p>\n<\/div>\n<div id=\"__asciidoctor-preview-8__\" class=\"paragraph\">\n<p>LimitCPU\u306f\u30e1\u30f3\u30c6\u3055\u308c\u306a\u304f\u306a\u3063\u305fCPUlimit\u306e\u30d5\u30a9\u30fc\u30af\u3067\u30b3\u30de\u30f3\u30c9\u3084\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u306f <code style=\"font-family: monospace;\">cpulimit<\/code> \u3067\u3059\uff0e(\u6df7\u4e71\u3059\u308b&gt;&lt;)<\/p>\n<\/div>\n<div id=\"__asciidoctor-preview-9__\" class=\"ulist\">\n<ul>\n<li>\n<p><a href=\"http:\/\/limitcpu.sourceforge.net\/\">LimitCPU<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/opsengine\/cpulimit\">GitHub &#8211; opsengine\/cpulimit: CPU usage limiter for Linux<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<div id=\"__asciidoctor-preview-10__\" class=\"listingblock\">\n<div class=\"title\">\u5c0e\u5165<\/div>\n<div class=\"content\">\n<pre>$ sudo apt install cpulimit<\/pre>\n<\/div>\n<\/div>\n<div id=\"__asciidoctor-preview-11__\" class=\"listingblock\">\n<div class=\"title\">usage<\/div>\n<div class=\"content\">\n<pre>$ cpulimit -h\r\nCPUlimit version 2.1\r\nUsage: cpulimit TARGET [OPTIONS...] [-- PROGRAM]\r\n   TARGET must be exactly one of these:\r\n      -p, --pid=N        pid of the process\r\n      -e, --exe=FILE     name of the executable program file\r\n                         The -e option only works when\r\n                         cpulimit is run with admin rights.\r\n      -P, --path=PATH    absolute path name of the\r\n                         executable program file\r\n   OPTIONS\r\n      -b  --background   run in background\r\n      -c  --cpu=N        override the detection of CPUs on the machine.\r\n      -l, --limit=N      percentage of cpu allowed from 1 up.\r\n                         Usually 1 - 200, but can be higher\r\n                         on multi-core CPUs (mandatory)\r\n      -q, --quiet        run in quiet mode (only print errors).\r\n      -k, --kill         kill processes going over their limit\r\n                         instead of just throttling them.\r\n      -r, --restore      Restore processes after they have\r\n                         been killed. Works with the -k flag.\r\n      -s, --signal=SIG   Send this signal to the watched process when cpulimit exits.\r\n                         Signal should be specificed as a number or\r\n                         SIGTERM, SIGCONT, SIGSTOP, etc. SIGCONT is the default.\r\n      -v, --verbose      show control statistics\r\n      -z, --lazy         exit if there is no suitable target process,\r\n                         or if it dies\r\n          --             This is the final CPUlimit option. All following\r\n                         options are for another program we will launch.\r\n      -h, --help         display this help and exit<\/pre>\n<\/div>\n<\/div>\n<div id=\"__asciidoctor-preview-12__\" class=\"paragraph\">\n<p>\u5236\u9650\u306f\u30d7\u30ed\u30bb\u30b9ID\u3067\u306e\u5236\u9650\uff0c\u30d7\u30ed\u30b0\u30e9\u30e0\u540d\u3067\u306e\u5236\u9650\uff0c\u6307\u5b9a\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5236\u9650\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\uff0e<br \/>\ncpu\u304c\u8907\u6570\u3042\u308b\u5834\u5408\u306f <code style=\"font-family: monospace;\">-l<\/code> \u306e\u5024\u306fcpu 1\u3064\u3042\u305f\u308a100\u3068\u3057\u3066\uff0c100 * cpu\u6570 \u3092\u5143\u306b\u6307\u5b9a\u3057\u307e\u3059\uff0ecpu 2\u3064\u3067 50% \u5229\u7528\u3057\u305f\u3044\u5834\u5408\u306f <code style=\"font-family: monospace;\">-l 100<\/code> \u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\uff0e<\/p>\n<\/div>\n<div id=\"__asciidoctor-preview-13__\" class=\"listingblock\">\n<div class=\"title\">\u30d7\u30ed\u30bb\u30b9ID <code style=\"font-family: monospace;\">1234<\/code> \u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092cpu\u30922\u3064\u5229\u7528\uff0c\uff43\uff50\uff55\u309250%(2\u30b3\u30a2\u306a\u306e\u3067\u5b9f\u969b\u306f100%\u5206)<\/div>\n<div class=\"content\">\n<pre>$ cpulimit -c 2 -p 1234 -l 50<\/pre>\n<\/div>\n<\/div>\n<div id=\"__asciidoctor-preview-14__\" class=\"listingblock\">\n<div class=\"title\">xz\u3068\u3044\u3046\u30d7\u30ed\u30b0\u30e9\u30e0\u3092cpu\u5229\u7528\u7387\u309225%\u306b\u5236\u9650<\/div>\n<div class=\"content\">\n<pre>$ cpulimit -c 2 -l 50 - xz<\/pre>\n<\/div>\n<\/div>\n<div id=\"__asciidoctor-preview-15__\" class=\"paragraph\">\n<p>\u203bxz\u306e\u524d\u306e <code style=\"font-family: monospace;\">-<\/code> \u306f\u306a\u304f\u3066\u3082\u3044\u3044\u304c cpulimit \u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u6700\u5f8c\u3092\u793a\u3059\uff0e<\/p>\n<\/div>\n<div id=\"__asciidoctor-preview-16__\" class=\"listingblock\">\n<div class=\"title\">cpu\u30921\u3064\u3060\u3051\u5229\u7528\uff0ecpu\u5229\u7528\u7387\u309225%\u306b\u5236\u9650\u3057\u3064\u3064xz\u3092\u5b9f\u884c\u3067\u304d\u307e\u3059\uff0e<\/div>\n<div class=\"content\">\n<pre>$ cpulimit -c 1 -l 25 -z -  xz -9 datafile<\/pre>\n<\/div>\n<\/div>\n<div id=\"__asciidoctor-preview-17__\" class=\"ulist\">\n<ul>\n<li>\n<p>-c :  \u5229\u7528\u3059\u308b\uff43\uff50\uff55\u6570<\/p>\n<\/li>\n<li>\n<p>-p : \u5236\u9650\u3059\u308b\u30d7\u30ed\u30bb\u30b9ID<\/p>\n<\/li>\n<li>\n<p>-l : \u5236\u9650\u3059\u308bcpu\u5229\u7528\u7387<\/p>\n<\/li>\n<li>\n<p>-z : \u6307\u5b9a\u3057\u305f\u30d7\u30ed\u30bb\u30b9\u304c\u5b8c\u4e86\u3057\u305f\u3089cpulimit\u3082\u7d42\u4e86\u3059\u308b(\u901a\u5e38\u306f\u95a2\u3057\u3092\u7d9a\u3051\u3066\u540c\u3058\u6761\u4ef6\u306b\u4e00\u81f4\u3059\u308b\u30d7\u30ed\u30bb\u30b9\u304c\u73fe\u308c\u305f\u3089\u5236\u9650\u3059\u308b)<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<div id=\"__asciidoctor-preview-18__\" class=\"paragraph\">\n<p>\u4eca\u56de\u306fxz\u3092\u5236\u9650\u3057\u305f\u3044\u306e\u3067\u3053\u3093\u306a\u611f\u3058\u306b\uff0e<br \/>\n\u3042\u307e\u308a\u5909\u308f\u308a\u307e\u305b\u3093\u306d\u2026\u2026\uff0e<\/p>\n<\/div>\n<div id=\"__asciidoctor-preview-19__\" class=\"listingblock\">\n<div class=\"content\">\n<pre>DUMP=\"\/mnt\/backup\/micro\/`date +\\%F_\\%T_$$`.sql\"; umask 0266 &amp;&amp; nice -n 19 ionice -c 3 \/usr\/bin\/mysqldump --defaults-file=\/mnt\/backup\/micro\/.my-backup.cnf --single-transaction --quick --all-databases --events &gt; ${DUMP} &amp;&amp; nice -n 19 ionice -c 3 cpulimit -c1 -l 25 - \/usr\/bin\/xz -9 ${DUMP}<\/pre>\n<\/div>\n<\/div>\n<div id=\"__asciidoctor-preview-20__\" class=\"paragraph\">\n<p>\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u5c02\u7528\u30e6\u30fc\u30b6\u3068\u3057\u3066\u5206\u3051\u3066\u3042\u308b\u306e\u3067\u305d\u306e\u30e6\u30fc\u30b6\u3067 <code style=\"font-family: monospace;\">cpulimit -c 1 -l 25 - xz<\/code> \u3068\u304b\u3057\u3066xz\u3068\u3044\u3046\u540d\u524d\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u5168\u90e8\u5236\u9650\u3057\u3066\u3057\u307e\u3046\u306e\u3082\u3042\u308a\u304b\u3082\u3057\u308c\u307e\u305b\u3093\uff0emonit \u3068\u304b\u3067\u76e3\u8996\u3055\u305b\u308c\u3070\u3044\u3044\u611f\u3058\u304b\u3082?\u305d\u3046\u3059\u308b\u3068\uff0c<\/p>\n<\/div>\n<div id=\"__asciidoctor-preview-21__\" class=\"listingblock\">\n<div class=\"content\">\n<pre>DUMP=\"\/mnt\/backup\/micro\/`date +\\%F_\\%T_$$`.sql\"; umask 0266 &amp;&amp; nice -n 19 ionice -c 3 \/usr\/bin\/mysqldump --defaults-file=\/mnt\/backup\/micro\/.my-backup.cnf --single-transaction --quick --all-databases --events &gt; ${DUMP} &amp;&amp; \/usr\/bin\/xz -9 ${DUMP}<\/pre>\n<\/div>\n<\/div>\n<div id=\"__asciidoctor-preview-22__\" class=\"paragraph\">\n<p>\u3042\u307e\u308a\u5909\u308f\u308a\u307e\u305b\u3093\u306d\u2026\u2026\uff0e<\/p>\n<\/div>\n<div id=\"__asciidoctor-preview-23__\" class=\"listingblock\">\n<div class=\"title\">\u74b0\u5883<\/div>\n<div class=\"content\">\n<pre>$ dpkg-query -W cpulimit xz-utils\r\ncpulimit        2.2-1\r\n$ lsb_release -d\r\nDescription:    Ubuntu 16.04.5 LTS\r\n$ uname -m\r\nx86_64<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u65e5mysqldump + xz \u5727\u7e2e\u306e\u9593\u306b pv \u3092\u631f\u3093\u3067\u5e2f\u57df\u5236\u9650\u3092\u3057\u3066 xz \u306e\u8ca0\u8377\u3092\u4e0b\u3052\u307e\u3057\u305f\uff0e mysqldump \u3092 pv \u3067\u5236\u9650 \u2013 matoken\u2019s meme \u3057\u304b\u3057\u3053\u306e\u65b9\u6cd5\u3067\u306f\u305d\u3093\u306a\u306b\u8ca0\u8377\u304c\u306a\u3044 mys [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"webmentions_disabled_pings":false,"webmentions_disabled":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[6,63,152],"tags":[435,436],"class_list":["post-2210","post","type-post","status-publish","format-standard","hentry","category-linux","category-ubuntu","category-xenial16-04","tag-cpulimit","tag-limitcpu"],"_links":{"self":[{"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/posts\/2210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/comments?post=2210"}],"version-history":[{"count":0,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/posts\/2210\/revisions"}],"wp:attachment":[{"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/media?parent=2210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/categories?post=2210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/matoken.org\/blog\/wp-json\/wp\/v2\/tags?post=2210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}