Skip to content

Instantly share code, notes, and snippets.

@sanggiChoi
Forked from mda590/stress_test.py
Created January 14, 2019 09:49
Show Gist options
  • Save sanggiChoi/311df749bc5d120612e8e43c8cfe9870 to your computer and use it in GitHub Desktop.
Save sanggiChoi/311df749bc5d120612e8e43c8cfe9870 to your computer and use it in GitHub Desktop.
Python script useful for stress testing systems
"""
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