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.
72 lines
2.6 KiB
Bash
Executable File
72 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Quantifies what component scanning costs, by adding classes to the scanned package
|
|
# and changing nothing else.
|
|
#
|
|
# baseline : the application as committed
|
|
# +5000 plain : 5000 classes with no annotations -- pure scan cost
|
|
# +5000 @Component : the same 5000, now bean definitions -- scan + define + instantiate
|
|
# +5000 @Component, lazy : lazy init removes the instantiation, not the scan
|
|
#
|
|
# Each variant is a full rebuild. Budget about ten minutes.
|
|
set -uo pipefail
|
|
source "$(dirname "$0")/env.sh"
|
|
cd "$ROOT"
|
|
RUNS="${RUNS:-3}"
|
|
|
|
measure() { # measure <label> <extra java args...>
|
|
local label="$1"; shift
|
|
local started=() parse="" inst="" steps=""
|
|
for i in $(seq 1 "$RUNS"); do
|
|
"$ROOT/scripts/stop.sh"
|
|
"$JAVA_HOME/bin/java" -Dstartup.tracking=buffering "$@" -jar "$JAR" > /tmp/scan-app.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
|
|
started+=("$(grep -ho 'in [0-9.]* seconds' /tmp/scan-app.log | head -1 | awk '{print $2}')")
|
|
if [ "$i" = "1" ]; then
|
|
curl -s 'localhost:8080/diag/startup?top=1' > /tmp/scan-diag.json
|
|
read -r parse inst steps <<<"$(python3 - <<'PY'
|
|
import json
|
|
d = json.load(open('/tmp/scan-diag.json'))
|
|
p = {r['step']: r for r in d['phasesBySelfTime']}
|
|
print(p.get('spring.context.config-classes.parse', {}).get('selfMs', 0),
|
|
p.get('spring.beans.instantiate', {}).get('selfMs', 0),
|
|
d['recordedSteps'])
|
|
PY
|
|
)"
|
|
fi
|
|
kill -9 $pid 2>/dev/null; wait $pid 2>/dev/null
|
|
done
|
|
printf '%-26s | %-18s | %9s | %9s | %6s\n' \
|
|
"$label" "$(IFS=,; echo "${started[*]}")" "$parse" "$inst" "$steps"
|
|
}
|
|
|
|
hdr() {
|
|
printf '%-26s | %-18s | %9s | %9s | %6s\n' \
|
|
"variant" "Started in (s)" "parse ms" "instMs" "steps"
|
|
printf -- '---------------------------+--------------------+-----------+-----------+-------\n'
|
|
}
|
|
|
|
echo "runs per variant: $RUNS (first run of each also queried for phase self times)"
|
|
echo
|
|
hdr
|
|
|
|
./scripts/gen-bulk.sh 0 plain >/dev/null 2>&1 || true
|
|
rm -rf src/main/java/com/ankurm/startup/bulk
|
|
mvn -B -q -DskipTests package > /tmp/scan-build.log 2>&1
|
|
measure "baseline"
|
|
|
|
./scripts/gen-bulk.sh 5000 plain > /dev/null
|
|
mvn -B -q -DskipTests package > /tmp/scan-build.log 2>&1
|
|
measure "+5000 plain classes"
|
|
|
|
./scripts/gen-bulk.sh 5000 component > /dev/null
|
|
mvn -B -q -DskipTests package > /tmp/scan-build.log 2>&1
|
|
measure "+5000 @Component"
|
|
measure "+5000 @Component, lazy" -Dspring.profiles.active=lazy
|
|
|
|
rm -rf src/main/java/com/ankurm/startup/bulk
|
|
mvn -B -q -DskipTests package > /tmp/scan-build.log 2>&1
|
|
echo
|
|
echo "bulk package removed; jar rebuilt at baseline."
|
|
true
|