Top Related Projects
Quick Overview
k6 is an open-source load testing tool and SaaS for engineering teams. It allows developers to test the performance of their APIs, microservices, and websites using JavaScript. k6 is designed to be developer-friendly, extensible, and capable of supporting various testing scenarios.
Pros
- Easy to use with a JavaScript-based scripting API
- Supports various protocols (HTTP/1.1, HTTP/2, WebSocket)
- Integrates well with CI/CD pipelines
- Provides detailed performance metrics and analysis
Cons
- Limited GUI for test creation and result visualization
- Steeper learning curve for non-developers
- Resource-intensive for large-scale tests on a single machine
- Limited built-in support for some specific protocols (e.g., gRPC)
Code Examples
- Basic HTTP GET request:
import http from 'k6/http';
import { check } from 'k6';
export default function () {
const res = http.get('https://test.k6.io');
check(res, { 'status was 200': (r) => r.status === 200 });
}
- Setting up test options:
export const options = {
vus: 10,
duration: '30s',
};
export default function () {
// Your test logic here
}
- Using checks and custom metrics:
import http from 'k6/http';
import { check, sleep } from 'k6';
import { Counter } from 'k6/metrics';
const myCounter = new Counter('my_counter');
export default function () {
const res = http.get('https://test.k6.io');
check(res, { 'status was 200': (r) => r.status === 200 });
myCounter.add(1);
sleep(1);
}
Getting Started
To get started with k6:
-
Install k6:
- On macOS:
brew install k6
- On Windows:
choco install k6
- On Linux: Follow the instructions at https://k6.io/docs/getting-started/installation
- On macOS:
-
Create a JavaScript file (e.g.,
script.js
) with your test logic:
import http from 'k6/http';
import { check } from 'k6';
export default function () {
const res = http.get('https://test.k6.io');
check(res, { 'status was 200': (r) => r.status === 200 });
}
- Run the test:
k6 run script.js
This will execute the test and display the results in your terminal.
Competitor Comparisons
Write scalable load tests in plain Python 🚗💨
Pros of Locust
- Python-based, making it accessible for developers familiar with the language
- Supports distributed load testing out of the box
- Highly customizable and extensible through Python scripts
Cons of Locust
- Generally slower performance compared to k6
- Limited reporting and visualization capabilities
- Lacks built-in support for certain protocols (e.g., gRPC)
Code Comparison
Locust example:
from locust import HttpUser, task, between
class WebsiteUser(HttpUser):
wait_time = between(1, 5)
@task
def index_page(self):
self.client.get("/")
k6 example:
import http from 'k6/http';
import { sleep } from 'k6';
export default function () {
http.get('http://test.k6.io');
sleep(1);
}
Both Locust and k6 are popular open-source load testing tools, but they differ in their approach and features. Locust is Python-based and offers great flexibility, while k6 is JavaScript-based and focuses on performance and developer-friendly scripting. The choice between them often depends on the specific requirements of the project and the team's expertise.
HTTP load testing tool and library. It's over 9000!
Pros of Vegeta
- Lightweight and fast, with minimal resource usage
- Simple CLI interface for quick and easy load testing
- Supports multiple output formats (JSON, CSV, Histogram)
Cons of Vegeta
- Limited scripting capabilities compared to k6
- Fewer built-in metrics and reporting options
- Less extensive documentation and community support
Code Comparison
Vegeta:
echo "GET http://example.com" | vegeta attack -duration=30s | vegeta report
k6:
import http from 'k6/http';
import { check } from 'k6';
export default function () {
let res = http.get('http://example.com');
check(res, { 'status is 200': (r) => r.status === 200 });
}
Vegeta focuses on simplicity and ease of use, making it ideal for quick load tests and simple scenarios. It excels in situations where minimal setup is required and raw performance is the primary concern.
k6, on the other hand, offers more advanced scripting capabilities and a wider range of features, making it suitable for complex testing scenarios and detailed performance analysis. It provides better integration with CI/CD pipelines and more comprehensive reporting options.
Both tools have their strengths, and the choice between them depends on the specific requirements of your load testing needs.
Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
Pros of JMeter
- Extensive GUI for test creation and analysis
- Wide range of built-in protocols and assertions
- Large community and extensive plugin ecosystem
Cons of JMeter
- Steeper learning curve for beginners
- Resource-intensive for large-scale tests
- Less developer-friendly for version control and CI/CD integration
Code Comparison
JMeter (XML-based):
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP Request" enabled="true">
<stringProp name="HTTPSampler.domain">example.com</stringProp>
<stringProp name="HTTPSampler.port">80</stringProp>
<stringProp name="HTTPSampler.protocol">http</stringProp>
<stringProp name="HTTPSampler.path">/api/users</stringProp>
</HTTPSamplerProxy>
k6 (JavaScript-based):
import http from 'k6/http';
export default function() {
http.get('http://example.com/api/users');
}
The code comparison highlights the difference in approach between JMeter's XML-based configuration and k6's JavaScript-based scripting. JMeter's XML format is more verbose and requires more setup, while k6's JavaScript approach is more concise and familiar to developers. This difference reflects k6's focus on developer-friendly, code-based testing compared to JMeter's GUI-centric approach.
Modern Load Testing as Code
Pros of Gatling
- Scala-based DSL allows for more complex and flexible test scenarios
- Built-in support for various protocols (HTTP, WebSocket, JMS, MQTT)
- Comprehensive reporting with detailed metrics and graphs
Cons of Gatling
- Steeper learning curve, especially for those unfamiliar with Scala
- Limited extensibility compared to k6's JavaScript ecosystem
- Resource-intensive for large-scale tests, potentially requiring more hardware
Code Comparison
Gatling:
scenario("My Scenario")
.exec(http("Request")
.get("/api/users")
.check(status.is(200)))
.pause(5)
k6:
http.get("http://test.k6.io");
check(res, {
"status is 200": (r) => r.status === 200,
});
sleep(5);
Both Gatling and k6 are powerful load testing tools, each with its own strengths. Gatling excels in complex scenarios and protocol support, while k6 offers a more accessible JavaScript-based approach with excellent extensibility. The choice between them often depends on the team's expertise, specific testing requirements, and infrastructure considerations.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Like unit testing, for performance
Modern load testing for developers and testers in the DevOps era.
Download · Documentation · Community Forum · Public Roadmap
k6 is a modern load-testing tool, built on our years of experience in the performance and testing industries. It's built to be powerful, extensible, and full-featured. The key design goal is to provide the best developer experience.
Its core features are:
- Configurable load generation. Even lower-end machines can simulate lots of traffic.
- Tests as code. Reuse scripts, modularize logic, version control, and integrate tests with your CI.
- A full-featured API. The scripting API is packed with features that help you simulate real application traffic.
- An embedded JavaScript engine. The performance of Go, the scripting familiarity of JavaScript.
- Multiple Protocol support. HTTP, WebSockets, gRPC, Browser, and more.
- Large extension ecosystem. You can extend k6 to support your needs. And many people have already shared their extensions with the community!
- Flexible metrics storage and visualization. Summary statistics or granular metrics, exported to the service of your choice.
- Native integration with Grafana cloud. SaaS solution for test execution, metrics correlation, data analysis, and more.
This is what load testing looks like in the 21st century.
Example script
import http from "k6/http";
import { check, sleep } from "k6";
// Test configuration
export const options = {
thresholds: {
// Assert that 99% of requests finish within 3000ms.
http_req_duration: ["p(99) < 3000"],
},
// Ramp the number of virtual users up and down
stages: [
{ duration: "30s", target: 15 },
{ duration: "1m", target: 15 },
{ duration: "20s", target: 0 },
],
};
// Simulated user behavior
export default function () {
let res = http.get("https://test-api.k6.io/public/crocodiles/1/");
// Validate response status
check(res, { "status was 200": (r) => r.status == 200 });
sleep(1);
}
You can run scripts like this on the CLI, or in your CI, or across a Kubernetes cluster.
Documentation
The docs cover all aspects of using k6. Some highlights include:
- Get Started. Install, run a test, inspect results.
- HTTP requests. Have your virtual users use HTTP methods. Or, check the other Protocols.
- Thresholds. Set goals for your test, and codify your SLOs.
- Options. Configure your load, duration, TLS certificates, and much, much more.
- Scenarios. Choose how to model your workload: open models, closed models, constant RPS, fixed iterations, and more.
- Results output. Study, filter, and export your test results.
- JavaScript API. Reference and examples of all k6 modules.
- Extensions. Extend k6 for new protocols and use cases.
These links barely scratch the surface! If you're looking for conceptual information, you can read about Test types, Test strategies, or one of the many informative Blog posts.
Roadmap
Our team is dedicated to continuously improving and providing the best user experience possible. The public roadmap covers user-oriented features, UX improvements and JavaScript support that our team will focus on. Remember that timeframes and priorities may shift, but we believe it's important to share our vision.
We hope it provides a clear overview of our plans for future development. We welcome feedback, corrections, and suggestions via GitHub to make it more comprehensive, accessible, and valuable for the community.
It's worth mentioning that we consider upvotes (thumbs-up) to be one of the essential metrics for determining community needs. If you want to show us the importance of a feature, please give it a thumbs-up.
Contribute
If you want to contribute or help with the development of k6, start by reading CONTRIBUTING.md. Before you start coding, it might be a good idea to first discuss your plans and implementation details with the k6 maintainersâespecially when it comes to big changes and features. You can do this in the GitHub issue for the problem you're solving (create one if it doesn't exist).
Note: To disclose security issues, refer to SECURITY.md.
Support
To get help, report bugs, suggest features, and discuss k6 with others, refer to SUPPORT.md.
License
k6 is distributed under the AGPL-3.0 license.
Top Related Projects
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot