Created
June 8, 2018 14:07
-
-
Save mda590/7a9a6b21b74ae10aa350b1703e2724a0 to your computer and use it in GitHub Desktop.
Python script useful for stress testing systems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Produces load on all available CPU cores. | |
Requires system environment var STRESS_MINS to be set. | |
""" | |
from multiprocessing import Pool | |
from multiprocessing import cpu_count | |
import time | |
import os | |
def f(x): | |
set_time = os.environ['STRESS_MINS'] | |
timeout = time.time() + 60*float(set_time) # X minutes from now | |
while True: | |
if time.time() > timeout: | |
break | |
x*x | |
if __name__ == '__main__': | |
processes = cpu_count() | |
print ('utilizing %d cores\n' % processes) | |
pool = Pool(processes) | |
pool.map(f, range(processes)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's my modified version which uses command line arguments and has some basic throttling available.
As with the original one above, hitting Ctrl-C while it's running can lead to some zombie processes - let it exit normally or kill the parent python process directly if you want to exit early.