Skip to main content

Overview

This guide will walk you through creating and running your first k6 load test. You’ll learn the basics of k6 scripting, test execution, and results interpretation.
Make sure you have k6 installed before proceeding with this guide.

Your first test

Let’s start with the simplest possible k6 test:
1

Create a test script

Create a new file called test.js with the following content:
test.js
This script imports the HTTP module and makes a single GET request to a test website.
2

Run the test

Execute your test from the command line:
k6 will run the test with a single virtual user for one iteration.
3

View the results

You’ll see output showing various metrics including:
  • Request duration
  • Response time percentiles
  • Data sent and received
  • HTTP success rate
By default, k6 runs with 1 virtual user for 1 iteration. You can change this behavior using command-line flags or test options.

Adding load configuration

Now let’s make the test more realistic by adding multiple virtual users and a test duration:
This test runs with 10 virtual users for 30 seconds, making requests with 1-second pauses between iterations.

Using ramping stages

For more realistic load patterns, use stages to ramp traffic up and down:
Stages allow you to simulate realistic traffic patterns like gradual user onboarding, steady-state usage, and graceful shutdown.

Adding thresholds

Thresholds let you define pass/fail criteria for your tests:
If any threshold fails, k6 exits with a non-zero exit code. This makes thresholds perfect for CI/CD integration where you want tests to fail the build if performance degrades.

Working with multiple requests

Test multiple endpoints and use checks to validate responses:

Batch requests for better performance

Use http.batch() to send multiple requests in parallel:
Batch requests are much more efficient than sequential requests when you need to test multiple endpoints simultaneously.

Working with JSON data

Send and parse JSON data in your requests:

Using custom metrics

Track custom metrics specific to your application:
k6 supports four types of custom metrics:
  • Counter: Sum of all values added
  • Gauge: Latest value set
  • Rate: Percentage of non-zero values
  • Trend: Time series with statistical aggregations

Understanding test results

After running a test, k6 displays detailed metrics:

Response times

Look at http_req_duration percentiles (p90, p95, p99) to understand user experience.

Error rate

Check http_req_failed to see the percentage of failed requests.

Throughput

http_reqs shows requests per second your system can handle.

Data transfer

data_received and data_sent track network usage.

Next steps

Test types

Learn about different load testing patterns: smoke, load, stress, and spike tests

HTTP requests

Deep dive into HTTP methods, headers, authentication, and more

Scenarios

Advanced workload modeling with open/closed models and executors

Results output

Export metrics to InfluxDB, Prometheus, Grafana Cloud, and more

Common testing patterns

Minimal load to verify system functionality:
Normal expected load:
Push beyond normal capacity:
Sudden traffic surge:
Start with smoke tests to validate your scripts, then gradually increase load to understand your system’s behavior.