When creating a load test, it is sometimes desirable to control how the rate of requests are scaled over time. k6 provides this behavior through the ramping-vus
executor, which allows gradual scaling of virtual users over a specified duration. This enables realistic simulations of user traffic patterns as expected in real-world use cases. In this brief post, we will outline the basics of using this feature in k6.
Example Script of Ramping VUs
The following k6 script outlines the syntax and usage of the ramping-vus
executor. You can also find a similar script example in the official k6 documentation pages:
import http from 'k6/http'; import { sleep } from 'k6'; export const options = { discardResponseBodies: true, scenarios: { contacts: { executor: 'ramping-vus', startVUs: 0, stages: [ { duration: '300s', target: 100 }, { duration: '60s', target: 0 }, ], gracefulRampDown: '30s', }, }, }; export default function () { http.get('https://test.k6.io/contacts.php'); sleep(0.5); }
In this two-stage example, the parameters specified tell k6 to first gradually ramp up users from zero to 100 simultaneous VUs over 5 minutes (i.e., 300 seconds). From that point, VUs are gradually taken out of rotation to smoothly taper back down to zero over the next 60 seconds. Finally, there is a graceful ramp down period specified of 30 seconds, which gives this additional time for requests to complete without abruptly ending the process.
Ramping VUs Configuration Options
In the above example, there are three options specific to the ramping-vus
executor. These are:
stages
– accepts an array of target number of VUs, and a duration over which ramp up or ramp down occursstartVUs
– accepts an integer count of the number of starting VUsgracefulRampDown
– specifies a duration of time over which requests already initiated are allowed to complete without terminating the process abruptly
Ideal Use Case
For tests which are intended to simulate real-world scenarios where requests to a target test application follow an expected cohort of users accessing a site over a period of time. This is a pattern which is arguably more realistic than a load test that simply aims to arbitrarily saturate a test endpoint without regard to the rate at which new VUs are instantiated. Testing with the ramping-vus
executor can thereby more realistically simulate actual expected user traffic in your tests.
Did you know that RedLine13 offers a full-featured, time-limited free trial? Sign up now, and move your k6 testing into the cloud today!