Build a breakpoint script

If you completed the stress milestones, you already have degradation results or a documented clean run. Breakpoint testing is optional and runs on a dedicated stack when you want an approximate outer bound beyond that stress profile.

Breakpoint testing ramps load continuously toward high load until thresholds fail or the ramp ends: an approximate outer bound, not an operating target.

Note

On QuickPizza, the ramp often completes without abort. You still learn ramping-arrival-rate and abortOnFail. For your own stack, use a dedicated test environment and disable autoscaling on components you want to measure. Refer to Breakpoint testing.

Tip

To see abortOnFail stop a run on QuickPizza, run QuickPizza locally with Docker and point http.get(...) at your local instance. You can use the same breakpoint.js script from this milestone to ramp a local instance to failure.

This milestone introduces the ramping-arrival-rate executor (RPS ramps over time) and abortOnFail thresholds (stop the run when conditions fail). For one-request scripts, iterations per second matches RPS.

To build a breakpoint script, complete the following steps:

  1. In your code editor, create a new file named breakpoint.js and add the following imports:

    JavaScript
    import http from 'k6/http';
    import { check, sleep } from 'k6';
  2. Define a scenario using the ramping-arrival-rate executor.

    The following example ramps from 0 to 200 iterations per second over 10 minutes, pre-allocating enough VUs to sustain the target rate. Plan for about 10 minutes of runtime on the next milestone when you run this script as written. Shorten duration (for example to 3m) while learning if you want a faster iteration.

    JavaScript
    export const options = {
      scenarios: {
        breakpoint: {
          executor: 'ramping-arrival-rate',
          startRate: 0,
          timeUnit: '1s',
          preAllocatedVUs: 500,
          maxVUs: 1000,
          stages: [
            { duration: '10m', target: 200 },
          ],
        },
      },
      thresholds: {
        http_req_duration: [
          {
            threshold: 'p(95)<2000',
            abortOnFail: true,
            delayAbortEval: '30s',
          },
        ],
        http_req_failed: [
          {
            threshold: 'rate<0.20',
            abortOnFail: true,
            delayAbortEval: '30s',
          },
        ],
      },
    };

    The preAllocatedVUs and maxVUs values avoid VU starvation during the ramp. delayAbortEval waits before abort evaluation so early noise does not stop the run; see Thresholds.

    Note

    Adjust target and duration for your stack. If stress showed no degradation on QuickPizza, you may finish the full ramp without abort, which is still a valid result.

  3. Add the default function with the same checks you’ve used throughout this path:

    JavaScript
    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(0.1);
    }

    The sleep value is shorter than in the stress test because the ramping-arrival-rate executor controls the request rate independently of VU think time.

  4. If you are testing your own service, replace the URL in http.get(...) with your endpoint, then save breakpoint.js.

In the next milestone, you run this breakpoint test and read off the load at test stop (threshold abort or end of ramp).

More to explore (optional)

At this point in your path, you can explore the following topics:

Ramping arrival rate executor

Thresholds with abortOnFail

Breakpoint testing


page 6 of 9