k6 Load Testing
Execution scope
Confirm exact target, environment, VU/request-rate/duration ceilings, window, stop conditions, downstream effects and test-data cleanup before load. Start at one VU; examples are not permission to stress a public endpoint. Cloud output requires authorization to upload results and incur charges. Checks alone do not fail a k6 run: add checks thresholds for asserted functional correctness. Fixtures must be nonempty and user allocation must match concurrency; modulo reuse can distort auth results.
Detailed Guide
Read the detailed guide before executing this skill. It retains the complete procedure and reference material. Treat its safety, prerequisites, and validation requirements as mandatory. For focused work, load the relevant sections; for end-to-end work, read the guide completely.
When to Use This Skill
- Use when you need to load test HTTP APIs, WebSocket endpoints, or browser scenarios
- Use when setting up performance regression tests in CI/CD
- Use when analyzing system behavior under various load conditions
- Use when comparing performance between code changes
- Use when validating SLA requirements and performance budgets
Examples
Example 1: Basic API Load Test
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 50,
duration: '2m',
thresholds: {
http_req_duration: ['p(95)<500'],
http_req_failed: ['rate<0.01'],
},
};
export default function () {
const res = http.get('https://api.example.com/users');
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
sleep(1);
}
Example 2: Test with Authentication and Data Parameterization
import http from 'k6/http';
import { check } from 'k6';
import { SharedArray } from 'k6/data';
const users = new SharedArray('users', function () {
return JSON.parse(open('./users.json'));
});
export default function () {
const user = users[__VU % users.length];
const loginRes = http.post('https://api.example.com/login',
JSON.stringify({ email: user.email, password: user.password }),
{headers: {'Content-Type': 'application/json'}, timeout: '10s', redirects: 0}
);
if (!check(loginRes, {'login succeeded': r => r.status === 200})) return;
let token;
try { token = loginRes.json('access_token'); } catch (_) { return; }
if (typeof token !== 'string' || !token) return;
const headers = { 'Authorization': `Bearer ${token}` };
const res = http.get('https://api.example.com/profile', { headers });
check(res, { 'profile loaded': (r) => r.status === 200 });
}
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
1---2name: k6-load-testing-23description: Comprehensive k6 load testing skill for API, browser, and scalability testing. Write realistic load scenarios, analyze results, and integrate with CI/CD.4metadata:5 source: https://skillmd.com/skills/sickn33/k6-load-testing-26 aas-category: testing7 aas-risk: safe8 aas-source: community9 aas-date-added: '2026-03-13'10 aas-author: Kairo Official11 aas-tags: '["k6","load-testing","performance","api-testing","ci-cd"]'12 aas-tools: '["claude","cursor","gemini"]'13---1415# k6 Load Testing1617## Execution scope1819Confirm exact target, environment, VU/request-rate/duration ceilings, window, stop conditions, downstream effects and test-data cleanup before load. Start at one VU; examples are not permission to stress a public endpoint. Cloud output requires authorization to upload results and incur charges. Checks alone do not fail a k6 run: add checks thresholds for asserted functional correctness. Fixtures must be nonempty and user allocation must match concurrency; modulo reuse can distort auth results.2021## Detailed Guide2223Read [the detailed guide](references/detailed-guide.md) before executing this skill. It retains the complete procedure and reference material. Treat its safety, prerequisites, and validation requirements as mandatory. For focused work, load the relevant sections; for end-to-end work, read the guide completely.2425## When to Use This Skill2627- Use when you need to load test HTTP APIs, WebSocket endpoints, or browser scenarios28- Use when setting up performance regression tests in CI/CD29- Use when analyzing system behavior under various load conditions30- Use when comparing performance between code changes31- Use when validating SLA requirements and performance budgets3233---3435## Examples3637### Example 1: Basic API Load Test3839```javascript40import http from 'k6/http';41import { check, sleep } from 'k6';4243export const options = {44 vus: 50,45 duration: '2m',46 thresholds: {47 http_req_duration: ['p(95)<500'],48 http_req_failed: ['rate<0.01'],49 },50};5152export default function () {53 const res = http.get('https://api.example.com/users');54 55 check(res, {56 'status is 200': (r) => r.status === 200,57 'response time < 500ms': (r) => r.timings.duration < 500,58 });59 60 sleep(1);61}62```6364### Example 2: Test with Authentication and Data Parameterization6566```javascript67import http from 'k6/http';68import { check } from 'k6';69import { SharedArray } from 'k6/data';7071const users = new SharedArray('users', function () {72 return JSON.parse(open('./users.json'));73});7475export default function () {76 const user = users[__VU % users.length];77 78 const loginRes = http.post('https://api.example.com/login',79 JSON.stringify({ email: user.email, password: user.password }),80 {headers: {'Content-Type': 'application/json'}, timeout: '10s', redirects: 0}81 );82 83 if (!check(loginRes, {'login succeeded': r => r.status === 200})) return;84 let token;85 try { token = loginRes.json('access_token'); } catch (_) { return; }86 if (typeof token !== 'string' || !token) return;87 88 const headers = { 'Authorization': `Bearer ${token}` };89 const res = http.get('https://api.example.com/profile', { headers });90 91 check(res, { 'profile loaded': (r) => r.status === 200 });92}93```9495---9697## Limitations98- Use this skill only when the task clearly matches the scope described above.99- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.100- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.