SoftwareTestPilot
Performance TestingPublished: 12 min read

k6 Tutorial — Modern Load Testing in JavaScript (2026)

Get productive with k6 in an hour: scripting, stages, thresholds, checks, and the Grafana Cloud output that replaces JMeter for teams shipping to Kubernetes.

Avinash Kamble
Founder & QA Engineer at SoftwareTestPilot
Reviewed by Priyanka G.
Share:XLinkedInWhatsApp
k6 tutorial — JavaScript load testing with stages, thresholds, and Grafana output.
k6 tutorial — JavaScript load testing with stages, thresholds, and Grafana output.

Last updated 2026-07-20 · 12 min read · By Avinash Kamble, reviewed by Priyanka G.

k6 replaced JMeter as the default load-test tool for cloud-native teams because scripts are JavaScript, results stream to Grafana, and one binary runs anywhere. This tutorial takes you from install to a production CI pipeline with meaningful thresholds.

Key takeaways

  • Install k6 and run your first load test in 5 minutes.
  • Stages, VUs, and iterations — the model you must understand.
  • Thresholds and checks — how to fail a build on p95 latency.
  • Output to Grafana Cloud and integrate into GitHub Actions.

1. Install and first test

brew install k6         # macOS
choco install k6        # Windows
sudo apt install k6     # Debian/Ubuntu

# script.js
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  vus: 10,
  duration: '30s',
};

export default function () {
  const res = http.get('https://api.example.com/health');
  check(res, { 'status is 200': (r) => r.status === 200 });
  sleep(1);
}

# run
k6 run script.js

2. Stages — ramp-up and hold

export const options = {
  stages: [
    { duration: '2m', target: 100 },   // ramp to 100 VUs
    { duration: '5m', target: 100 },   // hold
    { duration: '2m', target: 500 },   // spike
    { duration: '5m', target: 500 },   // hold
    { duration: '2m', target: 0 },     // ramp down
  ],
};

Match stages to a real user pattern. See our performance strategy guide for how to derive stages from prod metrics.

3. Thresholds — fail the build on regressions

export const options = {
  thresholds: {
    http_req_failed: ['rate<0.01'],                 // < 1% errors
    http_req_duration: ['p(95)<500', 'p(99)<1500'], // p95 < 500ms
    checks: ['rate>0.99'],                          // 99% checks pass
  },
};

k6 exits non-zero when thresholds fail — perfect for CI gating.

4. Scenarios — realistic mixes

export const options = {
  scenarios: {
    browse: { executor: 'ramping-vus', stages: [...], exec: 'browse' },
    checkout: { executor: 'constant-arrival-rate', rate: 10,
      timeUnit: '1s', duration: '5m', preAllocatedVUs: 20, exec: 'checkout' },
  },
};

export function browse() { http.get('/products'); }
export function checkout() { http.post('/orders', payload); }

5. Output to Grafana Cloud + CI

# Local Grafana + InfluxDB
k6 run --out influxdb=http://localhost:8086/k6 script.js

# Grafana Cloud k6
K6_CLOUD_TOKEN=... k6 cloud script.js

# GitHub Actions
- uses: grafana/k6-action@v0.3.1
  with:
    filename: script.js
    flags: --out cloud

See the official k6 docs and compare with JMeter to choose per project.

Frequently asked questions

1.k6 or JMeter in 2026?
k6 for cloud-native teams shipping scripts as code; JMeter for teams with existing recorded scenarios and heavy protocol variety.
2.Does k6 support browser testing?
Yes — k6/browser (Chromium) runs real browser scenarios alongside protocol tests. Great for end-to-end perf.
3.How many VUs can one k6 instance drive?
Roughly 30-40k VUs on a modern 8-core machine, protocol-level. Browser mode is 100-500 VUs per instance.
4.Is k6 free?
The k6 CLI is open source (AGPL). Grafana Cloud k6 has a free tier plus paid plans for higher VUs and longer retention.
Keep going

Practice these questions

Run a live QA mock interview tailored to this topic and get per-skill scoring in minutes.

Found this useful?
Share:XLinkedInWhatsApp

Was this article helpful?

Cluster · Performance

More from k6 Load Testing

Grafana k6 — scripting, thresholds, scenarios.

Pillar guide · 3 articles
More in this cluster
From the Performance pillar

Keep building your QA edge

Continue reading

Topic mapConcepts · Tools · People · Standards

Related concepts, tools & standards around Performance Testing

A quick reference of the people, companies, frameworks and technologies most often mentioned alongside Performance Testing in real QA teams — useful when you're mapping a learning path, preparing for interviews, or scoping a new project.

Core testing concepts
ThroughputResponse Time SLARamp-up ProfileTest PyramidShift-Left TestingBehavior-Driven DevelopmentTest-Driven DevelopmentPage Object ModelContract TestingExploratory Testing
Programming languages
JavaPythonJavaScriptTypeScriptC#SQL
Certifications worth knowing
ISTQB Foundation LevelISTQB Advanced — Test AnalystISTQB Agile TesterCertified Selenium ProfessionalAWS Certified DevOps EngineerCertified ScrumMaster (CSM)
Companies hiring for this skill
GoogleMicrosoftAmazonMetaNetflixAtlassianThoughtWorksInfosysTCSWipro

Discussion

Ask a question, share your experience, or correct us. Be kind — real people are reading.

Join the QA Community

Connect with fellow testers, share job leads, and get career advice.

Premium QA Resources

Stop Reinventing the Wheel. Upgrade Your QA Arsenal.

Take your testing skills from beginner to Lead Engineer. Supercharge your daily workflow with our premium digital resources.

  • Ready-to-use testing strategy templates
  • Advanced API & UI automation guides
  • ⏱️ Save 10+ hours a week on test planning
4.9/5 rating
Explore All Products

⭐⭐⭐⭐⭐ Trusted by 1,000+ Software Test Pilots • Instant Access