Optimizing JVM performance with 'jstat'
What could you do if you realise no tools been instrumented for Jvm performance diagnosis and analysis !!
One of the solution is , 'jstat' - simple CLI based tool bundled along with jdk.
It's extremely useful in environments not managed, designed by you.
jstat provide various options for jvm/gc insights.
How to launch jstat:
Simply go to command line and run jstat commands.
Yes, That's it !!
Key usage of jstat:
Let's have a look at them one by one.
1. Real time GC monitoring
Help gain insights into young and full GC events, to assess if the application is spending too much time in garbage collection, which can indicate potential memory pressure.
How to check gc stats using jstat:
jstat -gc -t <pid> <time-interval(in ms)> <sample-count>
Example: jstat -gc -t 80594 1000 5
The complete output , stats capapcity/ size and utilisation of :
And provides old /young GC event and time it took for those events.
GC stats only: Last columns indicate GC stats:
For sake of simplicity which is much needed here, consider
suffix 'C' stands for capacity i.e. size and 'U' stands for Utilisation both metrics in KB
Different metrics can be interpreted as below:
2. JVM Memory utilisation:
How to check memory utilisation stats using jstat.
Basically same command as for gc stats only you need to focus on initial columns
jstat -gc -t <pid> <time-interval(in ms)> <sample-count>
Example: jstat -gc -t 80594 1000 5
The complete output , stats capapcity/ size and utilisation of :
Recommended by LinkedIn
3. Identify GC Cause:
jstat can also indicate gc cause for each event.
How to check this:
jstat -gccause -t <pid> <time-interval(in ms)> <sample-count>
Example: jstat -gccause -t 80594 1000 5
4. Class Loading:
Stats for the number of classes loaded and unloaded, help understand how dynamic class loading impacts memory usage.
How to check class loading stats
jstat -class <pid> <time-interval(in ms)> <sample-count>
Example: jstat -class 80594 100 10
Where:
5. Compilation stats
Statistics related to the Just-In-Time compiler's behavior, including compilation counts and times.
How to check JIT Compilation stats
jstat -compiler <pid> <time-interval(in ms)> <sample-count>
Example: jstat -compiler 80594 100 10
Pros:
Advantages of using jstats:
Limitations :
Things to keep in mind while relying on jstat:
Conclusion:
It's a powerful and handy tool. Shall be use while no jvm tool is configured and instrumented for diagnosis and analysis.