SlideShare a Scribd company logo
1 of 18
Download to read offline
Load Tests as JavaScript Code
Load Testing with K6 Framework
Software University
https://softuni.bg
Svetlin Nakov, PhD
Technical Trainer and Inspirer
Co-Founder @ SoftUni
https://softuni.org
 Software engineer, trainer, entrepreneur,
inspirer, PhD, author of 15+ technical books
 3 successful tech educational initiatives (150,000+ students)
About Dr. Svetlin Nakov
2
Overview
Performance Testing
3
 Performance testing
 Determine whether software meets speed, scalability and
stability requirements under expected workloads
 Load testing & stress testing tools
 Record scenarios (e. g. login  place an order  logout)
 Execute the scenarios with multiple virtual users (e. g. 200 users)
 Tools can be configuration-driven (JMeter, LoadRunner) or
code-driven (k6, Locust, Gatling)
Performance Testing: Overview
4
 Load testing
 Examine the performance for a specific expected load
 E. g. run a scenario with 200 users in parallel for 5 minutes
 Expect the average load time < 500 ms
 Stress testing
 Test app stability when running under extreme conditions
 Goal: understand at which level the app can crash
 E. g. 5K users for 3 minutes  check how many succeed
Performance Testing: Types
5
"K6" Load Testing Tool
Code-Based Performance Testing
 k6 is modern, open-source load testing tool – https://k6.io
 Testing framework based on JavaScript (very powerful)
 Local & cloud script executor based on Go (high performance)
 Script recorder (Chrome plugin)  generates JS code
 Tests are plain JavaScript code
 No XML configuration, no need for complex UI
 Very powerful: JavaScript can test anything
 Easy to use with continuous integration scripts
K6 Load Testing Tool
7
 Installing k6 console app:
 https://github.com/loadimpact/k6/releases
 Simple testing script:
 Running the script (just once)
K6: Install and Run
k6 run simple.js
import http from 'k6/http';
export default function () {
http.get('https://nakov-mvc-node-app.herokuapp.com');
}
simple.js
8
K6: Script Execution
9
 Load test: 50 virtual users for 15 seconds:
 Stress test: 3000 virtual users for 30 seconds:
 Note this will flood most Web apps
 Unless a DoS protection is implemented
 Warning: flooding web apps (which you do not own) might be
illegal in some countries!
K6: Load Testing and Stress Testing
k6 --vus 50 --duration 15s run simple.js
k6 --vus 3000 --duration 30s run simple.js
10
 k6 has test recorder (Chrome plugin)
 Record testing scenarios (HTTP
requests) from the Web browser
 Generates HTTP archives (HAR files)
 Edit the recorded scripts at k6 cloud
 Edit the scenarios in a visual editor
 Or edit the JavaScript code behind
 https://app.k6.io – free limited access
K6 Test Recorder
11
The K6 Cloud
12
 Users in the real world behave like this:
 Open a page  wait  open another page  wait  fill a form
 submit the form  wait  open another page  …
Writing K6 Scripts for Real-World Scenarios
http.get("https://nakov-mvc-node-app.herokuapp.com/");
sleep(2);
http.get("https://nakov-mvc-node-app.herokuapp.com/students");
sleep(3);
http.get("https://nakov-mvc-node-app.herokuapp.com/add-student");
sleep(3);
let body = { name: "New student" + uniqueNum, email: "new@gmail.com" };
http.post("https://nakov-mvc-node-app.herokuapp.com/add-student", body);
sleep(2);
13
 Checks are like assertions in unit testing:
K6: Checks
import { check } from "k6";
import http from "k6/http";
export default function() {
let res = http.get("https://nakov-mvc-node-app.herokuapp.com/");
check(res, {
'HTTP status == 200': res => res.status == 200,
'Page heading': res =>
res.body.includes('<h1>Students Registry</h1>')
});
}
14
 Thresholds define pass / fail criteria for the test
K6: Thresholds
export let options = {
thresholds: {
// 95% of requests must finish within 500 ms & 99% within 1500 ms
http_req_duration: ['p(95) < 500', 'p(99) < 1500'],
},
};
export default function performanceTest() {
…
}
15
 Sample performance testing scenario for the "Students Registry"
app: https://nakov-mvc-node-app.herokuapp.com
1. Open the [Home] page & wait 2 secs
2. Open the [Students] page & wait 3 secs
3. Open the [Add Students] page & wait 3 secs
4. Submit the [Add Students] form & wait 2 secs
 Code: https://gist.github.com/nakov/79f5e28a8b8c91f73c26eb55a89d80bc
K6: Testing Script with Waits Example
16
k6 --vus 200 --duration 10s run load-test-with-waits.js
 Run k6 with
5000 virtual
users for 20
secs and see
the results:
K6: Full Performance Testing Script Example
17
© SoftUni – https://softuni.org

More Related Content

Similar to load-testing-with-k6-nakov-at-qa-challenge-accepted-oct-2021-211002181104.pdf

LoadUI web performance testing tool
LoadUI web performance testing toolLoadUI web performance testing tool
LoadUI web performance testing toolMilind Rupchandani
 
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...Vadym Kazulkin
 
Jenkins days workshop pipelines - Eric Long
Jenkins days workshop  pipelines - Eric LongJenkins days workshop  pipelines - Eric Long
Jenkins days workshop pipelines - Eric Longericlongtx
 
JCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop LabsJCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop LabsSimon Su
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applicationsqooxdoo
 
Oracle appsloadtestbestpractices
Oracle appsloadtestbestpracticesOracle appsloadtestbestpractices
Oracle appsloadtestbestpracticessonusaini69
 
Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments Pavel Kaminsky
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsYakov Fain
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code維佋 唐
 
Load impact insights webinar
Load impact insights webinarLoad impact insights webinar
Load impact insights webinarJohn Emmitt
 
JavaScript development methodology
JavaScript development methodologyJavaScript development methodology
JavaScript development methodologyAleksander Fabijan
 
Selenium RC, Selenium WebDriver and HP LoadRunner
Selenium RC, Selenium WebDriver and HP LoadRunnerSelenium RC, Selenium WebDriver and HP LoadRunner
Selenium RC, Selenium WebDriver and HP LoadRunnerMurageppa-QA
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3kognate
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extremeyinonavraham
 
Gatling Performance Workshop
Gatling Performance WorkshopGatling Performance Workshop
Gatling Performance WorkshopSai Krishna
 
Cloud-native applications with Java and Kubernetes - Yehor Volkov
 Cloud-native applications with Java and Kubernetes - Yehor Volkov Cloud-native applications with Java and Kubernetes - Yehor Volkov
Cloud-native applications with Java and Kubernetes - Yehor VolkovKuberton
 
Jenkins Days - Workshop - Let's Build a Pipeline - Los Angeles
Jenkins Days - Workshop - Let's Build a Pipeline - Los AngelesJenkins Days - Workshop - Let's Build a Pipeline - Los Angeles
Jenkins Days - Workshop - Let's Build a Pipeline - Los AngelesAndy Pemberton
 
From Web App Model Design to Production with Wakanda
From Web App Model Design to Production with WakandaFrom Web App Model Design to Production with Wakanda
From Web App Model Design to Production with WakandaAlexandre Morgaut
 
Web Applications with Eclipse RT and Docker in the Cloud
Web Applications with Eclipse RT and Docker in the CloudWeb Applications with Eclipse RT and Docker in the Cloud
Web Applications with Eclipse RT and Docker in the CloudMarkus Knauer
 

Similar to load-testing-with-k6-nakov-at-qa-challenge-accepted-oct-2021-211002181104.pdf (20)

LoadUI web performance testing tool
LoadUI web performance testing toolLoadUI web performance testing tool
LoadUI web performance testing tool
 
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
 
Jenkins days workshop pipelines - Eric Long
Jenkins days workshop  pipelines - Eric LongJenkins days workshop  pipelines - Eric Long
Jenkins days workshop pipelines - Eric Long
 
JCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop LabsJCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop Labs
 
Lesson 2
Lesson 2Lesson 2
Lesson 2
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applications
 
Oracle appsloadtestbestpractices
Oracle appsloadtestbestpracticesOracle appsloadtestbestpractices
Oracle appsloadtestbestpractices
 
Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot apps
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
Load impact insights webinar
Load impact insights webinarLoad impact insights webinar
Load impact insights webinar
 
JavaScript development methodology
JavaScript development methodologyJavaScript development methodology
JavaScript development methodology
 
Selenium RC, Selenium WebDriver and HP LoadRunner
Selenium RC, Selenium WebDriver and HP LoadRunnerSelenium RC, Selenium WebDriver and HP LoadRunner
Selenium RC, Selenium WebDriver and HP LoadRunner
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extreme
 
Gatling Performance Workshop
Gatling Performance WorkshopGatling Performance Workshop
Gatling Performance Workshop
 
Cloud-native applications with Java and Kubernetes - Yehor Volkov
 Cloud-native applications with Java and Kubernetes - Yehor Volkov Cloud-native applications with Java and Kubernetes - Yehor Volkov
Cloud-native applications with Java and Kubernetes - Yehor Volkov
 
Jenkins Days - Workshop - Let's Build a Pipeline - Los Angeles
Jenkins Days - Workshop - Let's Build a Pipeline - Los AngelesJenkins Days - Workshop - Let's Build a Pipeline - Los Angeles
Jenkins Days - Workshop - Let's Build a Pipeline - Los Angeles
 
From Web App Model Design to Production with Wakanda
From Web App Model Design to Production with WakandaFrom Web App Model Design to Production with Wakanda
From Web App Model Design to Production with Wakanda
 
Web Applications with Eclipse RT and Docker in the Cloud
Web Applications with Eclipse RT and Docker in the CloudWeb Applications with Eclipse RT and Docker in the Cloud
Web Applications with Eclipse RT and Docker in the Cloud
 

Recently uploaded

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 

load-testing-with-k6-nakov-at-qa-challenge-accepted-oct-2021-211002181104.pdf

  • 1. Load Tests as JavaScript Code Load Testing with K6 Framework Software University https://softuni.bg Svetlin Nakov, PhD Technical Trainer and Inspirer Co-Founder @ SoftUni https://softuni.org
  • 2.  Software engineer, trainer, entrepreneur, inspirer, PhD, author of 15+ technical books  3 successful tech educational initiatives (150,000+ students) About Dr. Svetlin Nakov 2
  • 4.  Performance testing  Determine whether software meets speed, scalability and stability requirements under expected workloads  Load testing & stress testing tools  Record scenarios (e. g. login  place an order  logout)  Execute the scenarios with multiple virtual users (e. g. 200 users)  Tools can be configuration-driven (JMeter, LoadRunner) or code-driven (k6, Locust, Gatling) Performance Testing: Overview 4
  • 5.  Load testing  Examine the performance for a specific expected load  E. g. run a scenario with 200 users in parallel for 5 minutes  Expect the average load time < 500 ms  Stress testing  Test app stability when running under extreme conditions  Goal: understand at which level the app can crash  E. g. 5K users for 3 minutes  check how many succeed Performance Testing: Types 5
  • 6. "K6" Load Testing Tool Code-Based Performance Testing
  • 7.  k6 is modern, open-source load testing tool – https://k6.io  Testing framework based on JavaScript (very powerful)  Local & cloud script executor based on Go (high performance)  Script recorder (Chrome plugin)  generates JS code  Tests are plain JavaScript code  No XML configuration, no need for complex UI  Very powerful: JavaScript can test anything  Easy to use with continuous integration scripts K6 Load Testing Tool 7
  • 8.  Installing k6 console app:  https://github.com/loadimpact/k6/releases  Simple testing script:  Running the script (just once) K6: Install and Run k6 run simple.js import http from 'k6/http'; export default function () { http.get('https://nakov-mvc-node-app.herokuapp.com'); } simple.js 8
  • 10.  Load test: 50 virtual users for 15 seconds:  Stress test: 3000 virtual users for 30 seconds:  Note this will flood most Web apps  Unless a DoS protection is implemented  Warning: flooding web apps (which you do not own) might be illegal in some countries! K6: Load Testing and Stress Testing k6 --vus 50 --duration 15s run simple.js k6 --vus 3000 --duration 30s run simple.js 10
  • 11.  k6 has test recorder (Chrome plugin)  Record testing scenarios (HTTP requests) from the Web browser  Generates HTTP archives (HAR files)  Edit the recorded scripts at k6 cloud  Edit the scenarios in a visual editor  Or edit the JavaScript code behind  https://app.k6.io – free limited access K6 Test Recorder 11
  • 13.  Users in the real world behave like this:  Open a page  wait  open another page  wait  fill a form  submit the form  wait  open another page  … Writing K6 Scripts for Real-World Scenarios http.get("https://nakov-mvc-node-app.herokuapp.com/"); sleep(2); http.get("https://nakov-mvc-node-app.herokuapp.com/students"); sleep(3); http.get("https://nakov-mvc-node-app.herokuapp.com/add-student"); sleep(3); let body = { name: "New student" + uniqueNum, email: "new@gmail.com" }; http.post("https://nakov-mvc-node-app.herokuapp.com/add-student", body); sleep(2); 13
  • 14.  Checks are like assertions in unit testing: K6: Checks import { check } from "k6"; import http from "k6/http"; export default function() { let res = http.get("https://nakov-mvc-node-app.herokuapp.com/"); check(res, { 'HTTP status == 200': res => res.status == 200, 'Page heading': res => res.body.includes('<h1>Students Registry</h1>') }); } 14
  • 15.  Thresholds define pass / fail criteria for the test K6: Thresholds export let options = { thresholds: { // 95% of requests must finish within 500 ms & 99% within 1500 ms http_req_duration: ['p(95) < 500', 'p(99) < 1500'], }, }; export default function performanceTest() { … } 15
  • 16.  Sample performance testing scenario for the "Students Registry" app: https://nakov-mvc-node-app.herokuapp.com 1. Open the [Home] page & wait 2 secs 2. Open the [Students] page & wait 3 secs 3. Open the [Add Students] page & wait 3 secs 4. Submit the [Add Students] form & wait 2 secs  Code: https://gist.github.com/nakov/79f5e28a8b8c91f73c26eb55a89d80bc K6: Testing Script with Waits Example 16 k6 --vus 200 --duration 10s run load-test-with-waits.js
  • 17.  Run k6 with 5000 virtual users for 20 secs and see the results: K6: Full Performance Testing Script Example 17
  • 18. © SoftUni – https://softuni.org