Skip to content

Commit

Permalink
test: randomize the iteration interval
Browse files Browse the repository at this point in the history
  • Loading branch information
shibbas committed Oct 26, 2023
1 parent 29cc328 commit 61c82ab
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
16 changes: 16 additions & 0 deletions tests/load/README.md
Original file line number Diff line number Diff line change
@@ -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=<webapp_uri>
export SEARCH_API_URI=<search_api_uri>
```

Once set, you can now run load tests using the following command:

```
npm run test:load
```
10 changes: 8 additions & 2 deletions tests/load/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
});
}
29 changes: 9 additions & 20 deletions tests/load/config.js
Original file line number Diff line number Diff line change
@@ -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,
};

0 comments on commit 61c82ab

Please sign in to comment.