Load testing with Python and Locust

Locust.io is an open source Python-based user load testing tool. This lightweight, distributed and scalable framework helps to figure out how many concurrent users a system can handle by writing test scenarios in Python code.

Locust.io load testing toolWeb applications and services need efficient scaling for serving a large number of requests. In order to check the behavior of services under load developers need to perform load and stress testing. They generate requests similar to those made by users and test them in production environment. The results (as close to real and accurate as possible) are used for optimization of application or service. There are different tools that assist with building, conducting and analyzing load tests for the web. One of them is Locust.

Locust.io is an open source Python-based user load testing tool. This lightweight, distributed and scalable framework helps to find out how many concurrent users a system can handle by writing test scenarios in Python code. It can be used for web applications, websites and web-based services.

The main idea is that the behavior of each test user (locust) is defined by developer or tester. Then “a swarm of locusts will attack” your web application or service. There is no need for bloated XML or clunky UIs. Locust scripts are written in simple Python code. This way test codes are more reusable and version control tools can be applied to track the differences between histories.

Locust.io is completely event based and uses the async approach, so it can support running thousands load tests on a single machine or distributed over multiple machines to simulate milions of concurrent users. In contrast to many other similar tools it uses gevent instead of callbacks. This means that each locust runs inside it’s own process (greenlet). Any number of test users will act independently with their own session data. When the tasks are defined, each Locust node can handle thousands of users in a single process. This framework even allows running in a distributed master/worker fashion with only a few configuration adjustment.

Locust comes with a web-based user interface (in HTML and JavaScript) that displays test data in real-time. This tool measures request/second (or minimum, maximum, average), total request, failed request, etc. All relevant data is shown in the form of reports in dashboard. The UI is cross-platform and easily extendable. Users can use it to start/stop tests. Locust also provides a command line support for single run mode. For master-slave mode, it is possible to control framework via HTTP request.

Locust.io is very hackable. Since all heavy-lifting tasks, like evented I/O and coroutines, are delegated to gevent, you can hack Locust and add specific functionality. Out of the box it tests HTTP endpoints, but it can be extended to test almost anything. The integration for this tool is seamless and it is highly customizable with the help of JavaScript and Python. So despite being web-based, Locust can test almost any system if you write a client for it.

Among the main benefits of Locust are concurrency, scalability, maintainability and customization. It is very useful in finding the server’s issues, like resource exhausted, memory leak, etc. Visit locust.io for more detailed information.

Connect with our experts Let's talk