ON-DEMAND KUBERNETES WORKSHOP

Java on K8s: The Startup vs. Steady-State Sizing Dilemma

Java logo

TL;DR

Java pods need far more CPU and memory in their first few minutes than they ever use again, so sizing for startup wastes money all month, and sizing for steady state risks slow or failed boots. PerfectScale's init spike optimization gives each pod two recommendations: startup resources at boot, then an in-place resize down to steady state after about five minutes, with no restart. In the live demo, a pricing service dropped from 2 cores to 36 millicores after startup, cutting its estimated cost from about $152 to about $5 a month.

In this summary

Why the dilemma exists

Java pods use far more CPU and memory in their first few minutes than they will for the rest of their lives. That leaves you with a bad choice: size for the startup spike and pay for it on every replica all month, or size for steady state and watch pods crawl through boot or crash. In this session, Vikram Seshadri and Joshua Fox walk through why it happens, what you can fix in the JVM itself, and how PerfectScale sizes each phase separately with no restarts.

Joshua compares startup to a restaurant before the first customer: the soup goes on, the vegetables get chopped, the deliveries come in. Once orders start, the work looks completely different. A JVM pod behaves the same way. The first minutes are short and busy, and the weeks after are quiet.

If you size for the spike, the pod starts fine, but you pay for peak capacity forever. If you size for steady state, the pod probably won't start, or it will take a very long time. We cover the mechanics in JVM Startup CPU Throttling in Kubernetes, and the problem of sizing for the wrong phase in How to Fix Kubernetes Resource Policies That Optimize for the Wrong Phase.

Slide: sizing for one number loses either way. Size for the spike and you pay for peak on every pod all month; size for steady state and startup crawls or fails.

What drives the startup spike

Joshua lists the usual suspects: JIT compilation, class loading, framework initialization (scanning, proxies, dependency injection), connection pool warm-up, migrations, heap growth and the garbage collection it triggers, plus metadata, threads, and boot-time data. In PerfectScale's customer work, CPU often drops by about 75% after startup, while memory drops by about 33%.

Common offenders include Spring Boot, Hibernate, Tomcat and other app servers, Kafka, Spark, and Elasticsearch or OpenSearch. Joshua also shares a favorite example: an application that loaded its entire database into memory as a homegrown fast cache. It consumed roughly 200 GB and took up to ninety minutes to start. Five minutes is a typical startup window, but it varies.

Slide: where Java startup spikes show up, including Spring Boot, Hibernate, Tomcat, Kafka consumers, cache preloaders, and Elasticsearch.

If you want to find out where your own startup time goes, see How Do You Identify What Makes Your Service Expensive to Start? And to learn how to spot spikes that averages hide, read Kubernetes CPU Throttling & OOM Kills: Find Startup Spikes.

What you can do yourself first

Joshua recommends trying these before reaching for a tool: application class data sharing, less JIT compilation (with the trade-off in speed), lazy initialization (which pushes the wait to later), bounding the heap or container, and a startup probe that tolerates a slow boot. Each helps shrink the spike, but none removes the trade-off. For more on the Java side, see 5 Strategies to Optimize Java in 2026 and Java Garbage Collection in Kubernetes.

What it costs you

Joshua shows an anonymized customer example. A pod sized at 2,000m CPU used about a third of that on average, so roughly 71% of the reservation sat idle. After optimizing for the init spike, the steady-state request dropped to 500m. Memory shows a smaller gain: 41% reserved but unused, down to 18%.

Slide: CPU, same pod, two ways to size it. Without init spike optimization 71% of the request is reserved but unused; with it, 23%.

Slide: memory, same pod, two ways to size it. Without init spike optimization 41% is reserved but unused; with it, 18%.

Across 50 replicas, that's about 75 vCPUs and 25 GB reclaimed, or around $2,300 a month at typical cloud prices.

Slide: what init spike optimization frees up across a fleet of 50 replicas, with estimated monthly savings by replica count.

For more on how inflated requests add up, read Cost Problem with Overinflated Requests.

How PerfectScale solves it

PerfectScale calculates two recommendations for the same pod. The startup recommendation applies when the pod is created and covers the initialization window (about five minutes, and configurable). After that window, PerfectScale resizes the pod down to its steady-state recommendation, then keeps tuning as usage trends up or down.

Slide: two recommendations, one pod. The pod starts with the startup recommendation, stabilizes after about 5 minutes, keeps tuning, and shows a Spike icon in the UI.

This relies on in-place pod resize, which lets Kubernetes change a running pod's resources without replacing it. It's now stable in Kubernetes 1.35. Our In-Place K8s Workload Right-sizing announcement covers how it works, and Init Spike Handling: Right-Size JVM Pods for Boot and Run covers the feature itself. If you're weighing alternatives, see our look at the Vertical Pod Autoscaler.

PerfectScale applies init spike optimization only when all four conditions are met:

  • Automation is enabled for the workload.
  • In-place updates are enabled.
  • The startup recommendation is higher than the runtime recommendation.
  • The savings are large enough to be worth acting on.

Slide: init spike optimization applies when automation is enabled, in-place updates are enabled, the startup recommendation is higher than runtime, and the change is worth more than $1.

If any condition is missing, PerfectScale still does its regular long-term optimization. The feature suits JVM services (Spring Boot, plus Kotlin and Scala, which generate many classes), long-running fleets, and other runtimes with similar startup patterns. It doesn't suit workloads without a startup spike or short-lived jobs.

Live demo: the pricing service

Vikram demos a Spring Boot pricing service with three replicas at different ages. Before optimization, the service had a single 2-core request. After turning on init spike optimization and automation, PerfectScale showed separate init and runtime requests. Init stayed at about 2.1 cores, while runtime dropped to 36 millicores, 80 to 90% lower. A look at the pod YAML confirmed the older replicas had been resized in place to 36m.

He then compared three approaches over the first 15 minutes of pod life, estimated across three replicas:

  • Sized for peak: the pod is up in about a minute, but it costs roughly $152 a month for this workload.
  • Sized for steady state: the pod takes around ten minutes to come up, which risks late payments and dropped traffic.
  • Sized by PerfectScale: the pod starts with the right resources, resizes after five minutes, and costs about $5 a month.

Across hundreds of pods and several Java services or Kafka consumers, Vikram estimates $50 to $60k a year on m5.xlarge instances in EKS. To see the JVM heap, non-heap, and GC data PerfectScale collects, check out the Java containers docs.

Init spike optimization is in early preview with design partners and customers, with general availability coming soon.

Try it and what's next

You can try PerfectScale for free on a non-prod cluster, and learn more about how it handles Java optimization on Kubernetes. The session also announced the next webinar on November 17, Agentic Karpenter: Using kagent + Claude to Tune Your Autoscaling, with Ramesh, a principal consultant at AWS and Karpenter contributor.

Meet your speakers

Vikram Seshadri

Vikram Seshadri

Sr. Evangelist, DoiT

Vikram Seshadri spent eight years in platform engineering in the fintech space, including a stint as Senior Vice President leading EKS platform engineering at Citi. Now a Senior Evangelist for Enterprise Platforms at DoiT, he helps engineering teams solve the hard operational problems of running Kubernetes at scale: reliability, cost, and everything in between.

Joshua Fox

Joshua Fox

Senior Cloud Architect II, DoiT

Joshua Fox has spent two decades building and leading software architecture, from Mercury and IBM, where he drove the Guardium Redaction privacy system, to the startups Twiggle and Freightos. Now a Senior Cloud Architect at DoiT, he advises customers on everything from cloud architecture to weird bugs. He holds a PhD in Semitic Philology from Harvard.