Skip to main content
Image
blog%20banner%20load%20testing.jpg

Load Testing with Locust: An Overview

article publisher

Jayati

Generic

Who doesn't want their site to be a success? But are you prepared for that success? And how can you be 100% prepared for it? What all measures are to be taken to ensure it?

An elderly man lifting four loaded boxes


One of the most important measures is load testing.

It helps expose and identify potential performance killers and provide insight into how a site will perform in the wild under peak traffic spikes.

What is Load Testing?

Load testing is the process where you apply requests to your site to unleash the maximum load that your site will face once it is live. The test ensures that the site can withstand the peak traffic spikes after the launch. This test is ideally performed on the live environment before the site launch to anticipating major-traffic events or after major overhauls.

Load testing is the process where you apply requests to your site to unleash the maximum load that your site will face once it is live.

In case, your site is already live, you can run load tests on the test environment which has two application containers. However, live environments on sites with a service level of Performance Medium and above can have multiple application containers serving the site. Thus, try to run a proportionate amount of traffic based on how many containers you currently have on your live environment.

Load testing in 5 steps

Along with knowing if our site can handle the desired number of visitors, we also want to know how far we can go. Thus, we focus on load and stress testing with the following steps:

1. Existing Data

Retrieving data from existing statistics helps to create realistic scenarios in test preparation. For instance, the number of visitors on the website. But if the site is new, the existing customer can share some insights. And in case you are building a new version of the same site, you can still guess about expected visits.

2. Make Scenarios

If you want to simulate that a large number of visitors, simultaneously, click on several pages, download documents, login, send forms, etc, then make sure you have enough CPU on your machine to perform the tests. This will be a realistic and multiple scenarios test to determine limit values and to assign an accurate score to the performance.

3. Pick the Tool

Next, you need to determine the tool that can be used to carry out the test. Most used and common tools are: 

  • Apache Bench(AB) -  Can conduct load test only for the webserver - HTTP or HTTPS
  • Gatling - A paid alternative similar to JMeter. 
  • Locust:  Uses Python code.
  • Siege - Similar to AB, more extensive and useful for performing a quick load test.
  • Blazemeter - With simple characterization, it is a hosted version of Jmeter.
  • Jmeter - An open source testing tool with many possibilities and proven solutions. 

Although all these tools are equally performative and well tested, moving ahead in this blog, we will focus on load testing with Locust only.

4. Test

This is a crucial step where we determine whether the current infrastructure is sufficient to run the application and sustainable with respect to peak user load. The goal of detecting the network delay between the client and the server is also achieved along with other issues that flesh out.

5. Analyze

Analyzing the results makes us learn more about the out of sight problems in our application and thus, widens the scope of improvement.

What is locust?

Locust logo with the word ‘LOCUST’ written on right and green coloured circle with an insect inside on the left


Locust is an easy-to-use open source load testing tool written in Python intended for load-testing web sites and figuring out how many concurrent users a system can handle. It can simulate millions of users to load test your application with an intuitive user interface that you can use to easily get started with it.

Locust is an easy-to-use open source load testing tool written in Python intended for load-testing web sites and figuring out how many concurrent users a system can handle

During a test, a swarm of locusts attacks your website where the behavior of each locust is defined by you and the swarming process is monitored from a web UI in real-time. This helps in battle test and identifies bottlenecks in your code before letting real users in.

Being a complete event-based tool, Locust can support thousands of users on a single machine. When compared to other event-based apps, it doesn’t use callbacks. Instead, it uses light-weight processes, through gevent. This allows writing very expressive scenarios in Python without complicating the code with callbacks.

Why Locust?

  • It uses plain-old Python for test scenarios. 
  • Doesn’t require clunky UIs or bloated XML. By using coroutines instead of callbacks, your code looks and behaves normally as blocking Python code
  • Being distributed and scalable, it supports thousands of users
  • Locust holds upload tests distributed over multiple machines which simulate millions of simultaneous users.
  • It has a web-based UI
  • Locust features a neat HTML+JS user interface that brings out relevant test details in real-time. And along with web-based UI, it’s cross-platform and easily extendable
  • Despite being web-oriented, it can be used to test almost any system
  • Locust is small and very hackable as all heavy-lifting of evented I/O and coroutines are delegated to gevent. 

In Conclusion 

Locust is a relatively fresh performance framework written in Python. The main trademark of this framework is that you can write performance scripts in pure Python. Along with its “test as code” feature, Locust is highly scalable due to its extensively event-based implementation. Because of these facts, Locust has a wide and fast-growing community, who prefer this framework over JMeter which is written in pure Java language and has an elaborate versions history. 

With the fleeting developments in technology, performance and load testing have become an integral part of the process. 

At OpenSense Labs, we understand that websites need to be robust and equipped to face unanticipated challenges in order to boost the overall performance. Contact us at [email protected]. Catch all-new updates and news on Drupal at our Twitter handle @OpenSenseLabs.

Subscribe

Ready to start your digital transformation journey with us?

Related Blogs

In conversation with Danish Usmani, CEO, OpenSense Labs

danish-interview-osl.jpeg

In a year-end interview, CEO Danish Usmani showcases OpenSense Labs' achievements, emphasising new client partnerships and expansions. He…

Why should you prioritize lean digital in your company?

Untitled%20design%20%281%29.png

We are living in an era where the change and innovation rate is just so high. If you want your organization to reach new heights then you…

How to measure your open source program’s success?

Untitled%20design%20%282%29%20%281%29%20%281%29.png

Along with active participation, it is very important to look after the ROI of open-source projects, programs, and contributions. The…