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 May 2023
JProfiler
|
Get rid of your performance problems and memory leaks!
|
JProfiler
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 270 contents
https://www.youtube.com/watch?v=wT1QJ3JHBIM
"Show Me the Garbage!", Garbage Collection a Friend or a Foe (Page last updated April 2023, Added 2023-05-26, Author Haim Yadid, Publisher NLJUG). Tips:
- Garbage collectors have 3 KPIs: CPU & wall clock time overheads; memory overhead; pause probability and durations.
- Garbage collection algorithms tend to start with determining a root set - that set of objects reachable from outside the application. The time taken to find this is usually dependent on the number of threads. Then the object graph is traced, with a time taken dependent on the number of live objects. Finally memory is managed - ideally to avoid fragmentation.
- Multi-generation garbage collectors tend to be more efficient as most objects don't live long. So collecting those early in a young generation using a fast but not necessarily complete collection get's rid of most garbage with lower overhead. Then a more complete multi-generation collector can clean the remainder less efficiently but more thoroughly.
- A concurrent garbage collector can still pause the application, but has a much lower probability of doing so. However they are competing for resources with the application and are racing to collect garbage quickly enough before the application generates too much for it to get too far behind.
- Garbage collector properties: compacting, regional, generational, (mostly) concurrent, target: Serial (compacting and generational, targets small heaps, single CPUs); Parallel (compacting and generational, targets high throughput); G1 (compacting, regional, generational, mostly concurrent, targets average applications with pauses acceptable of 100ms); ZGC (compacting, regional, concurrent, targets large heaps pauses acceptable of 1ms); Shenandoah (compacting, regional, concurrent, targets large heaps pauses acceptable of 1ms); .
- ZGC and Shenandoah need more memory and CPU resources than other garbage collectors, so the low pauses come at a higher resource cost.
- Use GC logging: -Xlog:gc=info:time,uptime,level... Logs lines are usually "when it happened", "what happened", "what memory changed", "how long it took".
- If GC overhead is too high, the solution is to increase the heap size (or try a different collector).
- If latency (pause time) is too high, use the latest JVM and try one of the low pause collectors but expect to need more resources.
- If you have performance problems from having huge objects regularly collected, you need to tune the region sizes or try a different garbage collector.
- If your long-lived objects use more space than is available in the old generation, the old generation needs to be made big enough to hold them.
- Answer these questions: the heap size, the GC overhead, max pause time, number of collections above your pause time target, live set size, the allocation rate.
https://www.youtube.com/watch?v=hHhmn2Sk2Z0
A Glance At The Java Performance Toolbox (Page last updated April 2023, Added 2023-05-26, Author Ana-Maria Mih?lceanu, Publisher Voxxed Days Bucharest). Tips:
- To minimize container size, you can use a stripped base image (eg jre-slim) and install the minimum that is needed for your application.
- jlink let's you generate custom stripped JREs which can be the smallest runtime possible for your application (though note that if you strip our serviceability tooling, like jcmd, you will have difficulty troubleshooting the resulting JVM). jdeps let's you find the minimum set of modules the stripped image needs to run your application.
- jcmd can obtain statistics from the running JVM (eg GC stats), but running jcmd too often adds an overhead to the JVM.
- Only enable -XX:NativeMemoryTracking when needed, as it adds significant overhead to the JVM.
- You can trigger a heapdump using any JMX client (eg jconsole).
- jstat gets statistics from the running JVM.
- jmap let's you get heap histograms and heap dumps from a running JVM.
- JFR recordings can be enabled and let you investigate performance. You can stream the JFR recording out of the JVM.
https://medium.com/javarevisited/reduce-network-calls-in-a-java-applications-8d018b2f4d3b
Reduce network calls in a Java applications (Page last updated March 2023, Added 2023-05-26, Author Srikanth Dannarapu, Publisher Javarevisited). Tips:
- Cache network calls where the data from a previous call can suffice, for at least some time/some calls. Cache element expiration can be time based or based on some other invalidation criteria.
- Batch network calls where there will be multiple calls to an endpoint and the calls can wait a tiny amount of time. This reduces roundtrips and improves network efficiency.
- Compressing data before sending it on the network reduces the amount of data transmitted.
- Asynchronous calls allows the application to continue executing while a network call is in progress. This reduces the amount of time the application spends blocked.
- Optimize your database queries to eliminate unnecessary data transfer and minimize the amount of data retrieved.
- Review the network calls to see if any are completely unnecessary, and eliminate those.
Jack Shirazi
Back to newsletter 270 contents
Last Updated: 2025-01-27
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/newtips270.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us