Introduction to K6 Performance Testing Tool | Installation of K6 | Run K6 Load Test | Littles Law

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi hello wanna come and welcome back to yet another episode on literal's Law YouTube channel so in our little fly YouTube channel we have discussed about laundry tools like jmeter newload and load Runner so in this series of videos we are going to see about k6 the latest load testing tool in the market which has created huge waves in testing the apis so we will see from Step from the for the beginners who are interested to learn and for those who are in intermediate I can help you with more Advanced Techniques with k6 so before we move on to the installation so I will tell you what is k6 okay 6 is an open source load testing tool which is focused on Simplicity and ease of use and this allows us to write performance test in JavaScript so some a few things about k6s it is a JavaScript based testing so the tests are written in JavaScript and this allows us to easily script complex scenarios and leverage JavaScript libraries since JavaScript libraries are very huge in numbers so we can leverage the support of JavaScript libraries and the second thing is the scenario based testing so we can Define scenarios that simulate different user behaviors such as browsing purchasing Etc CLI driven so k6 can be run from command line which makes it easy to automate test in continuous integration pipelines and the last thing is the metrics and outputs so k6 provides detailed performance metrics during and after the test which can be used for analysis this is and Reporting so now with no further due let's go to the installation so if you are using a Windows machine make sure you have installed the chocolaty package manager and once you install a Security package manager you can install any supporting tools like what you do in the Linux so first let me type the charcoal install k6 and this will ask for Sr no to continue so I'm typing y the s so now the installation has started so this will so this has now okay let me change it to the admin mode let me exit this one and let me open partial in admin mode because that will give me enough privileges to install so let me again go back and type charcoal install k6 so this has given me the additional privileges of installing the chocolate in my mission sorry the k6 so k6 is installed now so let's now move on to the next steps so now we have completed our installation and now we will create a simple local script to do a testing so this is basically testing a https URL and to test that we will have to import the HTTP from k6 http colon and then again I'm going to import sleep from k6 then I'm going to close it with the k6 the semicolon and then I'm going to export the default function and now I'm going to get the function of this is going to be a get function and the URL is the pet store URL so this is going to be a get function and I'm closing this with a semicolon and then I'm going to wait I'm going to add a sleep time of one second so that is how I'm going to save so now I'm going to save this inside C drive version k6 folder and this is going to be my first test script dot j so we have to say since I told you in the very beginning so this has to be saved as a Javascript file so I'm just saving this as a js1 so this is going to be test script.js and I'm going to save this so what did I do is so the first line is I'm going to import HTTP from k6 HTTP and then I'm going to import the Sleep which I'm using this in this statement so this is a sleep command and then I'm going to export the default function so here you can see I'm going to I'm testing or I'm hitting a request which is a basically a get request and I've saved it and let's now go to the partial so how to execute the test so let me just maximize the command the partial command so here now I'm in C drive so the command to run this in the CLI mode is to run k6 run test script Dot Js so here you can see the file could not be found so as I told you the file is not in this particular location and it is in a different location so we have to CD into that directory and then we have to run the command zones you run the command automatically you can see here the k6 dot IO image with the scenarios I have got one scenario with one visual user and it has got 10 m a 10 minute and 30 seconds of Max duration and also we can see the entire data the data received the data sent the HTTP request blocked HTTP request is correcting so every metric you can see it in this line here so this is completed so there are like zero of one which will use it's completed so with that we have executed our first test so in case if I want to add more users what can I do so in that scenario I have to run the following command which is k6 run minus minus v u so for this example I'm going to run 20 users and what about the duration so this we normally in any tool we give the duration in the the thread group or in the test duration or in the controller so here we can give directly in the command line so I'm going to run this test for one minute and what is the script so it is going to be the test script.js so the syntax goes like this so we have to start with with it with KS run and then the number of visual users the duration and then finally the test script which you're going to run and when I click enter here you can see the test is still running just minimize it for you let me drag down so still the test is running so let's wait for some more seconds so the test to complete so we have to wait until the test is completed let's wait for a few more seconds or else I can just yeah so here you can see the test is running and so far we have crossed 30 seconds and the test is running fine totally we have got 600 hits since we have a very less sleeping time so as you can see here it's just one less than milliseconds so it is not going to stop anything and here you can see there are already there are like 900 so in case if you want to so here you can see there the request has been failed because we have sent lot of requests with within a less pan of time like 20 users with these many requests will actually create lot of request to the user and here you can see we have got one one four zero requests that has got that has been hit so in case if I want to increase the theme time I can add it in description for example here I can even add it like 20 or 50 and then if I run the command again so let me run the command again so previously we had around 1000 hits and let's see how much hits does we do we get in this particular test because we have increased the sleep time to 50. let's wait for few more seconds to see at which point of time do we get the first hit because since we have increased the sleeping time which is basically they think time in any other tool so we have got the first hit which is 20 users hit because the 50 the number 50 we gave is which is around the 50 seconds so the time that we give in this test or in this sleeping time is basically calculated in seconds and not in milliseconds so we have got a one minute of test and in that we have got 50 seconds to be waited so that's how why we have got the first hit after the 50th second so it looks like this the test has completed now and we have got 20 hits so in case if you really want to increase or decrease throughput we can play with the think time so there is another option in case in instead of running the entire code like this where you enter the code with let me just show you here so here we have Korea so instead of giving the users the virtual users in this line here and the duration we can even bring that in the code so how can we bring that in the code like how can we implement the option of adding the code yes so here let me add the code for that so here you have to add another option which is constant options equal to then open and close braces and inside this I'm going to give the visual users so in this scenario I'm going to give 50 users adding a comma and then the next line I'm going to give the duration which is 60 Seconds so with that we have added the duration of the test and also the virtual users and previously we had the get request and the Sleep option so I'm not going to make any changes to it so this way we can add instead of adding it in the command line we can add them here and the duration here so that the next time when we want to run a test we do not want to give the visual users here so instead what we can do is just type KS run and test script.js so this will start the test so we have got 50 virtual users and we will have to wait for the 20 seconds of think time and then we will get the first hit as per the testing so so far we have discussed about the installation how to create our first JavaScript file where we have hit the request using the get request and also we have tested the file with different level of visual users and different user duration and also with different thing times so in our next video we will see how to ramp up the visual users and how to use the other KS Resources with different examples so until then it's bye bye from Vasan chanmugam and Little's law
Info
Channel: Littles Law
Views: 2,594
Rating: undefined out of 5
Keywords:
Id: wEb4Qzleejg
Channel Id: undefined
Length: 12min 50sec (770 seconds)
Published: Mon Sep 25 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.