Write, run, and interpret k6 load tests: scenario design (smoke, load, spike, soak, stress), SLO thresholds that gate CI, reading k6's metrics output, and wiring runs into CI pipelines. Triggers when someone needs to load test an HTTP API or website, asks how many users a system can handle, or wants performance gates in CI.
./install.sh k6-load-testingname: "k6_load_testing" description: "Write, run, and interpret k6 load tests: scenario design (smoke, load, spike, soak, stress), SLO thresholds that gate CI, reading k6's metrics output, and wiring runs into CI pipelines. Triggers when someone needs to load test an HTTP API or website, asks how many users a system can handle, or wants performance gates in CI."
Turn "is it fast enough under load?" into a runnable k6 script with SLO thresholds, then read the results and know what to fix. Covers HTTP APIs and web services; enough for first-pass browser/perf hybrid awareness but protocol load is the core.
references/scenarios.md: ramp (capacity baseline), spike (surge), soak (long-run degradation), stress/breakpoint (find the ceiling). Use multiple named scenarios in one script when a flow needs separate load shapes (see references/scenarios.md for executor choice).references/thresholds.md). k6 exits non-zero on breach, which is what gates CI.http_req_duration p(95)/p(99), http_req_failed rate, http_reqs throughput, and the checks summary. See references/reading-results.md for the decision tree (is it the app, the DB, or the network?).references/ci.md: smoke on every PR, heavier scenarios nightly or pre-release, results exported as JSON artifacts.A finished job hands back:
references/reading-results.md.A smoke script that actually runs. Uses Grafana's free public test API (the same quickpizza.grafana.com endpoint their docs use for examples) so anyone can execute it without a target of their own:
js
import http from 'k6/http';
import { check, sleep } from 'k6';
const BASE_URL = __ENV.BASE_URL || 'https://quickpizza.grafana.com';
export const options = {
vus: 2,
duration: '30s',
thresholds: {
http_req_failed: ['rate<0.01'],
http_req_duration: ['p(95)<2000'],
},
};
export default function () {
const res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify({
maxCaloriesPerSlice: 500,
mustBeVegetarian: false,
excludedIngredients: ['pepperoni'],
excludedTools: ['knife'],
maxNumberOfToppings: 6,
minNumberOfToppings: 2,
}), { headers: { 'Content-Type': 'application/json' } });
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}
Run it: k6 run smoke.js, or against your own target: k6 run -e BASE_URL=https://staging.example.com smoke.js. Thresholds are relaxed here because a shared public API is slower and noisier; your own staging environment gets tighter numbers from your SLOs.
check validates response content and only logs failures; it does not fail the run. A threshold enforces an SLO and fails the run when breached. Use checks for correctness, thresholds for SLOs.publisher key 2e43c913833850e6d80f939677e3de76e806d47785c0f1caaca90f9d18c98e1e
No ratings yet — be the first to rate it.