Video in progress
After every deploy or scale-up, the new pods respond slowly in their first minute and p99 spikes. What is the cause, and how do you get a new Java pod ready for traffic?
A new JVM is "cold": code is still interpreted, the JIT hasn't had time to compile, classes aren't loaded, and the connection pool and caches are empty. What helps: warm-up before traffic, slow start on the load balancer, and a CDS/AOT cache that speeds up startup.
📖 Answer
As soon as a new pod passes readiness, the load balancer gives it its full share. The first thousands of requests:
- run in the interpreter or in C1, several times slower;
- JIT compilation keeps the CPU busy (and if the CPU limit is low, throttling);
- Hibernate, Jackson serializers and proxies get created on the first call;
- HikariCP is at its minimum connections and the HTTP client pool is empty, and every new TLS connection takes extra time.
If you add one cold pod to a 10-pod service, that is 10% of requests, enough to push p99 up.
What I do:
- Warm-up before readiness. Boot doesn't switch readiness to
ACCEPTING_TRAFFICuntil theApplicationRunners finish, and I use that:
@Component
class WarmUp implements ApplicationRunner {
private final PricingService pricing;
WarmUp(PricingService pricing) { this.pricing = pricing; }
@Override
public void run(ApplicationArguments args) {
for (int i = 0; i < 500; i++) {
pricing.quote(SampleData.cart()); // paths with no side effects
}
}
}
The startup probe limit has to leave room for the warm-up time too.
-
Slow start. Let the load balancer ramp traffic up to a new endpoint gradually:
warmupDurationSecsin Istio/Envoy, slow start on an AWS ALB. The JIT warms up under real load, but step by step. -
Speeding up startup. AppCDS (convenient since Boot 3.3 with
-Djarmode=tools extract), and the AOT cache in Java 24 (JEP 483), which does class loading and linking ahead of time. In Java 25, JEP 515 also added method profiles to the AOT cache, so the JIT warms up faster. The more drastic options are CRaC or a native image, but they have a different price. -
CPU. During startup the JVM asks for a lot of CPU. If the limit is low, the warm-up stretches to minutes. Set
requestsfor the average load and the limit with headroom for startup (or set no CPU limit at all).
Measure first: a latency graph by pod age (the first 5 minutes and after). If the difference is big, you need warm-up.
Sign up to mark studied questions and save your progress.