Spring Boot startup time: bean-by-bean diagnosis, and one directory per post
Adds spring-boot-startup-time/, the companion project for BLOG-618: a runnable Spring Boot 4.1.1 application on JDK 25 that installs BufferingApplicationStartup and FlightRecorderApplicationStartup behind a system property, and a /diag/startup endpoint that computes step self time -- the number /actuator/startup does not give you and the one that names the actual culprits. Captured under docs/output/: the step tree sorted both ways, the same startup as JFR events, a +5000-class experiment putting 0.11 ms per scanned class on the classpath scan tax, the silent truncation a 2048-step buffer performs, and JDK 25 AOT cache timings (6.93 s to 4.82 s). Post body and metadata live in post/. Moves the existing Actuator project into actuator-in-production/ so the repository holds one directory per article; the root README is now an index.
This commit is contained in:
66
spring-boot-startup-time/scripts/demo-what-helps.sh
Executable file
66
spring-boot-startup-time/scripts/demo-what-helps.sh
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env bash
|
||||
# The four things people reach for, measured on the same jar.
|
||||
#
|
||||
# no tracking : baseline, no ApplicationStartup installed
|
||||
# buffering : BufferingApplicationStartup(16384) -- what it costs to measure
|
||||
# jfr : FlightRecorderApplicationStartup + an active recording
|
||||
# lazy : spring.main.lazy-initialization=true
|
||||
# AOT cache : JDK 25 ahead-of-time cache (JEP 483/515), trained on this app
|
||||
set -uo pipefail
|
||||
source "$(dirname "$0")/env.sh"
|
||||
RUNS="${RUNS:-4}"
|
||||
|
||||
run_variant() { # run_variant <label> <extra args...>
|
||||
local label="$1"; shift
|
||||
local out=()
|
||||
for _ in $(seq 1 "$RUNS"); do
|
||||
"$ROOT/scripts/stop.sh"
|
||||
"$JAVA_HOME/bin/java" "$@" -jar "$JAR" > /tmp/helps.log 2>&1 &
|
||||
local pid=$!
|
||||
for _ in $(seq 1 240); do curl -fs -o /dev/null localhost:8080/actuator/health && break; sleep 0.5; done
|
||||
out+=("$(grep -ho 'in [0-9.]* seconds' /tmp/helps.log | head -1 | awk '{print $2}')")
|
||||
kill -9 $pid 2>/dev/null; wait $pid 2>/dev/null
|
||||
done
|
||||
# median of the runs
|
||||
local med
|
||||
med=$(printf '%s\n' "${out[@]}" | sort -n | awk '{a[NR]=$1} END {print (NR%2)? a[(NR+1)/2] : (a[NR/2]+a[NR/2+1])/2}')
|
||||
printf '%-34s | %-26s | %8s\n' "$label" "$(IFS=,; echo "${out[*]}")" "$med"
|
||||
}
|
||||
|
||||
printf '%-34s | %-26s | %8s\n' "variant" "Started in (s), each run" "median"
|
||||
printf -- '-----------------------------------+----------------------------+---------\n'
|
||||
|
||||
run_variant "no tracking" -Dstartup.tracking=none
|
||||
run_variant "BufferingApplicationStartup" -Dstartup.tracking=buffering
|
||||
run_variant "FlightRecorder + recording" -Dstartup.tracking=jfr \
|
||||
-XX:StartFlightRecording=filename=/tmp/helps.jfr,settings=profile,dumponexit=true
|
||||
run_variant "lazy-initialization" -Dstartup.tracking=none -Dspring.profiles.active=lazy
|
||||
|
||||
echo
|
||||
echo "=== JDK 25 AOT cache (Project Leyden) ==="
|
||||
"$JAVA_HOME/bin/java" -version 2>&1 | head -1
|
||||
rm -f /tmp/app.aotconf /tmp/app.aot
|
||||
|
||||
echo "-- training run (-XX:AOTMode=record) --"
|
||||
"$JAVA_HOME/bin/java" -XX:AOTMode=record -XX:AOTConfiguration=/tmp/app.aotconf \
|
||||
-Dstartup.tracking=none -jar "$JAR" > /tmp/aot-train.log 2>&1 &
|
||||
PID=$!
|
||||
for _ in $(seq 1 240); do curl -fs -o /dev/null localhost:8080/actuator/health && break; sleep 0.5; done
|
||||
curl -fs -o /dev/null localhost:8080/orders/summary || true
|
||||
kill -TERM $PID 2>/dev/null; wait $PID 2>/dev/null
|
||||
sleep 2
|
||||
ls -la /tmp/app.aotconf 2>/dev/null || { echo "no AOT configuration produced:"; tail -5 /tmp/aot-train.log; }
|
||||
|
||||
echo "-- assembly run (-XX:AOTMode=create) --"
|
||||
"$JAVA_HOME/bin/java" -XX:AOTMode=create -XX:AOTConfiguration=/tmp/app.aotconf \
|
||||
-XX:AOTCache=/tmp/app.aot -jar "$JAR" > /tmp/aot-create.log 2>&1
|
||||
tail -4 /tmp/aot-create.log
|
||||
ls -la /tmp/app.aot 2>/dev/null || echo "no cache produced"
|
||||
|
||||
echo
|
||||
if [ -f /tmp/app.aot ]; then
|
||||
run_variant "AOT cache (-XX:AOTCache)" -XX:AOTCache=/tmp/app.aot -Dstartup.tracking=none
|
||||
run_variant "AOT cache + lazy" -XX:AOTCache=/tmp/app.aot -Dstartup.tracking=none -Dspring.profiles.active=lazy
|
||||
fi
|
||||
"$ROOT/scripts/stop.sh"
|
||||
true
|
||||
Reference in New Issue
Block a user