Today, you will learn how to perform distributed load testing in Locust. If you are not familiar with Locust, then let’s refresh the basics and see how to perform distributed execution. Locust is an open source load testing tool and you can describe all your test in Python code.
Installation Locust is a Python library. It does not have any UI to write or configure your test. You can describe all your test in Python code.
pip install locustio
Locust File CreationCreate a python file using the below code.
from locust import HttpLocust, TaskSet, task class UserBehavior(TaskSet): @task def index(self): self.client.get("/") class WebsiteUser(HttpLocust): task_set = UserBehavior min_wait = 5000 max_wait = 9000
Note: If a file has HttpLocust class, then it will be considered as LocustFile. In the above code, we have two classes, one is TaskSet which is used to declare all your tests and the second one is HttpLocust which represents one user and it should have task_set attribute.
Executing Locust FileUse the below command to run your Locust file.
locust -f locust-examples/locustfile.py --host=http://google.com
Note: As per the above command, our LocustFile is placed inside a folder (i.e. locust-examples). Once you execute the above command, Locust web monitor will start and you can start load execution from web monitor
Locust Web MonitorYou can launch the web monitor using http://localhost:8089/.
Now, click Start Swarming button after entering number of users and Hatch rate.
Distributed Execution
To start locust in master mode:
locust -f my_locustfile.py --master
And then on each slave (replace 192.168.0.14 with IP of the master machine):
locust -f my_locustfile.py --slave --master-host=192.168.0.14
Comments(0)