Skip to content

Instantly share code, notes, and snippets.

@mda590
Created June 8, 2018 14:07
Show Gist options
  • Save mda590/7a9a6b21b74ae10aa350b1703e2724a0 to your computer and use it in GitHub Desktop.
Save mda590/7a9a6b21b74ae10aa350b1703e2724a0 to your computer and use it in GitHub Desktop.

Revisions

  1. mda590 created this gist Jun 8, 2018.
    23 changes: 23 additions & 0 deletions stress_test.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    """
    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))