Introduction to K6 – Performance Testing

Tram Ho

What is Performance Testing?

Have you ever wanted to see the quality and load capacity of your products but you didn’t know how? Or do you have an API or a certain feature that when you request with Postman, it’s still good, but when you put it into operation, it crashes continuously or it takes a long time to load, making the user experience bad?

So let’s learn about Performance Testing and tools to do it.

Performance Testing is a testing technique to determine the bandwidth, processing capacity, scalability, or generally the performance of the system under the workload defined by the work. The results of performance testing serve to investigate, measure and evaluate the real performance of the system. There are common types such as:

Along with that, there are also many supporting tools such as Jmeter, Grinder, Artillery, LoadComplete, … But here, let’s learn about K6 .

Install K6?

K6 supports packages for Linux, Mac and Windows operating systems. Alternatively, you can use Docker.

Linux

Debian/Ubuntu

Fedora/CentOS

Use dnf or yum on older versions

Mac

Using Homebrew

Windows

Here I use Chocolatey package manager , you can install it in the following way:

Docker

To check for success, run the command:

Performance Testing with K6

With k6, you need to know 2 concepts: Virtual Users – VUs (you can set the number of virtual users to access simultaneously on your product) and Duration – a string that specifies the duration of the testing process. take place.

To create and Run a Test on K6 is quite simple because K6 uses Javascript to run the test, so it is quite familiar to us. A simple js file used in testing with k6 would look like this:

Or you can add multiple VUs and Duration as follows:

Or you can increase or decrease the number of VUs during the Test:

Now let’s create the test.js file with the above Config and run it with this command to see the results (Here I use docker):

And here is the End of test result:

The results are available and let’s analyze what the metrics in the End of test have:

Each http_req parameter has indexes avg, min, max, med, p(90), p(95).

  • Check (check) is the successful check rate.
  • Response time (http_req_duration) is the total time for the request. It is equal to http_req_sending + http_req_waiting + http_req_receiving.
  • Request rate (http_reqs) is the total number of HTTP k6 requests made.
  • Failed request (http_req_failed) is the percentage of failed requests according to setResponseCallback.
  • Connecting (http_req_connecting) is the time it takes to establish a TCP connection with the server.
  • TLS handshake (http_req_tls_handshaking) is the TLS session handshake time with the server.
  • Data sent (data_sent) is the amount of data sent. Track data for an individual URL to track data for an individual URL.
  • Data received (data_received) is the amount of data received.
  • Receiving (http_req_receiving) is the time it takes to receive the response data from the server.
  • Sending (http_req_sending) is the time it takes to send response data from the server.
  • Block (http_req_blocked) time blocked (waiting for a free TCP connection) before starting the request.
  • Waiting (http_req_waiting) is the time to wait for a response from the server.
  • Iteration duration (iteration_duration) is the time it takes to complete a full iteration, including time spent on initialization and destruction.
  • Iteration (iterations) is the total number of times VUs execute the default function.
  • VUs (vus) is the number of active users.
  • VUs max (vus_max) is the maximum number of VUs.

If you don’t want to manually code the Config file with Javascript as above, you can also use cloud K6 to test it, very convenient. Please click here to experience it. (Note that the Free version will have many different limitations, but is it better than not, guys :v)

Summary:

So I gave you a basic introduction to Performance Testing and how to use K6. Hope to help everyone in some way in the process of learning about Performance Testing. In the next part, I will continue to share more about K6.

References: https://k6.io/

Share the news now

Source : Viblo