Add quarkus-vs-spring-ai module: the same support assistant (system prompt, tool, RAG) built with Quarkus LangChain4j and Spring AI against a stub OpenAI-compatible server, with wire-format capture, startup/memory benchmarks and a Quarkus native image

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b4XrpfdpsacrvqnrBM
This commit is contained in:
asmhatre
2026-11-27 00:08:03 +05:30
co-authored by Claude Sonnet 5.5
parent f4f90b3b30
commit 5e5326c810
46 changed files with 1395 additions and 0 deletions
+99
View File
@@ -0,0 +1,99 @@
#!/usr/bin/env python3
"""
Startup / memory / latency harness. Runs every app RUNS times against the stub LLM, interleaved
(quarkus, spring, quarkus, spring, ...) so both see the same background load.
RUNS=7 python3 scripts/bench.py # needs the stub on :18089 (scripts/start-stub.sh)
Measured per run:
t_port ms from process launch until the app's TCP port accepts a connection
t_first ms from process launch until GET /ask?q=... returns 200 (first answered request)
cpu_first CPU milliseconds (user+sys, from /proc) consumed by then; far less sensitive to a busy host than wall time
rss_first RSS in MiB right after that first answer
rss_after RSS in MiB after 300 further requests (a mix of tool, RAG and plain questions)
p50 / p95 latency in ms over those 300 sequential requests
The model is a local stub, so these numbers are framework overhead and nothing else.
"""
import os, socket, statistics, subprocess, sys, time, urllib.parse, urllib.request
RUNS = int(os.environ.get("RUNS", "5"))
PORT = int(os.environ.get("APP_PORT", "18080"))
STUB = "http://localhost:18089/v1"
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
QUESTIONS = ["Where is my order 1001?", "How many days do I have to return an item?", "What is the weather in Paris"]
APPS = {
"quarkus-jvm": ["java", f"-Dquarkus.http.port={PORT}", f"-Dquarkus.langchain4j.openai.base-url={STUB}",
"-jar", f"{ROOT}/quarkus-app/target/quarkus-app/quarkus-run.jar"],
"spring-jvm": ["java", f"-Dserver.port={PORT}", f"-Dspring.ai.openai.base-url={STUB}",
"-jar", f"{ROOT}/spring-ai-app/target/spring-ai-app-1.0.0.jar"],
}
NATIVE = f"{ROOT}/quarkus-app/target/quarkus-app-1.0.0-runner"
if os.path.exists(NATIVE):
APPS["quarkus-native"] = [NATIVE, f"-Dquarkus.http.port={PORT}", f"-Dquarkus.langchain4j.openai.base-url={STUB}"]
if os.environ.get("ONLY"):
APPS = {k: v for k, v in APPS.items() if k in os.environ["ONLY"].split(",")}
def rss_mib(pid):
for line in open(f"/proc/{pid}/status"):
if line.startswith("VmRSS"):
return int(line.split()[1]) / 1024
def cpu_ms(pid):
f = open(f"/proc/{pid}/stat").read().rsplit(")", 1)[1].split()
return (int(f[11]) + int(f[12])) * 1000 / os.sysconf("SC_CLK_TCK")
def ask(q):
with urllib.request.urlopen(f"http://localhost:{PORT}/ask?q=" + urllib.parse.quote(q), timeout=10) as r:
assert r.status == 200
return r.read()
def one_run(cmd):
t0 = time.perf_counter()
p = subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True)
try:
while True:
try:
socket.create_connection(("localhost", PORT), timeout=0.05).close()
t_port = (time.perf_counter() - t0) * 1000
break
except OSError:
time.sleep(0.005)
if time.perf_counter() - t0 > 90:
raise SystemExit("app did not start")
while True:
try:
ask(QUESTIONS[0]); break
except Exception:
time.sleep(0.005)
t_first = (time.perf_counter() - t0) * 1000
rss_first, cpu_first = rss_mib(p.pid), cpu_ms(p.pid)
lat = []
for i in range(300):
s = time.perf_counter()
ask(QUESTIONS[i % 3])
lat.append((time.perf_counter() - s) * 1000)
lat.sort()
return dict(t_port=t_port, t_first=t_first, cpu_first=cpu_first, rss_first=rss_first,
rss_after=rss_mib(p.pid), p50=lat[149], p95=lat[284])
finally:
p.kill(); p.wait()
time.sleep(1.0)
def main():
print(f"host: {os.cpu_count()} cpus, load average at start {os.getloadavg()[0]:.1f} (other processes were running)")
rows = {name: [] for name in APPS}
for _ in range(RUNS):
for name, cmd in APPS.items():
rows[name].append(one_run(cmd))
for name, rs in rows.items():
print(f"\n== {name} ({RUNS} runs)")
print(f"{'metric':10s} " + " ".join(f"{'run'+str(i+1):>7s}" for i in range(RUNS)) + f" {'median':>8s}")
for k in ["t_port", "t_first", "cpu_first", "rss_first", "rss_after", "p50", "p95"]:
vals = [r[k] for r in rs]
fmt = "{:7.1f}" if k in ("rss_first", "rss_after", "p50", "p95") else "{:7.0f}"
print(f"{k:10s} " + " ".join(fmt.format(v) for v in vals) + " " + fmt.format(statistics.median(vals)).rjust(8))
print(f"\nload average at end {os.getloadavg()[0]:.1f}")
main()
+21
View File
@@ -0,0 +1,21 @@
# Shared helpers. Everything uses ports 18080 (app) and 18089 (stub) so it does not fight a dev server on 8080.
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
STUB_URL="http://localhost:18089/v1"
Q_JAR="$ROOT/quarkus-app/target/quarkus-app/quarkus-run.jar"
S_JAR="$ROOT/spring-ai-app/target/spring-ai-app-1.0.0.jar"
STUB_JAR="$ROOT/stub-llm/target/stub-llm-1.0.0.jar"
# kill_jar <jar path>: kills by the jar's absolute path (never by a generic pattern like "spring-boot")
kill_jar() { for p in $(ps -eo pid,args | grep -F -- "$1" | grep -v grep | awk '{print $1}'); do kill -9 "$p" 2>/dev/null; done; }
start_stub() { # start_stub [record-dir]
kill_jar "$STUB_JAR"
local opts="-Dstub.port=18089"; [ -n "${1:-}" ] && opts="$opts -Dstub.record.dir=$1"
setsid nohup java $opts -jar "$STUB_JAR" > /tmp/stub-llm.log 2>&1 < /dev/null &
for i in $(seq 1 50); do curl -s localhost:18089/stats >/dev/null && return 0; sleep 0.2; done; return 1
}
start_quarkus() { setsid nohup java -Dquarkus.http.port=18080 -Dquarkus.langchain4j.openai.base-url=$STUB_URL -jar "$Q_JAR" > /tmp/quarkus-app.log 2>&1 < /dev/null & wait_app; }
start_spring() { setsid nohup java -Dserver.port=18080 -Dspring.ai.openai.base-url=$STUB_URL -jar "$S_JAR" > /tmp/spring-app.log 2>&1 < /dev/null & wait_app; }
wait_app() { for i in $(seq 1 300); do curl -s -o /dev/null "localhost:18080/ask?q=ping" && return 0; sleep 0.2; done; return 1; }
ask() { curl -s --get --data-urlencode "q=$1" localhost:18080/ask; echo; }
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# Regenerates everything in output/. Needs JDK 25 on PATH. The native step needs GraalVM 25 (set GRAALVM_HOME) and is skipped without it.
set -eu
source "$(dirname "$0")/lib.sh"
cd "$ROOT"
mvn -B -q install # tests write output/11,12,21,22
scripts/wire.sh > /dev/null # output/30-wire-summary.txt and output/wire/*
start_stub
RUNS="${RUNS:-7}" ONLY=quarkus-jvm,spring-jvm python3 scripts/bench.py > output/40-bench-jvm.txt
if [ -n "${GRAALVM_HOME:-}" ]; then
(cd quarkus-app && JAVA_HOME="$GRAALVM_HOME" PATH="$GRAALVM_HOME/bin:$PATH" mvn -B -q -DskipTests \
-Dquarkus.native.enabled=true -Dquarkus.native.native-image-xmx=3g package)
RUNS="${RUNS:-7}" ONLY=quarkus-native python3 scripts/bench.py > output/41-bench-native.txt
fi
kill_jar "$STUB_JAR"
ls -la output
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Starts the stub LLM on :18089 in the background (optional arg: directory to record request bodies into).
source "$(dirname "$0")/lib.sh"
start_stub "${1:-}"
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Captures the HTTP requests each framework sends to the "LLM" for the same two questions.
set -u
source "$(dirname "$0")/lib.sh"
OUT="$ROOT/output/wire"; mkdir -p "$OUT/quarkus" "$OUT/spring"
for side in quarkus spring; do
rm -f "$OUT/$side"/*.json
start_stub "$OUT/$side" || { echo "stub failed"; exit 1; }
if [ $side = quarkus ]; then start_quarkus; else start_spring; fi
rm -f "$OUT/$side"/*.json && curl -s localhost:18089/stats >/dev/null # drop the readiness probe
ask "Where is my order 1001?" > /dev/null
ask "How many days do I have to return an item?" > /dev/null
[ $side = quarkus ] && kill_jar "$Q_JAR" || kill_jar "$S_JAR"
kill_jar "$STUB_JAR"; sleep 1
done
python3 "$ROOT/scripts/wire_summary.py" "$OUT" > "$ROOT/output/30-wire-summary.txt"
cat "$ROOT/output/30-wire-summary.txt"
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
"""Summarises the recorded chat requests of both apps: shape, tool declaration, and prompt text."""
import glob, json, sys
root = sys.argv[1]
def load(side):
return [json.load(open(f)) for f in sorted(glob.glob(f"{root}/{side}/*-chat.json"))]
def show(side, reqs):
print(f"##### {side}: {len(reqs)} chat requests for 2 questions")
for i, r in enumerate(reqs, 1):
print(f"--- request {i}: top-level keys = {sorted(r)}")
for m in r["messages"]:
c = m.get("content")
if isinstance(c, list):
c = "".join(p.get("text", "") for p in c)
extra = f" tool_calls={json.dumps(m['tool_calls'])}" if m.get("tool_calls") else ""
print(f" [{m['role']}] {str(c)[:110]!r}{extra}")
if r.get("tools"):
print(" tools:", json.dumps(r["tools"], sort_keys=True))
print()
q, s = load("quarkus"), load("spring")
show("quarkus", q)
show("spring", s)
qt = [r["tools"] for r in q if r.get("tools")][0]
st = [r["tools"] for r in s if r.get("tools")][0]
print("tool declaration identical:", qt == st)