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
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