diff --git a/tests/load/README.md b/tests/load/README.md new file mode 100644 index 00000000..dd00d156 --- /dev/null +++ b/tests/load/README.md @@ -0,0 +1,16 @@ +The tests use [k6](https://k6.io/) to perform load testing. + +# To run the test + +Set the following environment variables to point to the deployment. + +``` +export WEBAPP_URI= +export SEARCH_API_URI= +``` + +Once set, you can now run load tests using the following command: + +``` +npm run test:load +``` diff --git a/tests/load/chat.js b/tests/load/chat.js index a39115c8..b776bbd6 100644 --- a/tests/load/chat.js +++ b/tests/load/chat.js @@ -5,8 +5,14 @@ import { group, sleep } from 'k6'; const chatStreamLatency = new Trend('chat_stream_duration'); const chatNoStreamLatency = new Trend('chat_nostream_duration'); +function between(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive +} + function choose(list) { - return list[Math.floor(Math.random() * list.length)]; + return list[between(0, list.length)]; } export function chat(baseUrl, stream = true) { @@ -55,6 +61,6 @@ export function chat(baseUrl, stream = true) { const latencyMetric = stream ? chatStreamLatency : chatNoStreamLatency; latencyMetric.add(response.timings.duration, { type: 'API' }); - sleep(1); + sleep(between(5, 20)); }); } diff --git a/tests/load/config.js b/tests/load/config.js index ec5959cd..0494cde6 100644 --- a/tests/load/config.js +++ b/tests/load/config.js @@ -1,27 +1,16 @@ export const thresholdsSettings = { 'http_req_failed{type:API}': [{ threshold: 'rate<0.01' }], // less than 1% failed requests 'http_req_failed{type:content}': [{ threshold: 'rate<0.01' }], // less than 1% failed requests - 'http_req_duration{type:API}': ['p(95)<30000'], // 95% of the API requests must complete below 30s - 'http_req_duration{type:content}': ['p(99)<500'], // 99% of the content requests must complete below 500ms + 'http_req_duration{type:API}': ['p(90)<40000'], // 90% of the API requests must complete below 40s + 'http_req_duration{type:content}': ['p(99)<200'], // 99% of the content requests must complete below 200ms }; +// 5.00 iterations/s for 1m0s (maxVUs: 50-100, gracefulStop: 30s) export const standardWorkload = { - executor: 'per-vu-iterations', - vus: 50, - iterations: 50, - maxDuration: '50s', -}; - -export const heavyWorkload = { - executor: 'ramping-vus', - stages: [ - { duration: '10s', target: 20 }, - { duration: '50s', target: 20 }, - { duration: '50s', target: 40 }, - { duration: '50s', target: 60 }, - { duration: '50s', target: 80 }, - { duration: '50s', target: 100 }, - { duration: '50s', target: 120 }, - { duration: '50s', target: 140 }, - ], + executor: 'constant-arrival-rate', + rate: 5, + timeUnit: '1s', + duration: '1m', + preAllocatedVUs: 50, + maxVUs: 100, };