5 Tips for Optimizing Java Performance on Kubernetes

Transcript

Do your instances devour cloud resources or CPU time? Do containers restart frequently for unknown reasons? Are response times suboptimal? Is it challenging to meet service level agreement?

If the answer is yes to any of these questions, these five tips may help you boost the performance of your Java apps in the cloud!

Tip 1. Set CPU and RAM limits properly

Set CPU and RAM limits based on the results of load testing, stress testing, Native Memory tracking data, and other relevant metrics such as memory usage inside the pod. In addition, you should take Kubernetes overhead into account. For instance, AWS Fargate adds 256 MB to each Pod's memory reservation for the required Kubernetes components. 

Tip 2. Configure Kubernetes probes correctly

Probes are essential for monitoring the health of your pod. But improper prob configuration may lead to unnecessary container restarts, unrequired vertical scaling, or other issues. 

Tip 3. Choose a small base image

Choose a small base image to reduce container image size. For instance, Liberica Runtime Container can help you reduce RAM consumption by up to 30%.

Tip 4. Select the right Garbage collector

Select a Garbage Collector tailored to your needs. HotSpot JVM offers a selection of garbage collectors for various purposes, such as ParallelGC for high throughput or ZGC for low latency. 

Tip 5. Reduce application startup and warmup time

Reduce startup and warmup time of your applications. Java services may take dozens of minutes to reach stable peak performance. During that period, they process way fewer requests. You can alleviate the situation by using AppCDS, GraalVM Native Image, or Coordinated Restore at Checkpoint.

Summary

If your Java apps in the cloud struggle with high resource consumption, frequent container restarts, or slow response times, these five tips can help enhance their performance. First, set CPU and RAM limits properly based on load testing and account for Kubernetes overhead. Additionally, configure Kubernetes probes accurately, use a small base image to optimize container size, choose a suitable garbage collector, and reduce application startup and warmup time to ensure faster performance.

About Catherine

Java developer passionate about Spring Boot. Writer. Developer Advocate at BellSoft

Social Media

Videos
card image
Jan 30, 2025
Dockerize Spring Boot Wisely: 6 tips to improve the container images of your Spring Boot apps

Your Spring Boot applications deserve a top-notch package!

Videos
card image
Jan 22, 2025
JEP 483: Ahead-of-Time Class Loading & Linking. Project Leyden in JDK 24

JEP 483 introduces Ahead-of-Time (AOT) Class Loading and Linking in JDK 24, which enhances Java application startup times by loading and linking classes ahead of time and storing them in a reusable AOT cache. This feature, part of Project Leyden, reduces the JVM's workload during startup without requiring changes to application code, though a training run mimicking production is needed to create an efficient cache. Early tests with a Spring Boot app showed significant improvements, cutting startup time from two seconds to just one second.

Further watching

Videos
card image
Feb 25, 2025
PF4J: Plugin Framework for Java. Plugin Systems for Backend

PF4J (Plugin Framework for Java) is a lightweight framework that allows developers to create modular applications using plugins. It enables the integration of custom code into applications through extension points, with support for lifecycle management and Spring integration for dependency injection. PF4J is useful for both desktop and web applications, offering flexibility in scaling and extending functionality without altering the core system.

Videos
card image
Feb 13, 2025
How to Profile Java Applications in Docker Containers with JFR

Java applications in Docker containers using Java Flight Recorder (JFR), a built-in OpenJDK tool. It covers three profiling methods: enabling JFR at application startup, attaching to a running container using an ephemeral container with jcmd, and monitoring real-time performance with JDK Mission Control via remote JVM connections.

Videos
card image
Feb 7, 2025
How to Create Dynamic SQL Queries with Spring Boot

Build SQL queries dynamically based on the user input with the Specification interface. Use the JPA Static Model Generator to create type-safe queries. Run the tests to check your application.