Design a stress profile
A stress profile extends your baseline load profile by adding stages that push above the load you validated in baseline testing. Where a baseline test holds at your expected production VU count, a stress test ramps past that point and holds at a higher level so you can watch for degradation. The exercises below ramp to 2× and then 3× your baseline target as a clear, repeatable pattern; in your own environments you would size overload from risk (there is no single correct multiplier). The key addition is an elevated-load plateau: a period at higher concurrency where the system either stabilizes or shows strain.
To design a stress profile, complete the following steps:
In your code editor, create a new file named
stress.jsand add the following imports:import http from 'k6/http'; import { check, sleep } from 'k6';Tip: If your Grafana Cloud stack has Grafana Assistant enabled, you can use k6 Script Authoring mode to generate a stress script from a plain-language description (for example, 2× and 3× stages with looser thresholds). This path uses a code editor so you can see and modify the profile directly when you run tests locally.
Define the stress profile using
stages.The following example starts with a baseline phase at 20 VUs, then ramps to 40 VUs (2x), then 60 VUs (3x), before ramping down:
export const options = { stages: [ { duration: '30s', target: 20 }, // ramp from 0 VU to 20 VU { duration: '1m', target: 20 }, // sustain 20 VU { duration: '30s', target: 40 }, // ramp from 20 VU to 40 VU { duration: '1m', target: 40 }, // sustain 40 VU { duration: '30s', target: 60 }, // ramp from 40 VU to 60 VU { duration: '1m', target: 60 }, // sustain 60 VU { duration: '30s', target: 0 }, // ramp from 60 VU to 0 VU ], thresholds: { http_req_duration: ['p(95)<500'], http_req_failed: ['rate<0.05'], checks: ['rate>0.99'], }, };Stages one, three, and five ramp load over 30 seconds; stages two, four, and six sustain that load for one minute. The first pair establishes normal operating conditions; the next pairs push to 2× and then 3×. Adjust the
targetvalues based on your own baseline VU count.Tip: The thresholds are deliberately looser than in a baseline test so you can observe strain without the run stopping at the first error. Setting
rate<0.05(5% error rate) instead ofrate<0.01(1%) leaves room to watch the degradation curve. Resilient targets like QuickPizza may pass every stage anyway. That does not mean your profile is wrong.Add the default function with checks.
Use QuickPizza as in the earlier k6 paths:
export default function () { const res = http.get('https://quickpizza.grafana.com'); check(res, { 'status is 200': (r) => r.status === 200, 'response body is not empty': (r) => r.body.length > 0, }); sleep(1); }If you are testing your own service instead of QuickPizza, change the URL passed to
http.get(...)to your endpoint.Save
stress.js. Combine theoptionsblock from step 2 and the default function from step 3 into one file before you run the test in the next milestone.
In the next milestone, you run this stress test and learn how to identify the failure signals that indicate your system is under strain.