Listen to this blog
|
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.

InstallationLocust 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
[/code]
Locust File CreationCreate a python file using the below code.
from locust import HttpLocust, TaskSet, taskclass UserBehavior(TaskSet):
@task
def index(self):
self.client.get("/")class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 5000
max_wait = 9000
[/code]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
[/code]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
[/code]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
[/code]
Posted on 08/08/2019