Simple load testing demo with K6.
APIs used are the Public APIs of DataGovSG
Test Case:
- Ramp up user traffic slowly from 1 -> 10 users
- Assert request duration should be less than 100ms. According to the Nielsen Norman Group, 100ms is the threshold for responding "instantaenously"
-
Install k6
$ brew install k6
-
Install node modules
$ npm install
-
Download collection and environments from postman
-
Convert the collection to load tests
$ npx postman-to-k6 <postman_collection>.json --output <output>/k6-script.js ## Example: $ npx postman-to-k6 data/tech_immersion.postman_collection.json --output tests/k6-script.js
-
Run k6 load tests!
k6 run tests/k6-script.js
-
Improve load test to simulate real traffic
export let options = { maxRedirects: 4, stages: [ { duration: '0.25m', target: 1 }, // start at 1 user { duration: '0.25m', target: 5 }, // stay at 5 users for 15 seconds { duration: '0.25m', target: 10 }, // ramp-up to 10 users { duration: '0.25m', target: 0 }, // go-down to 0 users ], thresholds: { http_req_duration: ['p(95)<100'], // 95% of requests should be below 100ms }, };