Hey @codebien,
Thank you for the reply. I have read about the load test thoroughly. The documentation describes the different types of tests with examples, and it is easy to understand. Let me know if I am missing anything though.
I have generated a simple script from the k6 website:
import { sleep, check, group } from 'k6';
import http from 'k6/http';
export const options = {
stages: [
{ target: 50, duration: '1m' }, // 50 virtual users (VUs)
{ target: 50, duration: '3m' },
{ target: 0, duration: '1m' },
],
thresholds: {
// Requirement to pass the tests
http_req_duration: [
'p(95)<3000', // 95% of response times must be below 3s
// { threshold: "p(95)>=5000", abortOnFail: true },
// ],
http_req_failed: [
'rate<0.01', // Error rate should be less than 1%
{ threshold: "rate>=0.05", abortOnFail: true },
],
},
};
export default function main() {
let response;
group( 'Homepage group', function () {
// Homepage
response = http.get( 'https://example.com/' );
check( response, {
'status equals 200': ( response ) => response.status.toString() === '200',
'body contains My website': (
response
) =>
response.body.includes(
'My website'
),
} );
sleep( 3 );
} );
group( 'abc page', function () {
// abc page
response = http.get( 'https://example.com/abc' );
check( response, {
'status equals 200': ( response ) => response.status.toString() === '200',
'body contains abc page': ( response ) =>
response.body.includes( 'abc page' ),
} );
sleep( 2 );
} );
group( 'Blog page', function () {
// Blog
response = http.get( 'https://example.com/blog' );
check( response, {
'status equals 200': ( response ) => response.status.toString() === '200',
'body contains blog title': ( response ) =>
response.body.includes( 'blog title' ),
} );
sleep( 2 );
} );
}
I have ran the tests from my local machine. The 95% response time is 8.51s (I probably noted “max”), here is the result.
checks.........................: 100.00% ✓ 3408 ✗ 0
data_received..................: 214 MB 705 kB/s
data_sent......................: 651 kB 2.1 kB/s
group_duration.................: avg=7.27s min=3.14s med=7.36s max=15.36s p(90)=10.71s p(95)=11.53s
http_req_blocked...............: avg=13.2ms min=0s med=1µs max=1.82s p(90)=2µs p(95)=2µs
http_req_connecting............: avg=6.59ms min=0s med=0s max=1.24s p(90)=0s p(95)=0s
✗ http_req_duration..............: avg=3.68s min=235.32ms med=3.45s max=12.36s p(90)=7.65s p(95)=8.51s
{ expected_response:true }...: avg=3.68s min=235.32ms med=3.45s max=12.36s p(90)=7.65s p(95)=8.51s
✓ http_req_failed................: 0.00% ✓ 0 ✗ 2272
http_req_receiving.............: avg=440.4ms min=27µs med=502.04ms max=3.29s p(90)=791.97ms p(95)=1.21s
http_req_sending...............: avg=195.33µs min=23µs med=164µs max=1.67ms p(90)=341.9µs p(95)=394.44µs
http_req_tls_handshaking.......: avg=5.97ms min=0s med=0s max=516.03ms p(90)=0s p(95)=0s
http_req_waiting...............: avg=3.24s min=235.06ms med=2.94s max=11.42s p(90)=6.86s p(95)=7.68s
http_reqs......................: 2272 7.492106/s
iteration_duration.............: avg=21.81s min=11.11s med=22.76s max=32.65s p(90)=26.95s p(95)=28.18s
iterations.....................: 568 1.873026/s
vus............................: 1 min=1 max=50
vus_max........................: 50 min=50 max=50
I ran the tests with 20 users but it resulted in high CPU load. Do you suggest to gradually increase the concurrent users as following?
stages: [
{ target: 10, duration: '30s' },
{ target: 20, duration: '30s' },
{ target: 30, duration: '30s' },
{ target: 40, duration: '1m' },
{ target: 50, duration: '1m' },
{ target: 50, duration: '5m' },
{ target: 0, duration: '1m' },
],
Lets say if the system behaves okay when I set concurrent users to 10 and increases CPU load if I increase concurrent users, then what is the point of calculating the users from analytics?