Generating custom loads with Locust

The significance in ramping-up and ramping-down the user load

Performance tests support in creating reliable applications and make a better end-user experience. Hence, before we release an application to production it is recommended to run performance tests. Load testing scripts that can simulate actual user behaviors should be developed to understand performance bottlenecks. And then developers can come up with appropriate fixes. User patterns and application usage should be analyzed before writing performance scripts. These analyses indicate where the usual and peak traffic times exist.

Locust

We can generate similar load test scenarios and check at what stage our infrastructure starts misbehaving using Locust. Locust is an open-source performance testing framework written in Python which allows writing performance scripts in pure Python. The tool is implemented to resolve some specific issues with existing performance tools. You can write some effective performance scripts using this framework with some Python experience.

LoadTestShape class in Locust

Locust supports controlling user count and simulates load test strategies by using its LoadTestShape class. When we need to test how our applications behave during high traffic times, that cannot be achieved by simply setting or changing the user count and spawn rate. In such scenarios, a completely custom-shaped load test is required.

Figure (1). loadtestShape.py
  • Then continue with a spawn rate of 10 users and ramp-up to 50 users until the 45 seconds mark
  • Then again continue with a spawn rate of 10 users and ramp-up to 100 users until the 75 seconds mark
  • Then continue with a spawn rate of 10 users and ramp-down to 30 users until the 90 seconds mark
  • Then continue with a spawn rate of 10 users and ramp-down to 10 users until the 105 seconds mark
  • Then continue with a spawn rate of 1 user and ramp-down to 1 user until the 120 seconds mark
  • And finally, end the stages and ramp-down to 0 user
Figure (2). Running the Locust file
Figure(3). Starting a new load test
Figure(4).Console log which explains the load
Figure(5).Console log statistics
Figure(6).User interface statistics
Figure(7).Number of Users graph

Senior QA Engineer