k6 Load Testing
Modern load testing tool with JavaScript.
Overview
k6 is a modern load testing tool built by Grafana Labs that revolutionizes performance testing with JavaScript-based test scripts and developer-centric design. Unlike traditional tools like JMeter or LoadRunner, k6 emphasizes simplicity, version control compatibility, and CI/CD integration, making it the preferred choice for DevOps teams and developers who need to embed performance testing into their development workflows. Its lightweight architecture and ES6 JavaScript support enable teams to write maintainable test scripts that can be easily shared and evolved alongside application code.
This stack combines k6's testing capabilities with InfluxDB's time-series data storage and Grafana's visualization power to create a comprehensive performance testing observatory. k6 generates detailed metrics during load tests and streams them directly to InfluxDB, where time-stamped performance data is efficiently stored and indexed. Grafana then transforms this raw data into interactive dashboards showing real-time response times, throughput, error rates, and custom business metrics, enabling teams to spot performance bottlenecks as they happen rather than analyzing post-test reports.
Development teams building APIs, microservices, or web applications will find this combination invaluable for establishing performance baselines, regression testing, and capacity planning. The JavaScript-based approach means frontend developers can contribute to performance testing using familiar syntax, while the real-time visualization helps stakeholders understand system behavior under load without technical expertise. This stack particularly shines in environments where performance testing needs to be automated, repeatable, and integrated into continuous delivery pipelines.
Key Features
- JavaScript ES6 test scripts with full module support and modern syntax
- Real-time metrics streaming to InfluxDB with automatic time-series indexing
- Grafana dashboards showing live performance data during test execution
- Built-in HTTP, WebSocket, and gRPC protocol support for modern applications
- Scenario-based testing with ramp-up, constant load, and spike patterns
- Threshold definitions for automatic pass/fail criteria in CI/CD pipelines
- InfluxDB data retention policies for managing long-term performance history
- Grafana alerting on performance degradation with Slack, email, and webhook notifications
Common Use Cases
- 1API performance regression testing in CI/CD pipelines before production deployment
- 2Microservices capacity planning to determine optimal instance counts and resource allocation
- 3E-commerce platform load testing during peak shopping seasons and flash sales
- 4SaaS application performance monitoring across different subscription tiers and usage patterns
- 5Game server stress testing to validate concurrent player capacity and matchmaking performance
- 6Financial trading system latency testing to ensure sub-millisecond response requirements
- 7IoT backend testing to simulate thousands of concurrent device connections and data streams
Prerequisites
- Minimum 1GB RAM available for InfluxDB time-series data processing and storage
- Port 3000 available for Grafana dashboard access and 8086 for InfluxDB API
- Basic JavaScript knowledge for writing and modifying k6 test scripts
- Understanding of HTTP protocols, status codes, and API testing concepts
- Target application or service URLs accessible from the Docker host network
- Familiarity with performance testing metrics like RPS, response time percentiles, and error rates
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 k6: 3 image: grafana/k6:latest4 container_name: k65 volumes: 6 - ./scripts:/scripts7 environment: 8 K6_OUT: influxdb=http://influxdb:8086/k6910 influxdb: 11 image: influxdb:1.812 container_name: k6-influxdb13 restart: unless-stopped14 environment: 15 INFLUXDB_DB: k616 volumes: 17 - k6_influxdb:/var/lib/influxdb18 ports: 19 - "8086:8086"2021 grafana: 22 image: grafana/grafana:latest23 container_name: k6-grafana24 restart: unless-stopped25 environment: 26 GF_AUTH_ANONYMOUS_ENABLED: "true"27 GF_AUTH_ANONYMOUS_ORG_ROLE: Admin28 volumes: 29 - k6_grafana:/var/lib/grafana30 ports: 31 - "3000:3000"32 depends_on: 33 - influxdb3435volumes: 36 k6_influxdb: 37 k6_grafana: .env Template
.env
1# Create test scripts in ./scriptsUsage Notes
- 1Docs: https://k6.io/docs/
- 2Run: docker-compose run k6 run /scripts/test.js
- 3Write tests in JavaScript/TypeScript (ES6 modules)
- 4Grafana dashboard at http://localhost:3000 for real-time metrics
- 5Built-in checks, thresholds, and scenarios support
- 6Cloud integration available for distributed testing
Individual Services(3 services)
Copy individual services to mix and match with your existing compose files.
k6
k6:
image: grafana/k6:latest
container_name: k6
volumes:
- ./scripts:/scripts
environment:
K6_OUT: influxdb=http://influxdb:8086/k6
influxdb
influxdb:
image: influxdb:1.8
container_name: k6-influxdb
restart: unless-stopped
environment:
INFLUXDB_DB: k6
volumes:
- k6_influxdb:/var/lib/influxdb
ports:
- "8086:8086"
grafana
grafana:
image: grafana/grafana:latest
container_name: k6-grafana
restart: unless-stopped
environment:
GF_AUTH_ANONYMOUS_ENABLED: "true"
GF_AUTH_ANONYMOUS_ORG_ROLE: Admin
volumes:
- k6_grafana:/var/lib/grafana
ports:
- "3000:3000"
depends_on:
- influxdb
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 k6:5 image: grafana/k6:latest6 container_name: k67 volumes:8 - ./scripts:/scripts9 environment:10 K6_OUT: influxdb=http://influxdb:8086/k61112 influxdb:13 image: influxdb:1.814 container_name: k6-influxdb15 restart: unless-stopped16 environment:17 INFLUXDB_DB: k618 volumes:19 - k6_influxdb:/var/lib/influxdb20 ports:21 - "8086:8086"2223 grafana:24 image: grafana/grafana:latest25 container_name: k6-grafana26 restart: unless-stopped27 environment:28 GF_AUTH_ANONYMOUS_ENABLED: "true"29 GF_AUTH_ANONYMOUS_ORG_ROLE: Admin30 volumes:31 - k6_grafana:/var/lib/grafana32 ports:33 - "3000:3000"34 depends_on:35 - influxdb3637volumes:38 k6_influxdb:39 k6_grafana:40EOF4142# 2. Create the .env file43cat > .env << 'EOF'44# Create test scripts in ./scripts45EOF4647# 3. Start the services48docker compose up -d4950# 4. View logs51docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/k6/run | bashTroubleshooting
- k6 'connection refused' to target: Ensure target URLs are accessible from container network and not using localhost references
- InfluxDB 'database does not exist' error: Verify INFLUXDB_DB environment variable matches k6 output configuration database name
- Grafana shows no data sources: Check InfluxDB container is running and accessible on port 8086 before configuring data source
- k6 scripts fail with module errors: Ensure ES6 import/export syntax is used correctly and modules are in accessible paths
- High memory usage during tests: Reduce virtual user count or implement proper response body handling to prevent memory leaks
- InfluxDB disk space issues: Configure data retention policies to automatically remove old metrics data after specified time periods
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Ad Space
Shortcuts: C CopyF FavoriteD Download