Iterative Load Testing with Step Size in Locust
In this blog, we will explore step size iteration in Locust, which allows you to define user growth patterns and observe how your system handles the incremental load. We’ll dive into an example that uses a custom LoadTestShape
for step-load behavior.
Why Use Step-Load Testing?
Step-load testing gradually increases the number of simulated users at predefined intervals, providing insights into
How the system scales with additional load.
The exact user count where bottlenecks or failures occur.
Server behavior under sustained stress.
Example Code: Step-Load with Locust
Here’s a practical implementation of step-load testing in Locust. We’ll use a custom LoadTestShape
class to define step-wise load increments.
How the Step-Load Works
Step Timing:
Each step lasts for 60 seconds (
step_time
).Users are added incrementally every step, with 10 new users per step (
step_users
).
Spawn Rate:
Users are spawned at a rate of 5 users per second (
spawn_rate
), ensuring a steady ramp-up.
Maximum Users:
The test stops once the user count reaches 100 (
max_users
).
Custom Load Test Shape:
The
tick()
method calculates the current step based on runtime and determines the number of active users and spawn rate for that step.If the number of users exceeds the maximum, the test gracefully stops.
Last updated