I am running htop on the same machine where locust is running. during the tests I have been running this morning, I see one CPU (of 4) hit 100% while the other CPUs are largely idle. I have also observed up to 8 locust tasks running. This is not running distributed. How does locust implement threading and multiprocessing to maximize the available capabilities of the machine?
Asked
Active
Viewed 4,823 times
8

Chris Hare
- 161
- 2
- 12
-
see https://stackoverflow.com/a/73804595/459189 for one more option on how to use locust distributed – Fruch Sep 21 '22 at 17:11
3 Answers
6
See https://docs.locust.io/en/stable/running-locust-distributed.html
This applies both for running distributed over multiple machines or just multiple cores.
You need one worker process per core in order to fully utilize the machine.

Cyberwiz
- 11,027
- 3
- 20
- 40
-
1i see the page says run a worker for each core. but the page isn't clear how to do that. I did figure it out though. – Chris Hare Jun 03 '20 at 14:38
-
1@ChrisHare Ah thanks. I had the same problem. Turns out you run one locust with --master, and some others with --worker. – dfrankow May 27 '21 at 16:55
-
1I know this post is a bit old, but I just wanted to know if there is any way I can run locust to utilize multiple cores without spinning up `master` and `workers` distributed mode ? – jlim Feb 02 '22 at 16:52
2
You can use this bash script for running locust in distributed mode:
echo -e "\nStart LOCUST MASTER\n"
locust -f locust_scenario.py --headless -L $LOG_LEVEL --logfile=$LOG --master-bind-port=$MASTER_PORT \
--master-bind-host=$MASTER_IP -u $COUNT_OF_USERS --print-stats --master --expect-workers=$cores --host=$SERVER_HOST&
PID_MASTER=$!
echo "LOCAST MASTER PID = $PID_MASTER"
sleep 5
# start SLAVE (clients)
echo -e "\nStart LOCUST SLAVES\n"
PID_SLAVES=( )
for ((i = 1; i <= $cores; i++));do
locust -f locust_scenario.py --worker --master-host=$MASTER_IP --master-port=$MASTER_PORT -L $LOG_LEVEL --logfile=$LOG &
PID_SLAVES+=( $! )
done
echo "LOCAST SLAVE PIDs = ${PID_SLAVES[@]}"

Alexaxndr Lyakhov
- 79
- 1
- 6
0
I think the best option to run locust on multiple cores locally is to run locust master and workers with docker and docker-compose file as described here https://docs.locust.io/en/stable/running-in-docker.html
Simply mount your locustfile.py inside containers and start it using docker compose command. The number of workers can be easily changed using this command:
docker-compose up --scale worker=4

Vladimir Osintsev
- 96
- 2
- 4