Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: configuration of k6 for performance tests #256

Merged
merged 72 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
0ac779e
perf: add initial k6 scripts for testing crud performances
danibix95 Jan 10, 2024
dc4fc71
wip: updateds on k6 tests
Jan 12, 2024
3d8565d
feat: view registered-customers
Jan 16, 2024
ebd32c1
refactor: regenerate.js
Jan 16, 2024
8f9dff9
feat: items collection, update users
Jan 16, 2024
b47a48c
feat: runners
Jan 16, 2024
cf5dc3a
removed comments
Jan 17, 2024
13f2ed4
cleared up dc-k6.yml
Jan 17, 2024
0866a40
feat: perf-test github action
Jan 17, 2024
d2ea505
feat: add commands to perf-test
Jan 17, 2024
a059cb9
test: execute pwd for testing reasons
Jan 17, 2024
9a74d3e
feat(perf-test): use docker to create mongo, crud instances
Jan 17, 2024
6a3be86
fix: typo
Jan 17, 2024
5517274
fix: uncomment lines on docker-compose.yml
Jan 17, 2024
4d2b687
feat: trying to save artifact
Jan 17, 2024
28eaaa0
test: remove threshold
Jan 17, 2024
ef496e9
refactor: change regenerate script name to generate-customer-data
Jan 17, 2024
aa2aeac
test: tentative with multiple k6 tests
Jan 17, 2024
03648de
fix: typo on k6_ci_test pipeline
Jan 17, 2024
2570cb6
fix: update perf-test workflow
Jan 17, 2024
910bbbd
fix: connection string in perf-test.yml
Jan 17, 2024
e5949fc
fix: add database name in supercharge
Jan 17, 2024
7179536
fix wrong DB name
Jan 17, 2024
17bb55c
fix: syntax error
Jan 17, 2024
ea42ae2
fix(perf-test): start CRUD without blocking deamon
Jan 17, 2024
1b1f0ee
fix(perf-test): CRUD path
Jan 17, 2024
cb0b11d
fix(perf-test): not using utils.js in load-test
Jan 17, 2024
29e0b28
fix(perf-test): typo on POST requests
Jan 17, 2024
f1d388d
updated tests
Jan 18, 2024
b4d63d0
updated dc-k6 with all tests
Jan 18, 2024
ce341df
test: updated perf-test to use k6 local docker
Jan 18, 2024
0386b56
fix: correct folder in perf-test workflow
Jan 18, 2024
c7d8749
feat: using crud-service in docker container
Jan 18, 2024
ffd6f0d
fix: perf-test to have docker-compose to start crud and mongo
Jan 18, 2024
aeb229e
feat: add index in registeted-customers
Jan 18, 2024
7caea6c
fix: patch on load-test, including tags
Jan 18, 2024
ac17505
feat(docker-compose): remove crud-service:latest image ref
Jan 18, 2024
c23b511
feat: improvements in tests
Jan 18, 2024
d6fddfe
refactor: runners on same folder, introducing utils.js
Jan 18, 2024
1975240
refactor: using utils.js everywhere
Jan 18, 2024
b199325
fix: import in spike-test.js
Jan 18, 2024
4fb3bf4
Merge branch 'main' into feat/perf-test
Jan 19, 2024
6f6ee5b
Merge branch 'main' into feat/perf-test
Jan 22, 2024
03739ed
fix: imports in load-test
Jan 22, 2024
caa2265
feat: add smoke-test in dc-k6
Jan 22, 2024
a79a82a
add indexes in collections
Jan 22, 2024
2d86994
refactor: documenting code
Jan 22, 2024
40a32fe
refactor: moved collections
Jan 22, 2024
2f59eee
fix: removed restore-mongo step and fix crud-service in docker-compose
Jan 22, 2024
25dd1b6
clean up code to create customer data in DB
Jan 22, 2024
8ca0aa7
refactor: moved healthcheck fn
Jan 22, 2024
a41dc6b
refactor: removed comments from workflows/perf-test.yml
Jan 22, 2024
10ec897
tests updates
Jan 22, 2024
3d7fc63
fix: perf-test workflow
Jan 22, 2024
4bd1ac5
feat: README
Jan 22, 2024
392b7b8
fix error on the README
Jan 22, 2024
19c4a6c
update perf-test.yml
Jan 22, 2024
ec13644
chore: add commander as devDep
Jan 22, 2024
42d73b5
fix: add npm i stage in perf-test.yml
Jan 22, 2024
89a5348
refactor: clean up code
Jan 22, 2024
5703d53
fix: minor updates on code
Jan 23, 2024
d9f9bf1
remove unused gitignore
Jan 23, 2024
89d46e6
fix docker-compose folders
Jan 23, 2024
31a9ad7
fix: perf-test workflow executed after tests
Jan 23, 2024
dd7a124
fix: minor fixes
Jan 23, 2024
42da87a
minor fix on runner work, index in registered-customers
Jan 23, 2024
efec5f9
fix: defaults on generate-customer-data
Jan 23, 2024
e5db3dc
fix generate-customer-data script
Jan 24, 2024
68811e5
perf-test workflow to be executed at every tag released
Jan 24, 2024
62c54aa
chore: add disclaimer in updated files
Jan 29, 2024
3936e42
updated readme
Jan 29, 2024
ebb0da5
fix: removed duplicated title in README.md
Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ jobs:
version: main
secrets:
security_checks_token: ${{ secrets.CRUD_SERVICE_SYSDIG_CHECK_TRIGGER }}

perf-test:
needs:
- checks
uses: ./.github/workflows/perf-test.yml
49 changes: 49 additions & 0 deletions .github/workflows/perf-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: 'Performance Test'

on:
workflow_call:
inputs:
node-version:
default: 20.x
required: false
type: string
# TODO: Update this when we're ready to go - it should happen at every tag or something
push:
branches:
- 'feat/perf-test'
ThisIsDemetrio marked this conversation as resolved.
Show resolved Hide resolved


jobs:
k6_ci_test:
name: k6 CI Test run
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: start CRUD Service via docker file
run: docker compose --file bench/docker-compose.yml up -d

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: npm

- name: Populate "Customer" collection and "Registered Customer" View
run: npm i && node bench/utils/generate-customer-data.js -c mongodb://localhost:27017/bench-test -d bench-test -n 100000 -s 250

- name: Run k6 load test (collection Items)
working-directory: bench
run: docker compose -f dc-k6.yml up k6-load-test

- name: Run k6 spike test (collection Customers)
working-directory: bench
run: docker compose -f dc-k6.yml up k6-spike-test

- name: Run k6 stress test (view Registered Customers)
working-directory: bench
run: docker compose -f dc-k6.yml up k6-stress-test-on-view


6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ kms
test-collections
.npmrc
.tap
.local
.local
bench/definitions
#bench/definitions/views
ThisIsDemetrio marked this conversation as resolved.
Show resolved Hide resolved
#bench/definitions/collections

54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,60 @@ This API responses always in `application/application/x-ndjson`

See the documentation to see which parameters are available.

## Performance test

## Performance Test

We use [k6](https://example.com/k6) to simulate the load of traffic directed to the CRUD Service and retrieve some performance metrics. At every version released, a workflow automatically starts executing the following tests:

- **Load Test**: 10 virtual users execute POST requests for one minute on the same collection, then 100 virtual users execute GET, PATCH, and DELETE requests for another minute on the data created.
- **Spike Test**: We simulate a spike of activity by increasing the number of users from 5 to 500 in 30 seconds, then a decrement of activity from 500 to 5 in another 30 seconds. During this test, only GET requests are executed on a collection that includes 100,000 documents.
- **Stress Test**: We simulate a brief time of intense activity with 250 users for 90 seconds, followed by a decrement of activity to 5 in 30 seconds. During this test, only GET requests are executed on a collection that includes 100,000 documents.

These tests are executed ahead of every version release to ensure that further updates do not cause a degradation of performance that might affect the usage of the CRUD Service.

### Execute Performance Test on a Local Environment

In case you want to run the tests on your local environment, follow these steps:

- Start the CRUD Service in a Docker container.
- Have a MongoDB instance ready for use, eventually loaded with existing documents to simulate tests.

To simplify these operations, you can use the same setup for the tests executed during the GitHub workflow, by starting an instance of the CRUD Service using collections and views included in the folder `_bench/definitions`. Use the script `bench/utils/generate-customer-data.js` to quickly include mock documents in the _customers_ collection.

The `generate-customer-data.js` script can be executed at any time with the following command:

```bash
node bench/utils/generate-customer-data.js -c <connection string> -d <database name> -n <number of documents> -s <number of total shops>
```
Where the script arguments are the following:
- **connection string** (default: _mongodb://localhost:27017_): Connects to your MongoDB instance.
- **database name** (default: _bench-test_): Specifies the name of the database to write to.
- **number of documents** (default: _100000_): Sets the number of documents to be created and saved in the customers collection of the specified database.
- **number of total shops** (default: _250_): Defines a random value (from 1 to the specified number) applied to the shopID field of each document to be saved.


To simplify these operations, you can execute the command npm run bench:init from your shell. This command starts a container with a MongoDB 6.0 instance, a container with the CRUD Service (built from your current branch), and populates the _customers_ collection with 100,000 documents.

To execute any test, start the k6 service with the following command:
```
docker compose -f bench/dc-k6.yml up <service name>
```
Remember to replace `<service name>` with one of the following:

| Service Name | Description | File name containing the test |
|--------------------------------|-------------------------------------------------------------------------------------------------|------------------------------------------|
| k6-load-test | Executes a Load Test (1 minute of POST, 1 minute of GET/PATCH/DELETE) on the _items_ collection | [load-test.js](bench/scripts/load-test.js) |
| k6-smoke-test | Executes a Smoke Test (1 minute of GET requests) on the _customers_ collection | [smoke-test.js](bench/scripts/smoke-test.js) |
| k6-stress-test-on-collections | Executes a Stress Test (GET requests for 90 seconds by 250 users) on the _customers_ collection | [stress-test-on-collections.js](bench/scripts/stress-test-on-collections.js) |
| k6-stress-test-on-view | Executes a Stress Test (GET requests for 90 seconds by 250 users) on the _registered-customers_ view | [stress-test-on-view.js](bench/scripts/stress-test-on-view.js) |
| k6-spike-test | Executes a Spike Test (simulate a spike of 500 concurrent users for GET requests) on the _customers_ collection | [spike-test.js](bench/scripts/spike-test.js) |
| runner | An empty test that can be populated for tests on local environment | [runner.js](bench/scripts/runner.js) |

We suggest you to use the runner to execute customized tests for your own research.

You are free to modify and improve those tests and the definitions used for them but please remember to not use any sensible data.

## FAQ

### How do I change the Mongocryptd version on Debian
Expand Down
2 changes: 2 additions & 0 deletions bench/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data/dump
node_modules
106 changes: 106 additions & 0 deletions bench/dc-k6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
services:
runner:
image: grafana/k6:0.48.0
deploy:
resources:
limits:
memory: 512Mb
cpus: "1"
volumes:
- ./scripts:/app
networks:
- k6-net
command: [
"run",
"--out",
"json=runner-results.json",
"/app/runner-test.js",
]
k6-load-test:
danibix95 marked this conversation as resolved.
Show resolved Hide resolved
image: grafana/k6:0.48.0
deploy:
resources:
limits:
memory: 512Mb
cpus: "1"
volumes:
- ./scripts:/app
networks:
- k6-net
command: [
"run",
"--out",
"json=load-test-results.json",
"/app/load-test.js",
]
k6-smoke-test:
image: grafana/k6:0.48.0
deploy:
resources:
limits:
memory: 512Mb
cpus: "1"
volumes:
- ./scripts:/app
networks:
- k6-net
command: [
"run",
"--out",
"json=smoke-test-results.json",
"/app/smoke-test.js",
]
k6-stress-test-on-collection:
image: grafana/k6:0.48.0
deploy:
resources:
limits:
memory: 512Mb
cpus: "1"
volumes:
- ./scripts:/app
networks:
- k6-net
command: [
"run",
"--out",
"json=stress-test-on-collection-results.json",
"/app/stress-test-on-collection.js",
]
k6-stress-test-on-view:
image: grafana/k6:0.48.0
deploy:
resources:
limits:
memory: 512Mb
cpus: "1"
volumes:
- ./scripts:/app
networks:
- k6-net
command: [
"run",
"--out",
"json=stress-test-on-view-results.json",
"/app/stress-test-on-view.js",
]
k6-spike-test:
image: grafana/k6:0.48.0
deploy:
resources:
limits:
memory: 512Mb
cpus: "1"
volumes:
- ./scripts:/app
networks:
- k6-net
command: [
"run",
"--out",
"json=spike-test-results.json",
"/app/spike-test.js",
]

networks:
k6-net:
Loading
Loading