SlideShare a Scribd company logo
A Glance at
The Java Performance
Toolbox
Java Champion Alumni, Certified Architect
Senior Developer Advocate at Oracle
Passionate about solving complex scenarios involving
Java and Kubernetes.
ammbra1508 ammbra1508.mastondon.social
Using the JDK Tools for
Containerized Applications
 A Glance At The Java Performance Toolbox.pdf
 A Glance At The Java Performance Toolbox.pdf
Tools to build an OCI Compliant Image
• Docker build
• Buildpacks
• Jib
• kaniko
• buildah
• s2i
• And many more J
The Good Old Dockerfile
The Good Old Dockerfile
Use a small base image
The Good Old Dockerfile
Use a small base image
Create images with common layers
The Good Old Dockerfile
Use a small base image
Install only what is strictly needed
Create images with common layers
Creating Custom Java
Runtimes for Container
Images
Jlink
JEP 282 “Link time is an opportunity to do whole-world optimizations that are
otherwise difficult at compile time or costly at run-time”
jlink: Command Line Tool to Link Modules
• Modules in a jimage file
• Generate runtime images
Jlink Packaging
Legacy JDK image
JDK > 9 generated image
bin jre lib
bin conf ……..
Modular runtime image
jlink
Maintain The Good Old Dockerfile with JLink
The runtime stage build
• From a JDK base image
• Create your own custom JRE with jlink
Maintain The Good Old Dockerfile with JLink
The runtime stage build
• From a JDK base image
• Create your own custom JRE with jlink
The application stage build
• From an OS base image
• Copy the custom JRE from the runtime stage build
• Copy the artifacts needed by your application
• Run the application
The Runtime Stage Build
The Runtime Stage Build
The Runtime Stage Build
jdeps --ignore-missing-deps -q -recursive 
--multi-release 20 --print-module-deps 
--class-path 'target/libs/*’ 
target/spring-todo-app.jar
The Runtime Stage Build
The Runtime Stage Build
Strips debug information from the output image
The Runtime Stage Build
The Runtime Stage Build
Exclude man pages and header files
The Runtime Stage Build
z
The Runtime Stage Build
Enable compression of resources:
0: No compression
1: Constant string sharing
2: ZIP
The Application Stage Build
Copy the custom JRE
The Application Stage Build
Copy the artifacts needed by your application
The Application Stage Build
Run the application
Fine Tuning JVM Flags
Tracking Native Memory With Jcmd
Tracking Native Memory With Jcmd
Add jdk.jcmd module
Tracking Native Memory With Jcmd
WARNING: Overusing jcmd to send diagnostic commands can affect the performance of the VM.
Tracking Native Memory With Jcmd
WARNING: Overusing jcmd to send diagnostic commands can affect the performance of the VM.
Add -XX:NativeMemoryTracking={off|summary|detail} to JDK_JAVA_OPTIONS
• kubectl set env deployment/app JDK_JAVA_OPTIONS=“-XX:NativeMemoryTracking=summary”
• Please consider that having NMT enabled can add application performance overhead.
Tracking Native Memory With Jcmd
WARNING: Overusing jcmd to send diagnostic commands can affect the performance of the VM.
Add -XX:NativeMemoryTracking={off|summary|detail} to JDK_JAVA_OPTIONS
Create a native memory baseline
kubectl exec pod_name –it --/bin/bash -c "jcmd llvmid VM.native_memory baseline"
Tracking Native Memory With Jcmd
WARNING: Overusing jcmd to send diagnostic commands can affect the performance of the VM.
Add -XX:NativeMemoryTracking={off|summary|detail} to JDK_JAVA_OPTIONS
Create a native memory baseline
kubectl exec pod_name –it --/bin/bash -c "jcmd llvmid VM.native_memory baseline"
Create a native memory summary diff
kubectl exec pod_name –it --/bin/bash -c "jcmd llvmid VM.native_memory summary.diff"
Enabling JMX Monitoring and Remote Access
to a Remote Host
Get Statistics About
Running Java Processes
Obtain Statistics with Jstat and Jmap
Obtain statistics about garbage collectors by running jstat
kubectl exec pod_name –it --/bin/bash -c "jstat -gcutil llvmid 500 50"
Obtain Statistics with Jstat and Jmap
Obtain statistics about garbage collectors by running jstat
kubectl exec pod_name –it --/bin/bash -c "jstat -gcutil llvmid 500 50"
Print heap summaries
kubectl exec pod_name –it --/bin/bash -c "jmap -histo llvmid"
Capture Performance
Relevant JVM And
Application Events
Add JFR To Your Container Image
Enable JFR
Enable JFR in JDK_JAVA_OPTIONS
kubectl set env deployment/app JDK_JAVA_OPTIONS=“--XX:StartFlightRecording:..”
Use the diagnostic command:
kubectl exec pod_name –it --/bin/bash -c "jcmd 1 JFR.start…"
Start JFR
Enable JFR in JDK_JAVA_OPTIONS
kubectl set env deployment/app JDK_JAVA_OPTIONS=“--XX:StartFlightRecording:..”
Start a Time Fixed Recording with profile settings
-XX:StartFlightRecording=delay=10s,duration=10m,name=Profiling,settings=profile
Start JFR
Enable JFR in JDK_JAVA_OPTIONS
kubectl set env deployment/app JDK_JAVA_OPTIONS=“--XX:StartFlightRecording:..”
Start a Time Fixed Recording with profile settings
-XX:StartFlightRecording=delay=10s,duration=10m,name=Profiling,settings=profile
Start a Time Fixed Recording with default settings
-XX:StartFlightRecording=delay=10s,duration=10m,name=Default,settings=default
Start JFR
Enable JFR in JDK_JAVA_OPTIONS
kubectl set env deployment/app JDK_JAVA_OPTIONS=“--XX:StartFlightRecording:..”
Start a Time Fixed Recording with profile settings
-XX:StartFlightRecording=delay=10s,duration=10m,name=Profiling,settings=profile
Start a Time Fixed Recording with default settings
-XX:StartFlightRecording=delay=10s,duration=10m,name=Default,settings=default
Start a Continous Recording
-XX:StartFlightRecording:filename=/recordings/recording.jfr,settings=profile
Where to Use JFR Streaming
Streaming selected metrics to your monitoring service
Send an average, min, max, etc of a metric
Expose JFR data through other management APIs
Where NOT to Use JFR Streaming
“To consume the data today, a user must start a recording, stop it, dump the
contents to disk and then parse the recording file. This works well for
application profiling, where typically at least a minute of data is being
recorded at a time, but not for monitoring purposes.“
source: JEP 349
Make your settings by extending
jdk.jfr.SettingControl
Recording Custom
JFR Events
Make your settings by extending
jdk.jfr.SettingControl
Create your custom event by extending
jdk.jfr.Event
Recording Custom
JFR Events
Recording Custom
JFR Events
Make your settings by extending
jdk.jfr.SettingControl
Create your custom event by extending
jdk.jfr.Event
Register the custom settings in your custom
event via
@jdk.jfr.SettingsDefinition
Recording Custom Events in Spring Boot
(example)
Capture the custom JFR events in a dedicated filter and register it
Recording Custom Events in Spring Boot
(example)
Listen the custom JFR events and record their duration
Thank You!
https://github.com/ammbra/performance-glance
Useful Links
• Article https://www.javaadvent.com/2022/12/a-sneak-peek-at-the-java-performance-toolbox.html
• Tools https://docs.oracle.com/en/java/javase/20/docs/specs/man/index.html
• jlink https://dev.java/learn/jlink/
• Troubleshoot Memory Leaks: https://docs.oracle.com/en/java/javase/20/troubleshoot/troubleshooting-memory-
leaks.html
• JFR Runtime guide : https://docs.oracle.com/javacomponents/jmc-5-4/jfr-runtime-guide/about.htm#JFRUH170
• Innovative JFR use by @gunnarmorling: https://www.morling.dev/blog/finding-java-thread-leaks-with-jdk-flight-
recorder-and-bit-of-sql/
• @gunnarmorling article on custom JDK Flight Recorder Events
• Great intro by @BillyKorando https://www.youtube.com/watch?v=K1ApBZGiT-Y
• Stack walker episode by @BillyKorando: https://inside.java/2023/05/14/stackwalker-02/

More Related Content

PDF
A Glance At The Java Performance Toolbox-TIA.pdf
PDF
A Glance At The Java Performance Toolbox.pdf
PDF
A Glance At The Java Performance Toolbox.pdf
PDF
A Glance At The Java Performance Toolbox
PDF
A Glance At The Java Performance Toolbox
PDF
Commit to excellence - Java in containers
PPTX
JPrime_JITServer.pptx
PPTX
Javaland_JITServerTalk.pptx
A Glance At The Java Performance Toolbox-TIA.pdf
A Glance At The Java Performance Toolbox.pdf
A Glance At The Java Performance Toolbox.pdf
A Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
Commit to excellence - Java in containers
JPrime_JITServer.pptx
Javaland_JITServerTalk.pptx

Similar to A Glance At The Java Performance Toolbox.pdf (20)

ODP
Cloud Native Java Development Patterns
PPTX
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"
PDF
JITServerTalk-OSS-2023.pdf
PDF
ContainerWorkloadwithSemeru.pdf
PDF
JITServerTalk Nebraska 2023.pdf
PPTX
Are you ready for cloud-native Java?
PDF
JVMs in Containers
PDF
Java-light-speed NebraskaCode.pdf
PDF
USAA Mono-to-Serverless.pdf
PDF
JITServerTalk JCON World 2023.pdf
PDF
DevNexus 2024: Just-In-Time Compilation as a Service for cloud-native Java mi...
PDF
Java and Containers - Make it Awesome !
PDF
JITServerTalk.pdf
PDF
JVMs in Containers - Best Practices
PDF
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
PDF
Master your java_applications_in_kubernetes
PDF
Performance Monitoring with Java Flight Recorder on OpenJDK [DEV2406]
PPTX
Considerations when deploying Java on Kubernetes
PDF
Java Performance and Using Java Flight Recorder
PDF
Cloud-native Java EE-volution
Cloud Native Java Development Patterns
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"
JITServerTalk-OSS-2023.pdf
ContainerWorkloadwithSemeru.pdf
JITServerTalk Nebraska 2023.pdf
Are you ready for cloud-native Java?
JVMs in Containers
Java-light-speed NebraskaCode.pdf
USAA Mono-to-Serverless.pdf
JITServerTalk JCON World 2023.pdf
DevNexus 2024: Just-In-Time Compilation as a Service for cloud-native Java mi...
Java and Containers - Make it Awesome !
JITServerTalk.pdf
JVMs in Containers - Best Practices
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
Master your java_applications_in_kubernetes
Performance Monitoring with Java Flight Recorder on OpenJDK [DEV2406]
Considerations when deploying Java on Kubernetes
Java Performance and Using Java Flight Recorder
Cloud-native Java EE-volution
Ad

More from Ana-Maria Mihalceanu (20)

PDF
Empower Inclusion Through Accessible Java Applications
PDF
Java 25 and Beyond - A Roadmap of Innovations
PDF
Sécuriser les Applications Java Contre les Menaces Quantiques
PDF
Des joyaux de code natif aux trésors Java avec jextract
PDF
From native code gems to Java treasures with jextract
PDF
Exciting Features and Enhancements in Java 23 and 24
PDF
Monitoring Java Application Security with JDK Tools and JFR Events
PDF
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
PDF
From native code gems to Java treasures with jextract
PDF
Monitoring Java Application Security with JDK Tools and JFR Events
PDF
Java 23 and Beyond - A Roadmap Of Innovations
PDF
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
PDF
Monitoring Java Application Security with JDK Tools and JFR Events
PDF
Java 22 and Beyond- A Roadmap of Innovations
PDF
Surveillance de la sécurité des applications Java avec les outils du JDK e...
PDF
Monitoring Java Application Security with JDK Tools and JFR Events.pdf
PDF
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
PDF
Java 21 Language Features and Beyond
PDF
From Java 17 to 21- A Showcase of JDK Security Enhancements
PDF
Java 21 and Beyond- A Roadmap of Innovations
Empower Inclusion Through Accessible Java Applications
Java 25 and Beyond - A Roadmap of Innovations
Sécuriser les Applications Java Contre les Menaces Quantiques
Des joyaux de code natif aux trésors Java avec jextract
From native code gems to Java treasures with jextract
Exciting Features and Enhancements in Java 23 and 24
Monitoring Java Application Security with JDK Tools and JFR Events
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
From native code gems to Java treasures with jextract
Monitoring Java Application Security with JDK Tools and JFR Events
Java 23 and Beyond - A Roadmap Of Innovations
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
Monitoring Java Application Security with JDK Tools and JFR Events
Java 22 and Beyond- A Roadmap of Innovations
Surveillance de la sécurité des applications Java avec les outils du JDK e...
Monitoring Java Application Security with JDK Tools and JFR Events.pdf
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
Java 21 Language Features and Beyond
From Java 17 to 21- A Showcase of JDK Security Enhancements
Java 21 and Beyond- A Roadmap of Innovations
Ad

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
KodekX | Application Modernization Development
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
Teaching material agriculture food technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Electronic commerce courselecture one. Pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Big Data Technologies - Introduction.pptx
Cloud computing and distributed systems.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The AUB Centre for AI in Media Proposal.docx
KodekX | Application Modernization Development
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
“AI and Expert System Decision Support & Business Intelligence Systems”
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Teaching material agriculture food technology
Reach Out and Touch Someone: Haptics and Empathic Computing
MYSQL Presentation for SQL database connectivity
Electronic commerce courselecture one. Pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation_ Review paper, used for researhc scholars
Big Data Technologies - Introduction.pptx

A Glance At The Java Performance Toolbox.pdf

  • 1. A Glance at The Java Performance Toolbox
  • 2. Java Champion Alumni, Certified Architect Senior Developer Advocate at Oracle Passionate about solving complex scenarios involving Java and Kubernetes. ammbra1508 ammbra1508.mastondon.social
  • 3. Using the JDK Tools for Containerized Applications
  • 6. Tools to build an OCI Compliant Image • Docker build • Buildpacks • Jib • kaniko • buildah • s2i • And many more J
  • 7. The Good Old Dockerfile
  • 8. The Good Old Dockerfile Use a small base image
  • 9. The Good Old Dockerfile Use a small base image Create images with common layers
  • 10. The Good Old Dockerfile Use a small base image Install only what is strictly needed Create images with common layers
  • 11. Creating Custom Java Runtimes for Container Images
  • 12. Jlink JEP 282 “Link time is an opportunity to do whole-world optimizations that are otherwise difficult at compile time or costly at run-time” jlink: Command Line Tool to Link Modules • Modules in a jimage file • Generate runtime images
  • 13. Jlink Packaging Legacy JDK image JDK > 9 generated image bin jre lib bin conf …….. Modular runtime image jlink
  • 14. Maintain The Good Old Dockerfile with JLink The runtime stage build • From a JDK base image • Create your own custom JRE with jlink
  • 15. Maintain The Good Old Dockerfile with JLink The runtime stage build • From a JDK base image • Create your own custom JRE with jlink The application stage build • From an OS base image • Copy the custom JRE from the runtime stage build • Copy the artifacts needed by your application • Run the application
  • 18. The Runtime Stage Build jdeps --ignore-missing-deps -q -recursive --multi-release 20 --print-module-deps --class-path 'target/libs/*’ target/spring-todo-app.jar
  • 20. The Runtime Stage Build Strips debug information from the output image
  • 22. The Runtime Stage Build Exclude man pages and header files
  • 23. The Runtime Stage Build z
  • 24. The Runtime Stage Build Enable compression of resources: 0: No compression 1: Constant string sharing 2: ZIP
  • 25. The Application Stage Build Copy the custom JRE
  • 26. The Application Stage Build Copy the artifacts needed by your application
  • 27. The Application Stage Build Run the application
  • 30. Tracking Native Memory With Jcmd Add jdk.jcmd module
  • 31. Tracking Native Memory With Jcmd WARNING: Overusing jcmd to send diagnostic commands can affect the performance of the VM.
  • 32. Tracking Native Memory With Jcmd WARNING: Overusing jcmd to send diagnostic commands can affect the performance of the VM. Add -XX:NativeMemoryTracking={off|summary|detail} to JDK_JAVA_OPTIONS • kubectl set env deployment/app JDK_JAVA_OPTIONS=“-XX:NativeMemoryTracking=summary” • Please consider that having NMT enabled can add application performance overhead.
  • 33. Tracking Native Memory With Jcmd WARNING: Overusing jcmd to send diagnostic commands can affect the performance of the VM. Add -XX:NativeMemoryTracking={off|summary|detail} to JDK_JAVA_OPTIONS Create a native memory baseline kubectl exec pod_name –it --/bin/bash -c "jcmd llvmid VM.native_memory baseline"
  • 34. Tracking Native Memory With Jcmd WARNING: Overusing jcmd to send diagnostic commands can affect the performance of the VM. Add -XX:NativeMemoryTracking={off|summary|detail} to JDK_JAVA_OPTIONS Create a native memory baseline kubectl exec pod_name –it --/bin/bash -c "jcmd llvmid VM.native_memory baseline" Create a native memory summary diff kubectl exec pod_name –it --/bin/bash -c "jcmd llvmid VM.native_memory summary.diff"
  • 35. Enabling JMX Monitoring and Remote Access to a Remote Host
  • 37. Obtain Statistics with Jstat and Jmap Obtain statistics about garbage collectors by running jstat kubectl exec pod_name –it --/bin/bash -c "jstat -gcutil llvmid 500 50"
  • 38. Obtain Statistics with Jstat and Jmap Obtain statistics about garbage collectors by running jstat kubectl exec pod_name –it --/bin/bash -c "jstat -gcutil llvmid 500 50" Print heap summaries kubectl exec pod_name –it --/bin/bash -c "jmap -histo llvmid"
  • 39. Capture Performance Relevant JVM And Application Events
  • 40. Add JFR To Your Container Image
  • 41. Enable JFR Enable JFR in JDK_JAVA_OPTIONS kubectl set env deployment/app JDK_JAVA_OPTIONS=“--XX:StartFlightRecording:..” Use the diagnostic command: kubectl exec pod_name –it --/bin/bash -c "jcmd 1 JFR.start…"
  • 42. Start JFR Enable JFR in JDK_JAVA_OPTIONS kubectl set env deployment/app JDK_JAVA_OPTIONS=“--XX:StartFlightRecording:..” Start a Time Fixed Recording with profile settings -XX:StartFlightRecording=delay=10s,duration=10m,name=Profiling,settings=profile
  • 43. Start JFR Enable JFR in JDK_JAVA_OPTIONS kubectl set env deployment/app JDK_JAVA_OPTIONS=“--XX:StartFlightRecording:..” Start a Time Fixed Recording with profile settings -XX:StartFlightRecording=delay=10s,duration=10m,name=Profiling,settings=profile Start a Time Fixed Recording with default settings -XX:StartFlightRecording=delay=10s,duration=10m,name=Default,settings=default
  • 44. Start JFR Enable JFR in JDK_JAVA_OPTIONS kubectl set env deployment/app JDK_JAVA_OPTIONS=“--XX:StartFlightRecording:..” Start a Time Fixed Recording with profile settings -XX:StartFlightRecording=delay=10s,duration=10m,name=Profiling,settings=profile Start a Time Fixed Recording with default settings -XX:StartFlightRecording=delay=10s,duration=10m,name=Default,settings=default Start a Continous Recording -XX:StartFlightRecording:filename=/recordings/recording.jfr,settings=profile
  • 45. Where to Use JFR Streaming Streaming selected metrics to your monitoring service Send an average, min, max, etc of a metric Expose JFR data through other management APIs
  • 46. Where NOT to Use JFR Streaming “To consume the data today, a user must start a recording, stop it, dump the contents to disk and then parse the recording file. This works well for application profiling, where typically at least a minute of data is being recorded at a time, but not for monitoring purposes.“ source: JEP 349
  • 47. Make your settings by extending jdk.jfr.SettingControl Recording Custom JFR Events
  • 48. Make your settings by extending jdk.jfr.SettingControl Create your custom event by extending jdk.jfr.Event Recording Custom JFR Events
  • 49. Recording Custom JFR Events Make your settings by extending jdk.jfr.SettingControl Create your custom event by extending jdk.jfr.Event Register the custom settings in your custom event via @jdk.jfr.SettingsDefinition
  • 50. Recording Custom Events in Spring Boot (example) Capture the custom JFR events in a dedicated filter and register it
  • 51. Recording Custom Events in Spring Boot (example) Listen the custom JFR events and record their duration
  • 53. Useful Links • Article https://www.javaadvent.com/2022/12/a-sneak-peek-at-the-java-performance-toolbox.html • Tools https://docs.oracle.com/en/java/javase/20/docs/specs/man/index.html • jlink https://dev.java/learn/jlink/ • Troubleshoot Memory Leaks: https://docs.oracle.com/en/java/javase/20/troubleshoot/troubleshooting-memory- leaks.html • JFR Runtime guide : https://docs.oracle.com/javacomponents/jmc-5-4/jfr-runtime-guide/about.htm#JFRUH170 • Innovative JFR use by @gunnarmorling: https://www.morling.dev/blog/finding-java-thread-leaks-with-jdk-flight- recorder-and-bit-of-sql/ • @gunnarmorling article on custom JDK Flight Recorder Events • Great intro by @BillyKorando https://www.youtube.com/watch?v=K1ApBZGiT-Y • Stack walker episode by @BillyKorando: https://inside.java/2023/05/14/stackwalker-02/