Skip to content
Tutorials Center
My learning

Topics

k6 Load Testing Tutorial

Learn k6 Load Testing step by step: 36 lessons in 9 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is k6? Learn what k6 is, why teams use it for load testing, how a k6 test is written in JavaScript but run by a Go engine, and what you can and cannot run on this site.
  2. 2 Installing k6 and Running Your First Test Install k6 on Windows, macOS, Linux or Docker, write a first script, run it with k6 run, override options on the command line, and learn what the output means.
  3. 3 Types of Load Tests Learn the main load test types, smoke, average load, stress, spike, soak and breakpoint tests, what each one finds, and how to express each as k6 stages.
  4. 4 Virtual Users and Iterations Understand how k6 virtual users run iterations of your default function, how vus, duration and iterations interact, why VUs are isolated, and how to avoid common mistakes.
  5. 5 Reading the End-of-Test Summary Learn to read the k6 end-of-test summary: http_req_duration, percentiles, http_req_failed, iterations, vus, data sent and received, plus how percentiles are computed.

Concepts and Scripts

  1. 6 The k6 Script Lifecycle Learn the four stages of a k6 script, init code, setup, the default function and teardown, what runs how often, how data passes between them, and the common mistakes.
  2. 7 Options and Stages Learn the k6 options object, vus, duration, iterations, stages, gracefulStop, setup timeouts, user agent and more, and how stages ramp virtual users up and down.
  3. 8 GET and POST Requests in k6 Send your first requests with k6 http.get and http.post, set headers and JSON bodies, read the response object, parse JSON and use batch requests, with a runnable stand-in.
  4. 9 Groups and Tags Organize k6 results with group() and tags, tag requests and whole tests, keep URL cardinality low with the name tag, and create sub-metrics that thresholds and dashboards can filter on.
  5. 10 Test Data and Environment Variables Feed realistic data into k6 tests with open(), SharedArray and CSV parsing, pick data per VU and iteration, read environment variables with __ENV, and avoid memory blowups.

Checks and Thresholds

  1. 11 Checks in k6 Use k6 check() to validate status codes, bodies and timings, understand why failed checks do not stop a test, read the checks metric, and combine checks with thresholds.
  2. 12 Thresholds: Pass or Fail Your Load Test Define pass/fail criteria with k6 thresholds, write conditions on trends, rates, counters and gauges, filter by tags, abort early with abortOnFail, and use the exit code in CI.
  3. 13 Custom Metrics Create your own k6 metrics with Counter, Gauge, Rate and Trend, record business values such as cart size or login time, tag them, and set thresholds on them.
  4. 14 Think Time and Pacing Make k6 load realistic with sleep() think time, random pauses and pacing that keeps a steady iteration rate, and learn why tests without pauses overstate the load.

Scenarios and Executors

  1. 15 Scenarios Overview Learn what k6 scenarios are, how executors model traffic, the closed versus open workload models, the scenario options every executor shares, and when to leave plain vus and duration.
  2. 16 VU-Based Executors Configure the four VU-based k6 executors, shared-iterations, per-vu-iterations, constant-vus and ramping-vus, with their options, differences and when each one fits.
  3. 17 Arrival-Rate Executors Model an open workload in k6 with constant-arrival-rate and ramping-arrival-rate, size preAllocatedVUs and maxVUs correctly, and understand dropped iterations.
  4. 18 Multiple Scenarios and exec Run several k6 scenarios in one test with exec functions, startTime sequencing, per-scenario env, tags and thresholds, and the execution module to read scenario state.

Protocols and APIs

  1. 19 HTTP Requests, Bodies and Responses in k6 Send GET, POST, PUT and DELETE requests with k6/http, build JSON and form bodies, set headers and tags, and read status, body and timing details from each response.
  2. 20 Batches, Cookies and Redirects in k6 Load a page and its assets in parallel with http.batch, manage cookies with the cookie jar, control redirects and expected statuses, and know when parallelism helps or hurts.
  3. 21 Load Testing WebSockets and gRPC with k6 Test long-lived WebSocket sessions and gRPC calls with k6: event handlers, timers, message metrics, proto files, status codes and what to measure for real-time systems.
  4. 22 Authentication, Tokens and Correlation in k6 Log in once in setup or per iteration, pass bearer tokens, refresh expiring tokens, and correlate dynamic values such as CSRF tokens and ids between requests in k6 scripts.
  5. 23 Browser Testing with k6 and Web Vitals Understand the k6 browser module: drive Chromium with page and locator APIs, read Core Web Vitals, and combine one real browser with many protocol-level users in a hybrid test.

Results and Metrics

  1. 24 k6 Built-in Metrics Explained Learn every important k6 built-in metric, the four metric types (counter, gauge, rate, trend), how percentiles work, and how to read the end-of-test table without being misled.
  2. 25 Sub-metrics, Cardinality and Per-Route Results in k6 Slice k6 results with request tags, test-wide tags, group() and sub-metrics, keep URL cardinality under control and set per-endpoint thresholds that show which route is slow.
  3. 26 k6 End-of-Test Summary, handleSummary and Outputs Customize the k6 end-of-test summary with handleSummary, export JSON and HTML reports, stream metrics with --out to JSON, CSV or Prometheus, and use the web dashboard live.

CI and Cloud

  1. 27 Running k6 in CI/CD Pipelines Run k6 smoke and load tests in CI: exit codes and thresholds as gates, GitHub Actions and GitLab CI examples, what to run on pull requests versus nightly, and how to keep results trustworthy.
  2. 28 k6 with Docker and Kubernetes: Distributed Load Run k6 in Docker and Docker Compose, split one test across machines with execution segments, and use the k6 Operator TestRun resource to run distributed tests in Kubernetes.
  3. 29 Grafana Cloud k6: Cloud and Local Execution Understand Grafana Cloud k6: cloud execution versus local execution with cloud results, load zones and distribution, run comparison, scheduling, cost in VU hours and when open source is enough.

Patterns and Analysis

  1. 30 Test Design: Workload Models, Think Time and Little's Law Design realistic load tests: closed versus open workload models, think time and pacing, Little's Law for sizing VUs, test types (smoke, load, stress, spike, soak) and how to model a traffic mix.
  2. 31 Data Parameterization and SharedArray in k6 Feed k6 tests with realistic data: load JSON and CSV with SharedArray, pick unique rows per VU and iteration, avoid memory blowups, generate random data and handle files and secrets safely.
  3. 32 Analyzing k6 Results and Finding Bottlenecks Turn k6 numbers into conclusions: read latency versus load curves, spot the knee and saturation, separate generator limits from server limits, find common bottlenecks and write up findings.

Projects and Practice

  1. 33 Project: Load Test a REST API End to End Build a complete load test for a REST API: scenarios for browse and checkout, checks, thresholds, custom metrics, and a runnable Node mini-harness that mimics a k6 run against a local server.
  2. 34 Project: Spike and Soak Tests with SLOs Turn service level objectives into k6 thresholds, design a spike test and a soak test, and use runnable Node simulations to detect slow recovery after a spike and a memory-leak trend.
  3. 35 Project: A Performance Gate for Pull Requests Build a performance gate: a k6 smoke test exports a summary, a small Node script compares it with a stored baseline and budgets, posts a Markdown table and fails the build on regressions.
  4. 36 Practice: k6 Exercises with Solutions Practice k6 with design and analysis exercises: write thresholds, choose executors, size VUs, read result tables and build a test plan, with runnable Node self-checks and worked solutions.