Giter Site home page Giter Site logo

fagun18 / performance-testing-with-k6 Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 57 KB

Performance Testing with k6 I've been exploring performance testing with k6, a powerful tool for load testing and performance monitoring

Home Page: https://www.linkedin.com/in/mejbaur/

License: MIT License

JavaScript 100.00%
k6 load-testing mejbaur-bahar-fagun open-source performance-testing soak-testing software-tester software-testing spike-testing sqa stress-testing testing-tools

performance-testing-with-k6's Introduction

Performance Testing with k6

K6

When it comes to performance testing, JMeter has long been a popular choice. However, k6, an open-source load testing tool introduced in 2017, offers a compelling alternative with its efficiency and ease of use.

K6

Why k6?

  • Written in Go: k6 is built on Go, which prioritizes performance, making it highly efficient.
  • Easy Load Generation: A single instance of k6 can handle thousands of virtual users on a single machine, simplifying load distribution.
  • Protocol Support: k6 supports various protocols including HTTP/1.1, HTTP/2, WebSockets, gRPC, and SOAP/REST webservices.

Getting Started

Installation

To start using k6, install it based on your operating system:

  • Linux:
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6
  • MAC OS:
brew install k6
  • Windows:

If you use the Chocolatey package manager you can install the unofficial k6 package with:

choco install k6

If you use the Windows Package Manager, install the official packages from the k6 manifests (created by the community):

winget install k6 --source winget

For other installation options, refer to the k6 downloads page.

Writing Your First k6 Load Test

  1. Set Up: Install Visual Studio Code for creating JavaScript/TypeScript-based tests.
  2. Creating a Load Test: Begin by writing a simple k6 load test & save it as name : k6-Fagun.js
import http from "k6/http";

export default function () {
  http.get("https://test-api.k6.io/public/crocodiles/");
}

Or Clone this Respiratory

Installation

  1. Clone the repository:
    git clone https://github.com/fagun18/Performance-Testing-with-k6.git
  • Navigate to the project directory:
cd Performance-Testing-with-k6

Running the Test

Execute the test using the terminal command k6

k6 run k6-Fagun.js

Enhancing Load Tests

  • Adding Thresholds: Define acceptance criteria using thresholds to specify acceptable request durations or failure rates.
  • Adding Virtual Users: Configure the number of virtual users (vus) and duration to apply load.
import http from "k6/http";

export const options = {
  thresholds: {
    http_req_duration: ["p(95)<150"],
  },
  vus: 10,
  duration: "10s",
};

export default function () {
  http.get("https://test-api.k6.io/public/crocodiles/");
}

Generating HTML Reports

  • To generate HTML reports, leverage the k6-reporter library.
import http from "k6/http";
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";

export const options = {
  thresholds: {
    http_req_duration: ["p(95)<150"],
  },
  vus: 10,
  duration: "10s",
};

export default function () {
  http.get("https://test-api.k6.io/public/crocodiles/");
}

export function handleSummary(data) {
  return {
    "summary.html": htmlReport(data),
  };
}

Generating Both HTML Simple & Advanced Reports

  • To generate HTML reports, leverage the k6-reporter library.
import http from "k6/http";
import { htmlReport } from "https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js";
import { textSummary } from "https://jslib.k6.io/k6-summary/0.0.1/index.js";

export const options = {
    thresholds: {
        http_req_duration: ["p(95)<150"],
    },
    vus: 10,
    duration: "10s",
};

export default function () {
    http.get("https://fagun.com");
}

export function handleSummary(data) {
    return {
        "summary.html": htmlReport(data),
        "summary.txt": textSummary(data, { indent: " ", enableColors: true }),
    };
}

Viewing the Report

  • After running the test, locate the summary.html file in the root directory and open it in a web browser to view the detailed report.

License

All Copyright Goes to K6

Follow Me

LinkedIn Facebook YouTube Twitter Website Medium

Mejbaur Bahar Fagun
Mejbaur Bahar Fagun
Product Acceptance Engineer (L2) @ DEVxHUB | ๐Ÿฅธ Lead SQA and ๐Ÿž Security Analysts ๐Ÿ› Bug Bounty ๐Ÿ‘ป DevSecOps

performance-testing-with-k6's People

Contributors

fagun18 avatar

Stargazers

 avatar Andi maryono avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.