Performance Testing of an Application via Locust

Anubhav Chaturvedi
Python in Plain English
3 min readMay 30, 2021

--

Are you a developer who is looking forward to performing load testing on your application?

You might have heard about tools like Apache JMeter, SmartMeter, WebLOAD, etc. All these tools require some installation efforts and also familiarity with the usage.

In case you are new to this and want to rapidly implement load testing, then Locust tool written in Python is the go-to solution for your problem. It’s a one-line installation on your Linux Terminal as shown below:

Use this single line string for the installation :

pip3 install -e git://github.com/locustio/locust.git@master#egg=locust

Once we are done with the installation you can just log out and login into you shell and verify it later by: “locust -V”.

Once verification is done, we can look for APIs in GET and POST for testing:

You need to make a file in which we can write classes involving HTTP packages for interacting with all API’s and make relevant tasks to check for all APIs, the configuration file looks like this :

As you can see I have used the locust library and relevant HttpUser packages.

You will have the IP address of your server, and you can create task annotations followed by the writing of the APIs to be tested with relevant headers, the JSON data to be passed.

Here is the link to the file.

Once you have prepared the file, we can run it by using “locust -f filename.py”.

Your execution will start at port number 8089 and can be seen in the browser:

We will give the entries for emulation, like 10000 users to be spawned within every 100 seconds, also the IP address and the port number on which the webserver is running, for me it is 8880 (Apache Tomcat server).

You can monitor different types of charts for checking out the response times of the APIs:

Along with this, you can parallelly check for failures and also the CPU utilization of your server by using “htop”:

Once you feel that the CPU is handling the application load very well, you can go forward confidently.

For any further queries or anything related to DevOps or troubleshooting or load testing in Python, you can DM me on Linkedin or Instagram. id=acanubhav94.

More content at plainenglish.io

--

--

Linux & DevOps Geek, Blockchain Developer ,Statistics & Data Nerd ,Solutions architect, passionate hands on instructor . High on Athletics and Travel