Design your load profile
A load profile defines how many virtual users (VUs) hit your system and for how long. The shape of the profile matters because a sudden spike of traffic produces different results than a gradual ramp. For a reliable baseline, you want a profile that ramps up to a steady state, holds long enough to collect stable data, and then ramps back down.
k6 provides the ramping-vus executor for this purpose. You configure it with a stages array where each stage specifies a target VU count and a duration. k6 linearly ramps between stages, giving you full control over the traffic shape.
To design a load profile for your baseline test, complete the following steps:
In your code editor, create a new file named
baseline.jsand add the following imports.If you prefer a visual approach to script creation, you can use k6 Studio. This path uses a code editor so you can see and modify the script directly as you add checks and thresholds in later milestones.
import http from 'k6/http'; import { sleep } from 'k6';Define your load profile using the
stagesoption.The following example ramps up to 20 VUs over 30 seconds, holds steady for 1 minute, then ramps back down over 30 seconds:
export const options = { stages: [ { duration: '30s', target: 20 }, { duration: '1m', target: 20 }, { duration: '30s', target: 0 }, ], };The
stagesshorthand automatically uses theramping-vusexecutor. Adjust thetargetvalues to match the concurrent user count you expect in production, and adjust durations to allow enough time for metrics to stabilize.Add the default function that contains your test logic:
export default function () { http.get('https://quickpizza.grafana.com'); sleep(1); }Replace the URL with the endpoint you want to baseline.
Save the file. Your complete
baseline.jsshould look like this:import http from 'k6/http'; import { sleep } from 'k6'; export const options = { stages: [ { duration: '30s', target: 20 }, { duration: '1m', target: 20 }, { duration: '30s', target: 0 }, ], }; export default function () { http.get('https://quickpizza.grafana.com'); sleep(1); }Tip
The steady-state stage (the middle stage) is where your baseline data comes from. Make it long enough, at least 1 minute, so the metrics stabilize and reflect consistent system behavior rather than warm-up effects.
In the next milestone, you add checks to validate that responses are correct, not just fast.
At this point in your path, you can explore the following topics: