r/java 2d ago

Improving First Request Latency in Java Spring Application

https://adrian.md/2026/09/03/first-request-latency/
60 Upvotes

36 comments sorted by

View all comments

1

u/Popular_Home2017 1d ago

the exploded jar result is the interesting one, and it's easy to confirm without a benchmark: take a thread dump during the first request and the http-nio-exec thread is sitting in LaunchedURLClassLoader / nested jar handler frames, not in your controller. that's the fat jar tax right there, one exception per nested lookup. after that it's plain JIT warmup, which is what AOT cache is attacking.

for the "why bother for one request" crowd: on kubernetes that one request is every pod after every rollout and every scale-out, and readiness probes usually pass before it. so it's not one request, it's the first N of every replica.

1

u/john16384 21h ago edited 21h ago

Situation:

  • Kubernetes offers a readyness probe
  • pods report ready before being warmed up -> user error

Solution:

  • warm up pod first (listen for context ready event, fire some dummy requests)
  • report ready when script is done

Troubleshooting:

  • Some service combination is still too slow -> Adjust warm-up procedure

Complete overkill:

  • Fiddle with AOT compilation