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 June 2023
JProfiler
|
Get rid of your performance problems and memory leaks!
|
JProfiler
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 271 contents
https://foojay.io/today/writing-a-profiler-from-scratch-the-profiling-loop/
Writing a Profiler from Scratch: The Profiling Loop (Page last updated January 2023, Added 2023-06-27, Author Johannes Bechberger, Publisher foojay.io). Tips:
- If you only sample currently running threads, then you have cpu-time profiling; if you sample all threads (both running and idle), you have wall-clock profiling.
- CPU profiling is useful when you know you're bottlenecked on CPU; Wallclock profiling is useful when CPU utilisation seems low but you still have performance issues.
- With wall-clock profiling, the list of threads can be so large that sampling all threads is too costly. So instead sample a random subset of available threads (async-profiler, for example, takes 8).
https://www.youtube.com/watch?v=SovDuQefCys
How to write fast Java code - thinking about memory (Page last updated February 2023, Added 2023-06-27, Author Anders Peterson, Publisher JFokus). Tips:
- When scaling to achieve the same operations, small scale implementations may need different algorithms than the large scale implementations if you want optimal efficiency, especially when considering parallelization.
- If you can optimize your memory usage and algorthims to stay as much as possible in the CPU cache, you will get better performance. The target is to have data already in the cache if at all possible.
- Common causes of CPU cache misses: wrong algorithms, inefficient data layout, allocations, context switches.
- The order of nested loops (inner to outer) for array operations can make a huge one or two orders of magnitude difference in speed.
- Caching values that are repeatedly accessed in a local variable means the memory access is held in the fastest CPU cache so has optimal speed.
- Primitive operations (eg int) are much more efficient than object operations (eg Integer). Avoid autoboxing.
https://www.youtube.com/watch?v=aoymwYqmozg
Sensible JVM Configuration (Page last updated January 2023, Added 2023-06-27, Author Kirk Pepperdine, Publisher JChampions Conference). Tips:
- -XX:PrintFlagsFinal shows you all the JVM options and the values they have in the current JVM after JVM initialization.
- Start with the JVM default values, then change one option at a time and see the effect on your application, starting with heap size, garbage collector, helper threads.
- The JVM configuration defaults depend on the JVM version but also the hardware or container the JVM is running on, so the defaults are not the same for every JVM instance.
- Memory configuration is usually non-optimal: too small increases application tail latency, too big wastes money (paying for more memory than was needed). Try hard to right-size the memory .
- You want to minimize the objects being promoted to the old generation. A good tenured size starting point is twice the live data set size. The young generation by default is smaller than the old generation, but setting it larger than old gen is a valid choice for some types of applications. .
- The GC pause frequency is related to young generation size and allocation rate.
- Be aware of the heap sizing options that change when the container size is changed (like -XX:MaxRamPercentage) and those that don't (like -Xmx). Choose the appropriate options for your system - if the container sizes are very stable, selecting the latter gives you better control, but if container sizes will change, the former let's your JVM size according the container size.
Jack Shirazi
Back to newsletter 271 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/newtips271.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us