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 This script imports the HTTP module and makes a single GET request to a test website.
test.js with the following content:test.js
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
Adding load configuration
Now let’s make the test more realistic by adding multiple virtual users and a test duration: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:Working with multiple requests
Test multiple endpoints and use checks to validate responses:Batch requests for better performance
Usehttp.batch() to send multiple requests in parallel:
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
Smoke test
Smoke test
Minimal load to verify system functionality:
Load test
Load test
Normal expected load:
Stress test
Stress test
Push beyond normal capacity:
Spike test
Spike test
Sudden traffic surge: