Java Performance Tuning
Java(TM) - see bottom of page
Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks!
Training online: Concurrency, Threading, GC, Advanced Java and more ...
Tips December 2024
|
JProfiler
|
|
Get rid of your performance problems and memory leaks!
|
|
JProfiler
|
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 289 contents
https://www.youtube.com/watch?app=desktop&v=udFJm7u0Pv0
GC Tuning: Fortune 500 Case Studies on Cutting Costs and Boosting Performance (Page last updated October 2024, Added 2024-12-28, Author Ram Lakshmanan, Publisher yCrash). Tips:
- Tuning the GC can reduce latencies of requests, reduce CPU overheads, and reduce costs by allowing apps to run on fewer resources.
- To tune GC you need to monitor KPIs: avg gc pause time, max gc pause time, GC throughput, JVM memory size, JVM CPU time, Request response times (which is the most important).
- To tune GC you should use GC logging (-Xlog:gc*:file=FILEPATH) to analyse GC performance.
- GC logs analysis tools: https://fasterj.com/tools/gcloganalysers.shtml.
- To tune GC you should change one GC setting at a time, ensure you are testing in production (after basic validation in test), and run for at least a day.
- To tune GC you should: 1. start from scratch (no GC options); 2. address GC pause causes to choose initial options; 3. disable explicit GC (-XX:+DisableExplicitGC); 4. resize the overall heap; 5. resize the generations; 6. choose the GC algorithm (from parallel, G1, ZGC, Shenandoah, or exceptionally serial and CMS); 7. fine tune the GC algorithm using the most common options for each algorithm; 8. allocate sufficient system resources (RAM, CPU, cores, avoid swapping); 9. tune code to reduce object creation and memory usage.
https://www.youtube.com/watch?v=aRKKDN0EXuo
Quick off the blocks! rapid start options for your Java application (Page last updated November 2024, Added 2024-12-28, Author Akihiro Nishikawa, Publisher JCConf Taiwan). Tips:
- Java application startup has 3 Phases: JVM Startup (quite fast), application startup (slower than JVM startup), application warmup (takes the longest time - to reach peak performance).
- There are several options to improve Java startup time. The best choice depends on the specific application's characteristics and requirements. Using a compiled image is the fastest but has limitations. CRaC is very fast but has restrictions. CDS is a good general-purpose option.
- Simply extracting the JAR file (unpackaging it) can provide a small (5%+) improvement compared to running the JAR directly.
- JLink reduces the JRE size, improving class file loading speed. You can achieve a 5% startup speedup with a reduced JRE but it doesn't reduce application class loading time.
- CDS (Class Data Sharing) allows for significantly faster startup. JAR-based CDS is recommended over class-based CDS (ie do not unpack the jars, that opposes the CDS optimizations). CDS has three improved phases default, dynamic, and static; combining these gives best performance, but only slightly better than static.
- Tiered compilation (using both C1 and C2 compilers) is the default. Configuring to use only C1 (-XX:TieredStopAtLevel=1) disables C2 compilation, which reduces startup overhead. This can be better for very short-lived applications. AWS Lambda recommends this for custom Java runtimes. CDS is generally recommended for faster startup over using only C1.
- Ahead-of-time (AOT) compilation to generate a native image significantly improves startup time, but results in many restrictions on the application so is not suitable for many applications.
- CRaC (Coordinated Restore at Checkpoint) takes a snapshot of the application at a specific point (which can even be after peak performance has been reached), allowing for faster restarts. This provides very fast startup but has restrictions: open files and sockets must be closed before checkpointing, privileged operations may be required (problematic for some container platforms).
https://www.youtube.com/watch?v=ObKfGsJA-aQ
Introduction to Java Performance Tuning (Page last updated November 2024, Added 2024-12-28, Author Sunny Chan, Publisher JCConf Taiwan). Tips:
- High throughput does not mean low latency. Throughput is how many requests per second the system processes, latency is how long a request takes to process. Throughput can be increased by adding more servers independently of latency. Lowering latency does tend to improve throughput.
- Performance characteristics to consider: availability, memory efficiency, disk usage, network usage, datastore usage, scaling (vertical and horizontal) capability.
- Performance testing should use a workload as similar to production as possible (replaying production requests is one great option). It should be a reproducible test. For latency measurements, measure both average and various percentiles, eg 95%, 99%, etc. Ensure to include performance spikes.
- Microbenchmarks have many pitfalls. Avoid them, but if needed use JMH which handles warmups, JIT compiler efficiencies, etc.
- Useful free tools for analyzing performance include Java Flight Recorder, AsyncProfiler. These two are sampling profilers. Instrumentation profilers (which transform bytecodes) can be useful, especially for distributed tracing or focusing on a specific issue. OpenTelemetry is a good option for distributed tracing.
- "Fast" can mean a lot of different things, make sure you know what it means for your system before you start tuning or you could be tuning the wrong thing.
Jack Shirazi
Back to newsletter 289 contents
Last Updated: 2025-12-25
Copyright © 2000-2025 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
URL: http://www.JavaPerformanceTuning.com/news/newtips289.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us