Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Update tileer load test script #1770

Merged
merged 4 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed

- Update DB anonymization script [#1769](https://github.com/open-apparel-registry/open-apparel-registry/pull/1769)
- Update tileer load test script [#1770](https://github.com/open-apparel-registry/open-apparel-registry/pull/1770)

### Deprecated

Expand Down
15 changes: 13 additions & 2 deletions load-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ components necessary to execute a load test are encapsulated in this directory.

- `K6_CLOUD_TOKEN`: An Auth Token for interacting with the k6 Cloud (optional)
- `CACHE_KEY_SUFFIX`: A suffix to append in the path to ensure tile requests miss the cache (optional)
- `VU_MULTIPLER`: An integer number of parallel executions of each batch of requests

## Running

Expand Down Expand Up @@ -59,11 +60,21 @@ default ✓ [======================================] 10 VUs 01m38.9s/10m0s 10/
ERRO[0101] some thresholds have failed
```

To invoke an instance of the load test running with 10 times the number of
parallel requests and a random cache key suffix to avoid CloudFront

```console
VU_MULTIPLIER=10 \
CACHE_KEY_SUFFIX=$(echo $(date) | sha1sum | cut -c1-8) \
docker-compose -f docker-compose.yml run --rm \
k6 run /scripts/zoom_rio_de_janerio_with_contributor_filter.js
```

To invoke an instance of the load test streaming output to the k6 Cloud:

```console
$ export K6_CLOUD_TOKEN=...
$ docker-compose \
-f docker-compose.k6.yml \
run --rm k6 run -o cloud scripts/zoom_rio_de_janerio_with_contributor_filter.js
-f docker-compose.yml \
run --rm k6 run -o cloud /scripts/zoom_rio_de_janerio_with_contributor_filter.js
```
1 change: 1 addition & 0 deletions load-tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
environment:
- K6_CLOUD_TOKEN
- CACHE_KEY_SUFFIX
- VU_MULTIPLIER
volumes:
- ./:/scripts/
command: run /scripts/zoom_rio_de_janerio_with_contributor_filter.js
16 changes: 12 additions & 4 deletions load-tests/zoom_rio_de_janerio_with_contributor_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ har.log.entries.forEach((entry) => {
const cacheKey = crypto
.sha1(entry.request.url.match(pattern)[5], "hex")
.slice(0, 8);
// Including the __VU in the cache key should generate a worse situation
// than typical. Each batch of requests is made by a separate VU and when
// VU_MULTIPLIER is larger than 1, we repeat the same batch of requests a
// number of times equal to VU_MULTIPLIER. Using __VU in the cache key means
// subsequent requests for the same batch will not hit the cache.
const url = entry.request.url.replace(
pattern,
`${cacheKey}${__ENV.CACHE_KEY_SUFFIX}/$2/$3/$4.pbf?$5`
`${cacheKey}-vu-${__VU}-${__ENV.CACHE_KEY_SUFFIX}/$2/$3/$4.pbf?$5`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to figure out where __VU was defined: https://k6.io/docs/using-k6/execution-context-variables/#_vu-and-_iter-discouraged. Seemingly discouraged by the docs, but works as expected here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the discouragement, too, but continued using __VU since it was already used successfully elsewhere in the script.

);

const referer = entry.request.headers.find(
Expand Down Expand Up @@ -63,11 +68,13 @@ batches = batches.sort((a, b) => a - b);

const failRate = new Rate("failed requests");

const VU_MULTIPLIER = __ENV.VU_MULTIPLIER || 1;

export const options = {
// We want VUs and iterations to match the number of parallel request
// batches we're going to issue so we can replay traffic 1:1.
vus: batches.length,
iterations: batches.length,
vus: batches.length * VU_MULTIPLIER,
iterations: batches.length * VU_MULTIPLIER,

discardResponseBodies: true,
maxRedirects: 0,
Expand All @@ -79,7 +86,8 @@ export const options = {
export default function () {
// Sleep each Batch so that everything doesn't happen at once
const firstBatchTime = batches[0];
const thisBatchTime = batches[__VU - 1];
const batchIndex = (__VU - 1) % batches.length;
const thisBatchTime = batches[batchIndex];
sleep(Math.floor((thisBatchTime - firstBatchTime) / 1000));

const responses = http.batch(requests[thisBatchTime]);
Expand Down