Giter Site home page Giter Site logo

k6-loadtest's Introduction

K6 Load Test Example

This repository demonstrates an example of k6 Load tester which implements Smoke, Load, Stress and Soak tests scenarios on an AUT(Application Under Test). Additionally it stores the results in Influxdb an could be visualized in Grafana.

Prerequisites

  • npm
  • python 3.6+
  • Docker

Installation

Application under test

The AUT example is https://github.com/testdrivenio/flask-vue-crud which uses a flask application as server and vueJs as client. Clone, install and setup the requirements just as the readme guideline. You should be able to see the app on http://localhost:8080.

Install k6

Follow the instructions provided in https://k6.io/docs/getting-started/installation/ or for Ubuntu distributions:

sudo apt-get update && sudo apt-get install ca-certificates gnupg2 -y
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
$ echo "deb 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

Setup Influx and Grafana

  1. Up the docker-compose.yaml file with:
docker-compose -d up

You should be able to see Grafana dashboard on http://localhost:3000

Its default username and password is: admin

  1. Create a data source with below configurations:

influx-config

  1. Import the pre-configured Exa dashboard by id: 15080 or by the link

Now everything is ready to get the test.

Run the test

  1. Clone the repository

  2. change directory to files:

cd files

Run k6 with the desired test mode. Wait for the test to get accomplished.

k6 run -e test_mode=smoke --out influxdb=http://localhost:8086/myk6db test.js

You can choose the test_mode value according to the below options.

  • smoke: Targets the functionality of the system under the lowest load: Is it working with only one user?

  • load: Targets the system under normal usage by the users. You should ask: How many users are using the system simultaneously typically and how long is their session?

  • stress: What is the maximum capacity of the system? How many users with what kind of behavior should use the site to disrate its quality due to the SLO: i.e. availability, request latency, throughput and etc.

  • soak: Would the system last for a long time(normally hours to days) under normal conditions? It’s working for 15min under normal condition in the load test but is feasible for a much longer time?

  1. Now you can get back to the imported grafana dashboard and see the results.

results

Running k6 with Docker

You can use the k6 official docker image to run the tests. This is a practical approach specially for CI/CD purposes like run the tests with cronjob. The Dockerfile in the root of the repository will do that for you. Furthermore, you can use it in docker-compose along with other containers by commenting out the k6-tester service.

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.