Created
October 21, 2016 19:54
-
-
Save eezis/eddd935a942f24936dcf41edf780be9b to your computer and use it in GitHub Desktop.
Spread locust.io across cores using the multiprocessing library
This file contains hidden or 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
import sys | |
import subprocess | |
import multiprocessing | |
# use htop to see the utilization rates spread across cores | |
# use locust --help to see all the options | |
# the cmd launches 500 concurrent users on each core, hatch 5 per second, issue 10k requests then stops | |
# logs to results.txt, prints the summary in the terminal | |
cmd = "locust --no-web --clients=500 --hatch-rate=5 --num-request=10000 \ | |
--logfile=results.txt --print-stats --only-summary --host=https://yourtargeturl.com" | |
num_workers = multiprocessing.cpu_count() | |
def create_worker(): | |
sys.exit(subprocess.call(cmd, shell=True)) | |
if __name__ == '__main__': | |
jobs = [] # multiprocess.jobs | |
for i in range(num_workers): | |
p = multiprocessing.Process(target=create_worker) | |
jobs.append(p) | |
p.start() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment