Files
Ankur Mhatre 958b401f0f 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.
2026-09-05 00:17:37 +05:30

48 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Boots with BufferingApplicationStartup, then dumps the step tree three ways:
# self time by phase, slowest steps by self time, and the same list by total time
# (which is what /actuator/startup would have you sort by).
set -uo pipefail
source "$(dirname "$0")/env.sh"
"$(dirname "$0")/stop.sh"
"$JAVA_HOME/bin/java" -Dstartup.tracking=buffering -jar "$JAR" > /tmp/startup-app.log 2>&1 &
PID=$!
for _ in $(seq 1 180); do curl -fs -o /dev/null localhost:8080/actuator/health && break; sleep 0.5; done
echo "=== Boot's own startup line ==="
grep -h 'Started StartupDiagnosisApplication' /tmp/startup-app.log | sed 's/^.*: //'
echo
echo "=== /diag/startup ==="
curl -s 'localhost:8080/diag/startup?top=12' > /tmp/diag.json
python3 - <<'PY'
import json
d = json.load(open('/tmp/diag.json'))
print(f"recorded steps: {d['recordedSteps']}\n")
print("-- self time by step name (self = duration minus direct children) --")
print(f"{'self ms':>9} {'count':>5} step")
for r in d['phasesBySelfTime']:
print(f"{r['selfMs']:9.2f} {r['count']:5d} {r['step']}")
def bean(t): return t.get('beanName') or t.get('classNames') or ''
print("\n-- slowest individual steps by SELF time (the culprits) --")
print(f"{'self ms':>9} {'total ms':>9} step / tags")
for r in d['slowestBySelfTime']:
print(f"{r['selfMs']:9.2f} {r['totalMs']:9.2f} {r['name']} {bean(r['tags'])}")
print("\n-- slowest individual steps by TOTAL time (the containers) --")
print(f"{'total ms':>9} {'self ms':>9} step / tags")
for r in d['slowestByTotalTime']:
print(f"{r['totalMs']:9.2f} {r['selfMs']:9.2f} {r['name']} {bean(r['tags'])}")
PY
echo
echo "=== actuator's own endpoint: GET peeks, POST drains ==="
for verb in GET POST POST GET; do
n=$(curl -s -X $verb localhost:8080/actuator/startup \
| python3 -c "import sys,json;print(len(json.load(sys.stdin).get('timeline',{}).get('events',[])))" 2>/dev/null || echo "-")
echo " $verb /actuator/startup -> events in response: $n"
done
kill -9 $PID 2>/dev/null
wait $PID 2>/dev/null
true