Performance Testing with Locust (Part – 2)

Written by Divyanshi Bhamri, QA Engineer at MyGate

1. Introduction


Hello again. This is the second article of a series on performance testing with Locust. I strongly suggest that you take a look at part 1 of the series so that you are ready with environment setup.

Note: As a prerequisite, you need to be familiar with Python to create test scripts.

It is time to familiarise ourselves with few Locust centric attributes [1].

2. TaskSet


Class defining a set of tasks that a Locust user will execute is known as TaskSet. When a TaskSet starts running, it will pick a task from the list of activities marked with a task attribute, execute it, and call its wait_function which defines a time period to sleep. This defaults to a uniformly distributed random number between min_wait and max_wait milliseconds. It will then schedule another task for execution and repeat the process.

3. HttpLocust


For making HTTP calls, we need a class that inherits from HttpLocust. Here we can define other attributes, such as min_wait and max_wait as required.

Note: min_wait and max_wait can be defined in classes inherited either by TaskSet or HttpLocust. In our example we will be defining these attributes at class inherited by HttpLocust.

Step 1: Save this script with .py extension. I have saved this script as locusthello.py.

Note: In this script we are making four different GET requests to four different end points. But one of the main variables which is missing is the domain name. We will pass the domain name while running the test script from the command line with -host parameter.

If required, we can just add a host variable within class as shown below.

4. Script execution


Step 2: Run the following command.

As you can see in the image, the server has been started at port 8089.Step 3: Open a browser and navigate to http://localhost:8089

Once the page loads, you will notice two input text boxes. You need to set the maximum number of users to simulate and hatch rate which indicates ramp-up rate. I have set a configuration of 100 users with a hatch rate of 5. This translates to adding 5 users to the pool at a time until we reach 100 users. Click on submit.

Step 4: The test process starts automatically and you will see results flowing in immediately.

Step 5: Now click on the charts tab. You can inspect different categories of charts such as total request/ second, response time and number of users.

5. Conclusion


This is the second article of its series. In the next post we will learn about how to send POST requests.
Thanks for reading. I hope this article helps you trigger GET requests.

References

[1] Locust Documentation
https://docs.locust.io/
[2] Mock API
https://reqres.in/api

Disclaimer

This is a curated post of an article published at Medium.

Admin

MyGate is building technology to simplify check-ins everywhere. Our flagship solution, launched in 2016, currently facilitates over 2 million check-in requests every day at thousands of gated premises across the 25+ cities in which we operate, and continues to show rapid growth. We’ve strengthened our commitment to information privacy by following GDPR guidelines, the global gold standard for data privacy.

Introducing All Home Utility Payments on the MyGate app

It’s a recurring struggle to pay and manage your home utility bills via different platforms. Getting an overview of this spending is another story. To make life easy for...

Personalizing Customer Connections for Brands with Geo-Targeting

“Geo-targeting allows businesses to personalise their messagingand connect with customers on a more intimate level.”Ryan Holmes All brands are online today and reach out to their audience through online...

MyGate, convenience, and better communication

“Convenience is the catalyst that drives innovation in business.”Elon Musk Convenience is a mindful and necessary business virtue. Every brand is based on solutions to some problem. Communicating this...

A Match Made in Marketing Heaven: MyGate’s Engaged User Base

Attention brands and brand managers! It’s time to leave the old-fashioned advertising methods behind and hop on board the MyGate express! We’ve got some exciting news to share with...

Make Your Brand Unmissable On The Mygate App

“Our jobs as marketers are to understand how the customer wants to buy and help them do so.” Bryan Eisenberg, Founder & CMO at IdealSpot Brands are increasingly increasing...

Helping brands solve the problems of specific consumer tribes

“Our jobs as marketers are to understandhow the customer wants to buy and help them to do so.”– Bryan Eisenberg Personalisation is key to reaching the right audience and...