Load testing with Python and Locust
Web 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.
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.