Skip to content

Commit 7eb418a

Browse files
authored
Merge pull request #1164 from OpenConext/feature/#666-load-test-external-creation-api
Feature/#666 load test external creation api
2 parents c45f0f7 + 7604ded commit 7eb418a

22 files changed

Lines changed: 2094 additions & 0 deletions
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Performance test
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
benchmark_sizes:
7+
description: 'Comma-separated database sizes to test'
8+
required: false
9+
default: '1000,10000,100000,1000000,2000000,4000000'
10+
benchmark_users:
11+
description: 'Virtual users per Gatling run'
12+
required: false
13+
default: '100'
14+
benchmark_ramp_seconds:
15+
description: 'Ramp-up duration in seconds per Gatling run'
16+
required: false
17+
default: '30'
18+
19+
jobs:
20+
benchmark:
21+
runs-on: ubuntu-latest
22+
timeout-minutes: 180
23+
24+
steps:
25+
- uses: actions/checkout@v6
26+
27+
- name: Set up JDK 21
28+
uses: actions/setup-java@v5
29+
with:
30+
java-version: 21
31+
distribution: temurin
32+
cache: maven
33+
34+
- name: Set up Node.js
35+
uses: actions/setup-node@v6
36+
with:
37+
node-version: '24.3.0'
38+
39+
- name: Install mongosh
40+
run: |
41+
sudo apt-get update
42+
sudo apt-get install -y wget gnupg
43+
wget -qO - https://pgp.mongodb.com/server-7.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-7.0.gpg
44+
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
45+
sudo apt-get update
46+
sudo apt-get install -y mongodb-mongosh
47+
48+
- name: Start MongoDB and Mailpit
49+
run: docker compose up -d mongo mailpit
50+
51+
- name: Wait for MongoDB
52+
run: |
53+
for i in $(seq 1 60); do
54+
if docker compose exec -T mongo mongosh --quiet --eval "db.adminCommand({ ping: 1 }).ok" | grep -q 1; then
55+
exit 0
56+
fi
57+
sleep 2
58+
done
59+
echo "MongoDB did not become ready in time"
60+
exit 1
61+
62+
- name: Start backend
63+
run: |
64+
mkdir -p myconext-performance-test/target
65+
cd myconext-server
66+
nohup mvn spring-boot:run -Dspring-boot.run.profiles=dev > ../myconext-performance-test/target/backend.log 2>&1 &
67+
echo $! > ../myconext-performance-test/target/backend.pid
68+
69+
- name: Wait for backend
70+
run: |
71+
for i in $(seq 1 120); do
72+
if curl --silent --fail http://localhost:8081/myconext/api/swagger-ui/index.html >/dev/null; then
73+
exit 0
74+
fi
75+
sleep 5
76+
done
77+
echo "Backend did not become ready in time"
78+
tail -200 myconext-performance-test/target/backend.log || true
79+
exit 1
80+
81+
- name: Run database growth benchmark
82+
working-directory: myconext-performance-test/src/test/scripts
83+
env:
84+
BENCHMARK_SIZES: ${{ inputs.benchmark_sizes }}
85+
BENCHMARK_USERS_PER_RUN: ${{ inputs.benchmark_users }}
86+
BENCHMARK_RAMP_SECONDS: ${{ inputs.benchmark_ramp_seconds }}
87+
run: bash ./benchmark_database_growth.sh
88+
89+
- name: Stop backend
90+
if: always()
91+
run: |
92+
if [ -f myconext-performance-test/target/backend.pid ]; then
93+
kill $(cat myconext-performance-test/target/backend.pid) || true
94+
fi
95+
96+
- name: Stop Docker services
97+
if: always()
98+
run: docker compose down -v
99+
100+
101+
- name: Write workflow summary
102+
if: always()
103+
run: |
104+
{
105+
echo "## Database Growth Benchmark"
106+
echo
107+
echo "Artifacts uploaded: `database-growth-benchmark`"
108+
echo
109+
echo "Important files inside the artifact:"
110+
echo "- `myconext-performance-test/target/gatling/compare.html`"
111+
echo "- `myconext-performance-test/src/test/scripts/benchmark_database_growth.log`"
112+
echo "- `myconext-performance-test/target/backend.log`"
113+
echo
114+
echo "Inputs used:"
115+
echo "- sizes: `${{ inputs.benchmark_sizes }}`"
116+
echo "- benchmark users: `${{ inputs.benchmark_users }}`"
117+
echo "- ramp seconds: `${{ inputs.benchmark_ramp_seconds }}`"
118+
} >> "$GITHUB_STEP_SUMMARY"
119+
120+
- name: Upload benchmark artifacts
121+
if: always()
122+
uses: actions/upload-artifact@v4
123+
with:
124+
name: database-growth-benchmark
125+
path: |
126+
myconext-performance-test/target/gatling
127+
myconext-performance-test/src/test/scripts/benchmark_database_growth.log
128+
myconext-performance-test/target/backend.log
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Learn more about Configuration as Code: https://docs.gatling.io/reference/execute/cloud/user/configuration-as-code
2+
# This file is full deployment configuration file example.
3+
# Please note all these configuration fields, or even this file, are optional.
4+
5+
gatling.enterprise.package {
6+
# Consistent deployment using an existing package ID
7+
# https://docs.gatling.io/reference/execute/cloud/user/configuration-as-code/#consistent-deployment-with-id
8+
# id = "00000000-0000-0000-0000-000000000000"
9+
name = "My package name"
10+
team = "Default team" # or ID with team = "00000000-0000-0000-0000-000000000000"
11+
default {
12+
simulation {
13+
locations = [
14+
{
15+
name: "Europe - Paris",
16+
size: 2,
17+
weight: 30
18+
},
19+
{
20+
name: "AP Pacific - Mumbai",
21+
size: 2,
22+
weight: 70
23+
}
24+
]
25+
parameters {
26+
ignoreDefaults = false
27+
systemProperties {
28+
# System properties names should be surrounded by quotes
29+
# Otherwise, it would be interpreted as HOCON keys
30+
"com.example.prop.1" = "default value from system prop 1"
31+
"com.example.prop.2" = "default value from system prop 2"
32+
}
33+
environmentVariables {
34+
MY_SIMULATION_ENV_VAR_1 = "default value from environment 1"
35+
MY_SIMULATION_ENV_VAR_2 = "default value from environment 2"
36+
}
37+
}
38+
timeWindow {
39+
rampUp = 10 # in seconds
40+
rampDown = 10 # in seconds
41+
}
42+
}
43+
}
44+
simulations = [
45+
{
46+
# Consistent deployment using an existing simulation ID
47+
# https://docs.gatling.io/reference/execute/cloud/user/configuration-as-code/#consistent-deployment-with-id
48+
# id = "00000000-0000-0000-0000-000000000001"
49+
name = "My simulation name"
50+
# FQCN Fully Qualified Class Name
51+
simulation = "computerdatabase.ComputerDatabaseSimulation"
52+
}
53+
]
54+
}
55+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# See `example.package.conf` for a full deployment configuration file example
2+
# Learn more about Configuration as Code: https://docs.gatling.io/reference/execute/cloud/user/configuration-as-code
3+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "maven" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
day: "monday" # explicit, even tough it's the weekly default
12+
time: "07:00" # UTC
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
/src/test/scripts/benchmark_database_growth.log
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# MyConext Performance Testing
2+
3+
This project is used to test performance scenarios for **MyConext**.
4+
5+
It includes:
6+
- **Gatling performance tests** for load and flow validation
7+
- A **data seeder** to insert fake data into the `users` collection
8+
9+
## Current flow
10+
11+
At the moment, the project supports a single test flow:
12+
13+
1. **Check if an email exists**
14+
2. **Create a new myconext user** with status **Ongeverifieerd**
15+
3. **Update the myconext user** using data from step 2:
16+
- Change the verification status
17+
18+
## System Requirements
19+
- Java 21
20+
- Maven 3
21+
- mongoese 5.0.3
22+
23+
## How to run the preformance Test (Database Growth Benchmark)
24+
There is a script to run the performance test. This script will insert users in the database and run the performance test. It testing the database growth.
25+
1. It wil insert x amount of users in the database.
26+
2. It will run the performance test and generate a report.
27+
28+
It will repeat step 1 and 2 with the following amount of users 1000 10000 100000 1000000 2000000 4000000.
29+
30+
For `DatabaseGrowthBenchmarkSimulation`, a `target/gatling/compare.html` page is generated automatically after each run.
31+
32+
### Run the full database growth preformance test
33+
```bash
34+
cd ./src/test/scripts
35+
bash benchmark_database_growth.sh
36+
```
37+
38+
## How to Run MongoDB User Data Seeder
39+
Tip: This is simple command to count users:
40+
``` shell
41+
mongosh "mongodb://localhost:27017" --eval "db.getSiblingDB('surf_id_test').users.countDocuments()"
42+
```
43+
44+
1. Navigate to the scripts directory
45+
```bash
46+
cd ./src/test/scripts
47+
```
48+
2. Configure the connection (edit `seed_script.sh`)
49+
**Local MongoDB (no authentication):**
50+
```bash
51+
MONGO_HOST="localhost"
52+
MONGO_PORT="27017"
53+
MONGO_USERNAME=""
54+
MONGO_AUTH_DB=""
55+
```
56+
**Remote MongoDB (with authentication):**
57+
```bash
58+
MONGO_HOST="your-server.com"
59+
MONGO_PORT="27017"
60+
MONGO_USERNAME="admin"
61+
MONGO_AUTH_DB="admin"
62+
```
63+
64+
3. Run the script
65+
```bash
66+
bash seed_script.sh
67+
```
68+
Press `Enter` at the drop prompt to continue without clearing the collection first.
69+
Use `TOTAL_USERS=10000 bash seed_script.sh` to seed a different amount.
70+
71+
## How to run Gatling tests
72+
- Run the command `mvn gatling:test -Dgatling.simulationClass=...........`
73+
- The results can be found in the logging and there is a nice html page generated in the *target/gatling* folder
74+
- Tip: if you want to keep past results don't run `mvn clean`
75+
- For `DatabaseGrowthBenchmarkSimulation`, a `target/gatling/compare.html` page is generated automatically after each run
76+
- You can store the database size for that run with `-Damountusers=1000` so the compare page shows headers like `20260317135617983 (1000 users)`
77+
78+
### Run Gatling with props
79+
```shell
80+
mvn gatling:test \
81+
-Dgatling.simulationClass=myconext.simulations.SingleRunSimulation \
82+
-DbaseUrl=http://localhost:8081 \
83+
-Dusername=studielink \
84+
-Dpassword=secret
85+
```
86+
87+
### Run Gatling SingelRun (8 minutes)
88+
```shell
89+
mvn gatling:test -Dgatling.simulationClass=myconext.simulations.SingleRunSimulation
90+
```
91+
92+
### Run Database Growth Benchmark with database size label
93+
```shell
94+
mvn gatling:test \
95+
-Dgatling.simulationClass=myconext.simulations.DatabaseGrowthBenchmarkSimulation \
96+
-Damountusers=1000
97+
```
98+
99+
### Run the full database growth series
100+
```bash
101+
cd ./src/test/scripts
102+
bash benchmark_database_growth.sh
103+
```
104+
105+
### Run Gatling Stress Test (5 minutes)
106+
```shell
107+
mvn gatling:test -Dgatling.simulationClass=myconext.simulations.StressTestSimulation
108+
```
109+
110+
### Run Gatling Stress Test Gentle (5 minutes)
111+
```shell
112+
mvn gatling:test -Dgatling.simulationClass=myconext.simulations.StressTestSimulationGentle
113+
```
114+
115+
### Run Gatling Gradual Ramp Up (8 minutes)
116+
```shell
117+
mvn gatling:test -Dgatling.simulationClass=myconext.simulations.GradualRampUpSimulation
118+
```
119+
120+
### Run Gatling Soak Test (35 minutes)
121+
```shell
122+
mvn gatling:test -Dgatling.simulationClass=myconext.simulations.SoakTestSimulation
123+
```

myconext-performance-test/pom.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.openconext</groupId>
7+
<artifactId>myconext-performance-test</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
10+
<properties>
11+
<maven.compiler.release>21</maven.compiler.release>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<gatling.version>3.14.9</gatling.version>
14+
<gatling-maven-plugin.version>4.19.0</gatling-maven-plugin.version>
15+
<maven-compiler-plugin.version>3.14.0</maven-compiler-plugin.version>
16+
<maven-jar-plugin.version>3.5.0</maven-jar-plugin.version>
17+
<mongodb.version>5.2.1</mongodb.version>
18+
<datafaker.version>2.4.2</datafaker.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>io.gatling.highcharts</groupId>
24+
<artifactId>gatling-charts-highcharts</artifactId>
25+
<version>${gatling.version}</version>
26+
<scope>test</scope>
27+
</dependency>
28+
</dependencies>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<artifactId>maven-compiler-plugin</artifactId>
34+
<version>${maven-compiler-plugin.version}</version>
35+
</plugin>
36+
<plugin>
37+
<artifactId>maven-jar-plugin</artifactId>
38+
<version>${maven-jar-plugin.version}</version>
39+
</plugin>
40+
<plugin>
41+
<groupId>io.gatling</groupId>
42+
<artifactId>gatling-maven-plugin</artifactId>
43+
<version>${gatling-maven-plugin.version}</version>
44+
<configuration>
45+
<!-- Enterprise Cloud (https://cloud.gatling.io/) configuration reference: https://docs.gatling.io/reference/integrations/build-tools/maven-plugin/#running-your-simulations-on-gatling-enterprise-cloud -->
46+
</configuration>
47+
</plugin>
48+
</plugins>
49+
</build>
50+
</project>

0 commit comments

Comments
 (0)