Skip to content

Commit 39cffa8

Browse files
committed
[BAEL-9370] Added linux scripts to test the applications performance
* Removed the mac scripts and the related documentation * Downgraded to java21 to fix the build
1 parent d785ea0 commit 39cffa8

42 files changed

Lines changed: 514 additions & 214254 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

persistence-modules/spring-data-jpa-repo-5/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
<parent>
1818
<groupId>org.springframework.boot</groupId>
1919
<artifactId>spring-boot-starter-parent</artifactId>
20-
<version>4.0.0-RC1</version>
20+
<version>3.4.13</version>
2121
</parent>
2222

2323
<properties>
24-
<java.version>25</java.version>
24+
<java.version>21</java.version>
2525
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2626
</properties>
2727
</project>

persistence-modules/spring-data-jpa-repo-5/sample_output.txt

Lines changed: 0 additions & 213870 deletions
This file was deleted.
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# =========================
5+
# CONFIGURATION
6+
# =========================
7+
APP_COMMAND=""
8+
URL="http://localhost:8080/hello"
9+
URL_LOAD="http://localhost:8080/get-user"
10+
INTERVAL=0.01
11+
DURATION_SEC=30
12+
TPS=300
13+
MAX_CONCURRENCY=300
14+
15+
MEM_SAMPLE_INTERVAL_NS=1000000000 # sample max memory every 1 second
16+
PEAK_RSS=0
17+
18+
# =========================
19+
# SELECT MODE
20+
# =========================
21+
case "${1:-}" in
22+
aot)
23+
APP_COMMAND="java -Dspring.aot.enabled=true \
24+
-Dspring.aot.repositories.enabled=false \
25+
-jar spring-data-jpa-aot/target/spring-data-jpa-aot-0.0.1-SNAPSHOT.jar"
26+
;;
27+
aot-repo)
28+
APP_COMMAND="java -Dspring.aot.enabled=true \
29+
-Dspring.aot.repositories.enabled=true \
30+
-jar spring-data-jpa-aot-repository/target/spring-data-jpa-aot-repository-0.0.1-SNAPSHOT.jar"
31+
;;
32+
non-aot)
33+
APP_COMMAND="java -jar spring-data-jpa-not-aot/target/spring-data-jpa-not-aot-0.0.1-SNAPSHOT.jar"
34+
;;
35+
*)
36+
echo "Usage: $0 {aot|aot-repo|non-aot}"
37+
exit 1
38+
;;
39+
esac
40+
41+
# =========================
42+
# START APPLICATION
43+
# =========================
44+
echo "Starting application..."
45+
start_ns=$(date +%s%N)
46+
47+
bash -c "$APP_COMMAND" &
48+
APP_PID=$!
49+
50+
echo "PID: $APP_PID"
51+
echo "Waiting for service at $URL ..."
52+
53+
# Wait until HTTP 200
54+
while [[ "$(curl -s -o /dev/null -L -w "%{http_code}" "$URL")" != "200" ]]; do
55+
sleep "$INTERVAL"
56+
done
57+
58+
end_ns=$(date +%s%N)
59+
elapsed_ms=$(((end_ns - start_ns) / 1000000))
60+
61+
startup_mem=$(ps -o rss=,time= -p "$APP_PID")
62+
63+
echo ""
64+
echo "==== STARTUP RESULTS ===="
65+
echo "Startup time: ${elapsed_ms} ms"
66+
echo "Memory/CPU (RSS KB / TIME): $startup_mem"
67+
68+
# =========================
69+
# LOAD TEST SETUP
70+
# =========================
71+
echo ""
72+
echo "==== LOAD TEST ===="
73+
echo "URL: $URL_LOAD"
74+
echo "TPS: $TPS"
75+
echo "Duration: ${DURATION_SEC}s"
76+
77+
START_NS=$(date +%s%N)
78+
END_NS=$((START_NS + DURATION_SEC * 1000000000))
79+
INTERVAL_NS=$((1000000000 / TPS))
80+
next_time=$START_NS
81+
82+
METRICS_FILE=$(mktemp)
83+
MEMORY_BEFORE=$(ps -o rss=,time= -p "$APP_PID")
84+
85+
# =========================
86+
# REQUEST FUNCTION
87+
# =========================
88+
get() {
89+
local url="$1"
90+
local start end duration_ms result code time_total
91+
92+
start=$(date +%s%3N)
93+
94+
result=$(curl --max-time 2 -s -o /dev/null -w "%{http_code} %{time_total}" "$url")
95+
code=$(awk '{print $1}' <<< "$result")
96+
time_total=$(awk '{print $2}' <<< "$result")
97+
98+
end=$(date +%s%3N)
99+
duration_ms=$((end - start))
100+
101+
echo "$code $time_total $duration_ms" >> "$METRICS_FILE"
102+
}
103+
104+
# =========================
105+
# LOAD GENERATION (TPS + CONCURRENCY CONTROL)
106+
# =========================
107+
last_mem_sample=0
108+
while [[ "$(date +%s%N)" -lt "$END_NS" ]]; do
109+
now=$(date +%s%N)
110+
if (( now - last_mem_sample >= MEM_SAMPLE_INTERVAL_NS )); then
111+
current_rss=$(ps -o rss= -p "$APP_PID")
112+
113+
if [[ "$current_rss" -gt "$PEAK_RSS" ]]; then
114+
PEAK_RSS=$current_rss
115+
fi
116+
117+
last_mem_sample=$now
118+
fi
119+
120+
while [[ "$now" -ge "$next_time" ]]; do
121+
122+
# ---- concurrency cap (THIS is the new part) ----
123+
while [[ "$(jobs -rp | wc -l)" -ge "$MAX_CONCURRENCY" ]]; do
124+
sleep 0.001
125+
done
126+
127+
get "$URL_LOAD" &
128+
129+
next_time=$((next_time + INTERVAL_NS))
130+
done
131+
132+
sleep 0.001
133+
done
134+
135+
# Allow in-flight requests to finish (bounded)
136+
sleep 1
137+
138+
# =========================
139+
# SHUTDOWN
140+
# =========================
141+
MEMORY_AFTER=$(ps -o rss=,time= -p "$APP_PID")
142+
143+
echo "Stopping application..."
144+
kill "$APP_PID" 2>/dev/null || true
145+
sleep 2
146+
147+
# =========================
148+
# RESULTS
149+
# =========================
150+
echo ""
151+
echo "==== RESULTS ===="
152+
153+
total=$(wc -l < "$METRICS_FILE")
154+
success=$(awk '$1 ~ /^2/ {c++} END {print c+0}' "$METRICS_FILE")
155+
fail=$((total - success))
156+
157+
avg_time=$(awk '{sum+=$2} END {if (NR>0) print sum/NR}' "$METRICS_FILE")
158+
avg_duration=$(awk '{sum+=$3} END {if (NR>0) print sum/NR}' "$METRICS_FILE")
159+
160+
p95=$(awk '{print $2}' "$METRICS_FILE" | sort -n | awk '{a[NR]=$1} END {print a[int(NR*0.95)]}')
161+
max_time=$(awk '{print $2}' "$METRICS_FILE" | sort -n | tail -1)
162+
163+
echo "Total requests: $total"
164+
echo "Success (2xx): $success"
165+
echo "Failed: $fail"
166+
167+
echo "Avg time (curl): ${avg_time}s"
168+
echo "Avg duration (measured): ${avg_duration}ms"
169+
echo "P95: ${p95}s"
170+
echo "Max: ${max_time}s"
171+
172+
echo ""
173+
echo "Max memory utilised: $PEAK_RSS"
174+
echo "Memory/CPU (RSS KB / TIME):"
175+
echo "Before: $MEMORY_BEFORE"
176+
echo "After : $MEMORY_AFTER"
177+
178+
rm -f "$METRICS_FILE"

persistence-modules/spring-data-jpa-repo-5/scripts/load-test.sh

Lines changed: 0 additions & 76 deletions
This file was deleted.

persistence-modules/spring-data-jpa-repo-5/scripts/startup.sh renamed to persistence-modules/spring-data-jpa-repo-5/scripts/startup-linux.sh

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
set -euo pipefail
33

44
APP_COMMAND=""
5+
URL="http://localhost:8080/get-user"
6+
INTERVAL=0.01 # seconds between checks
57

68
case "$1" in
79
aot)
810
APP_COMMAND="java -Dspring.aot.enabled=true \
911
-Dspring.aot.repositories.enabled=false \
10-
-agentlib:native-image-agent=config-output-dir=target/native-image-hints \
1112
-jar spring-data-jpa-aot/target/spring-data-jpa-aot-0.0.1-SNAPSHOT.jar"
1213
;;
1314
aot-repo)
1415
APP_COMMAND="java -Dspring.aot.enabled=true \
1516
-Dspring.aot.repositories.enabled=true \
16-
-agentlib:native-image-agent=config-output-dir=target/native-image-hints \
17+
-Dspring.data.repositories.aot.enabled=true \
1718
-jar spring-data-jpa-aot-repository/target/spring-data-jpa-aot-repository-0.0.1-SNAPSHOT.jar"
1819
;;
1920
non-aot)
@@ -28,33 +29,22 @@ esac
2829
# --- 1. Start your script in the background ---
2930
# Record start time in milliseconds
3031
start_ns=$(date +%s%N)
32+
33+
# --- 2. Start the application ---
3134
$APP_COMMAND &
3235
APP_PID=$!
33-
echo "Started APP with PID $APP_PID"
34-
35-
# --- 2. Start sampling in the background ---
36-
sudo sample $APP_PID > sample_output.txt &
37-
SAMPLE_PID=$!
38-
echo "Sampling process started (PID $SAMPLE_PID)"
39-
echo "Waiting for service at http://localhost:8080/get-user ..."
36+
echo "Started APP with PID: $APP_PID"
4037

4138
# --- 3. Poll the endpoint until it returns HTTP 200 ---
42-
while [ "$(curl -s -o /dev/null -L -w ''%{http_code}'' http://localhost:8080/get-user)" != 200 ]
43-
do sleep 0.001;
39+
echo "Waiting for service at http://localhost:8080/get-user ..."
40+
while [ "$(curl -s -o /dev/null -L -w ''%{http_code}'' $URL)" != 200 ]
41+
do sleep $INTERVAL;
4442
done
4543

4644
# Capture elapsed time (SECONDS has fractional part) and the memory info
4745
end_ns=$(date +%s%N)
4846
elapsed_ms=$(((end_ns - start_ns) / 1000000))
49-
MEMINFO=$(ps -o rss,vsz,pcpu,time -p $APP_PID | tail -1)
50-
51-
## --- 4. Stop sampling and show results ---
52-
#echo "Stopping sample..."
53-
#sudo kill -INT "$SAMPLE_PID"
54-
#wait "$SAMPLE_PID" 2>/dev/null || true
55-
#
56-
## Give sample a moment to flush output
57-
#sleep 2
47+
MEMINFO=$(ps -o rss=,time= -p "$APP_PID")
5848

5949
# --- 5. Clean up ---
6050
echo "Stopping startup process..."
@@ -64,8 +54,6 @@ kill "$APP_PID" 2>/dev/null || true
6454
sleep 3
6555

6656
echo "Done."
67-
68-
THREADS=$(grep -E "Thread_[0-9]+" sample_output.txt | wc -l)
57+
echo "==== RESULTS ===="
6958
echo "time elapsed $elapsed_ms millis"
70-
echo "Threads: $THREADS"
71-
echo "Memory/CPU (RSS KB / VSZ KB / %CPU / CPU Time): $MEMINFO"
59+
echo "Process Specific Memory/CPU (RSS KB / CPU Time): $MEMINFO"

0 commit comments

Comments
 (0)