Performance test using k6
Kashif Mehmood
Terraform Certified | Kubernetes Certified Administrator | Kubernetes Application Developer| AWS Solution Architect | Cloud Infrastructure (AWS ,GCP) and on-premises
K6 is a popular open-source load testing tool designed for developers and DevOps teams to create and execute performance , load tests to simulate user traffic, API requests, and other types of network activity. K6 offers a user-friendly, scriptable interface that allows you to write and execute load tests with simplicity.
K6 has offers high level of customization, real-time metrics,distributed testing,multiple protocols.It has very strong documentation . K6 is used by a variety of organizations and individuals, including developers, testers, DevOps engineers,?and site reliability engineers, to help ensure their applications and systems can handle high levels of traffic and activity without performance degradation or downtime.?
Organization who need high-performance, reliable, and scalable web applications or APIs must use k6
Here is a very simple code to test my localhost application login behavior with 50 users
import http from 'k6/http'
import { check, sleep } from 'k6';
export let options = {
?vus: 50,?????????????????????? ?// number of virtual users
?duration: '5m',????????????// duration for which virtual users can send reuqest
?thresholds: {
??http_req_duration: ['p(90)<5000'],??????// 90 % request should pass within 5 sec
??http_req_failed: ['rate<0.1'],??????????????// only 10 % request can fail
?},};
export default function () {
?let res = http.post('https://localhost/login', {???????//application url
??email: '[email protected]',??????????????? ?//login username?
??password: 'password123',???????????????? ?//login password
?});
?check(res, { 'status was 200': (r) => r.status == 200 }); //check response code
?sleep(1);???????????????????????? ? //sleep for 1 sec
};
?
You can run the test like?
k6 run Applicationlogin.js???//Applicationlogin is the name of file where you wrote the above test
How store results?
you can use influx plugin with grafana to store the results.if you have already installed/configure influx?
you can run "k6 run --out influxdb=influxURL Applicationlogin.js"?to store the performance and loadtest results in influxdb and display them using grafana