Optimization of Java Applications – CPU Usage, Memory Usage, Startup Time, Resource Efficiency
What possibilities exist to optimize JVM-based applications in terms of CPU usage, memory usage, startup time, resource efficiency, etc.?
Framework
Studies:
- Analyzing JVM Energy Consumption for JDK 17: An Empirical Study – Ionut Balosin
- Wyciślik et al. (2023). A Comparative Assessment of JVM Frameworks to Develop Microservices. https://doi.org/10.3390/app13031343
@Wycislik.etal.2023.ComparativeAssessmentJVM - Belgaid (2022). Green coding: an empirical approach to harness the energy consumption of software services. PHD Thesis. https://theses.hal.science/tel-04074973/
- Jeleń & Dzieńkowski (2021). The comparative analysis of Java frameworks: Spring Boot, Micronaut and Quarkus. https://doi.org/10.35784/jcsi.2724
Quarkus vs. Spring Boot
Quarkus has a much faster startup time and a lower memory usage.
Virtual Machine
How to optimize the runtime efficiency?
OpenJ9 vs. HotSpot
OpenJ9 requires less memory than OpenJDK with HotSpot.
Vergilio et al. (2023)
@Vergilio.etal.2023.ComparativePerformanceEnergy
Note: A benchmark suite case was used that focusses on concurrency workloads. The way of how the energy was measured is also questionable (workload inside WSL2, measurement tool on the Windows host system).
Belgaid (2022)
Belgaid developed a tool called JReferral that can help to find the most energy-efficient JVM configuration. For that it runs your Java program through multiple versions of JVMs and optimizations options.
Ournani et al. (2021)
Ournani, Z., Belgaid, M. C., Rouvoy, R., Rust, P., & Penhoat, J. (2021, October 11). Evaluating the Impact of Java Virtual Machines on Energy Consumption. 15th ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM). https://inria.hal.science/hal-03275286
The results of our investigations showed that many JVMs share energy efficiencies and can grouped into 3 classes: HotSpot, J9, and GraalVM. The 3 selected JVM classes can however report a different energy efficiency for different software and/or workloads, sometimes by a large margin. While we did not observed a unique champion when it comes to energy consumption, GraalVM reported the best energy efficiency for a majority of benchmarks. Nonetheless, each JVM can achieve the best or the worst depending on the hosted application.
JVM vs. Native
JVM vs. Native Java Compilation
CRaC, CDS, Project Leyden
Overview created by Sébastien Deleuze (source: LinkedIn)
Deployment Type
Minimize the size of your Docker images
The reference application (Spring-PetClinic 2.1.0) used in the experiments needs only 14 modules from a total of 74 modules that comprise OpenJDK 11. By using the Java Linker (jlink), the Java Runtime Environment was customized for the given Java application (Spring-PetClinic), thus enabling us to minimize the size of the resulting Docker image
Database
Database Performance Optimization
🔗 References
Reduce the cloud bill of your Java applications by Ioannis Kolaxis
How to write greener Java applications by Red Hat (→ use Quarkus)
Tradeoffs, Bad Science, and Polar Bears – The World of Java Optimisation By Holly Cummins