using multi-CPU platforms with locust

Viewed 3299

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?enter image description here

3 Answers

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[@]}"

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
Related