{"id":1172,"date":"2023-12-13T21:21:25","date_gmt":"2023-12-13T21:21:25","guid":{"rendered":"https:\/\/labiol.xyz\/?p=1172"},"modified":"2024-01-10T21:28:08","modified_gmt":"2024-01-10T21:28:08","slug":"cpu-burn-in-linux-virtual-environment","status":"publish","type":"post","link":"https:\/\/www.labiol.xyz\/index.php\/2023\/12\/13\/cpu-burn-in-linux-virtual-environment\/","title":{"rendered":"CPU burn in linux\/virtual environment."},"content":{"rendered":"\n<p>Below you can find python script to burn cpu (for expamle, when testing alerting) in virtual (and physical) environment. Script is scaling (automatically) for number of CPU presented for the OS<\/p>\n\n\n\n<p>burn_cpu.py<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import multiprocessing\nimport time\n\ndef burn_cpu(duration):\n    end_time = time.time() + duration\n    while time.time() &lt; end_time:\n        pass\n\nif __name__ == &quot;__main__&quot;:\n    num_threads = multiprocessing.cpu_count()  # Get the number of CPU cores\n    duration = 60  # Burn CPU for 60 seconds\n\n    print(f&quot;Burning CPU with {num_threads} threads for {duration} seconds.&quot;)\n\n    processes = []\n\n    for _ in range(num_threads):\n        process = multiprocessing.Process(target=burn_cpu, args=(duration,))\n        processes.append(process)\n        process.start()\n\n    for process in processes:\n        process.join()\n\n    print(&quot;CPU burn completed.&quot;)\n<\/code><\/pre><\/div>\n\n\n\n<p>To run script use the following command: python3 burn_cpu.py<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Below you can find python script to burn cpu (for expamle, when testing alerting) in virtual (and physical) environment. Script is scaling (automatically) for number of CPU presented for the OS burn_cpu.py To run script use the following command: python3 burn_cpu.py<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,2],"tags":[],"class_list":["post-1172","post","type-post","status-publish","format-standard","hentry","category-linux","category-vmware"],"_links":{"self":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts\/1172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=1172"}],"version-history":[{"count":1,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts\/1172\/revisions"}],"predecessor-version":[{"id":1173,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/posts\/1172\/revisions\/1173"}],"wp:attachment":[{"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=1172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=1172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.labiol.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=1172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}