SlideShare a Scribd company logo
1 of 53
Download to read offline
A Glance at
The Java Performance
Toolbox
Java Champion Alumni, Certified Architect
Senior Developer Advocate at Oracle
“DevOps Tools for Java Developers” guest author
ammbra1508 ammbra1508.mastondon.social
What does application
performance mean?
Performance experienced
by end-users
Computational resources used by the
application
Performance Metrics
CPU Usage
Memory Usage
Error rates
User satisfaction (Apdex scores)
Average response time
Request rates
Latency and uptime
Throughput
More Questions Using Java Applications in
Containers
• Which JDK tools help you create container images with only what is needed at runtime?
• How to run the JDK tools in containers and proxy their output?
• Which tools help you fine tune the JVM flags and keep application overhead at minimum?
• How to capture performance relevant JVM and application events?
• How to correlate data from JVM monitoring tools with the one from tools like Prometheus,
Grafana?
Which tools help you create
container images with only what
is needed at runtime?
Tools to build an OCI Compliant Image
• Docker build
• Buildpacks
• Jib
• kaniko
• buildah
• s2i
• And many more J
The Good Old Dockerfile
FROM openjdk:10-jre-slim
# Continue with your application deployment
COPY ./target/spring-todo-app.jar /app.jar
COPY entrypoint.sh /entrypoint.sh
RUN groupadd -r appuser && useradd -r -g appuser appuser
RUN chmod +x /entrypoint.sh
USER appuser
CMD ["/entrypoint.sh"] #CMD ["java", "-jar", "app.jar"]
The Good Old Dockerfile
FROM openjdk:10-jre-slim
# Continue with your application deployment
COPY ./target/spring-todo-app.jar /app.jar
COPY entrypoint.sh /entrypoint.sh
RUN groupadd -r appuser && useradd -r -g appuser appuser
RUN chmod +x /entrypoint.sh
USER appuser
CMD ["/entrypoint.sh"] #CMD ["java", "-jar", "app.jar"]
Use a small base image
Create images with common layers
The Good Old Dockerfile
FROM openjdk:10-jre-slim
# Continue with your application deployment
COPY ./target/spring-todo-app.jar /app.jar
COPY entrypoint.sh /entrypoint.sh
RUN groupadd -r appuser && useradd -r -g appuser appuser
RUN chmod +x /entrypoint.sh
USER appuser
CMD ["/entrypoint.sh"] #CMD ["java", "-jar", "app.jar"]
Install only what is strictly needed
JDK tools that shape
efficient 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
FROM container-registry.oracle.com/java/openjdk:21-oraclelinux8 as jre-build
# Create a custom Java runtime
RUN $JAVA_HOME/bin/jlink 
--add-modules <modules> 
--no-man-pages 
--no-header-files 
--compress=zip-9 
--output /javaruntime
jdeps --ignore-missing-deps -q -recursive 
--multi-release 21 --print-module-deps 
--class-path 'target/libs/*’ 
target/spring-todo-app.jar
The Runtime Stage Build
FROM container-registry.oracle.com/java/openjdk:21-oraclelinux8 as jre-build
# Create a custom Java runtime
RUN $JAVA_HOME/bin/jlink 
--add-modules <modules> 
--no-man-pages 
--no-header-files 
--compress=zip-9 
--output /javaruntime
Exclude man pages and header files
The Runtime Stage Build
FROM container-registry.oracle.com/java/openjdk:21-oraclelinux8 as jre-build
# Create a custom Java runtime
RUN $JAVA_HOME/bin/jlink 
--add-modules <modules> 
--no-man-pages 
--no-header-files 
--compress=zip-9 
--output /javaruntime
Enable compression of resources zip[0-9]:
zip-0: No compression
zip-6: Default value
zip-9: Best compression
The Application Stage Build
FROM oraclelinux:8-slim
ENV JAVA_HOME /usr/java/openjdk-21
ENV PATH $JAVA_HOME/bin:$PATH
COPY --from=jre-build /javaruntime $JAVA_HOME
# Continue with your application deployment
ENV JDK_JAVA_OPTIONS "--enable-preview"
CMD ["/entrypoint.sh"]
Copy the custom JRE
The Application Stage Build
FROM oraclelinux:8-slim
ENV JAVA_HOME /usr/java/openjdk-21
ENV PATH $JAVA_HOME/bin:$PATH
COPY --from=jre-build /javaruntime $JAVA_HOME
# Continue with your application deployment
ENV JDK_JAVA_OPTIONS "--enable-preview"
CMD ["/entrypoint.sh"]
Copy the artifacts needed by
your application
The Application Stage Build
FROM oraclelinux:8-slim
ENV JAVA_HOME /usr/java/openjdk-21
ENV PATH $JAVA_HOME/bin:$PATH
COPY --from=jre-build /javaruntime $JAVA_HOME
# Continue with your application deployment
ENV JDK_JAVA_OPTIONS "--enable-preview"
CMD ["/entrypoint.sh"] Run the application
How about fine tuning
JVM Flags?
Conserving Dynamic Footprint by
Minimizing Java Heap Size
Start by looking at the JVM ergonomics
Conserving Dynamic Footprint by
Minimizing Java Heap Size
Start by looking at the JVM ergonomics
At initialization of the virtual machine, the entire space for the heap is reserved.
Eg: setting for minimum and maximum heap size: -Xms768m -Xmx768m
Conserving Dynamic Footprint by
Minimizing Java Heap Size
Start by looking at the JVM ergonomics
At initialization of the virtual machine, the entire space for the heap is reserved.
Eg: setting for minimum and maximum heap size: -Xms768m -Xmx768m
Minimize Java heap size by lowering the values of the options:
• -XX:MaxHeapFreeRatio (default value is 70%)
-XX:MinHeapFreeRatio (default value is 40%)
• Eg:-XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=70
What if the problem is not
the amount of resources
allocated to/by the JVM?
Tracking Native Memory With jcmd
FROM container-registry.oracle.com/java/openjdk:21-oraclelinux8 as jre-build
# Create a custom Java runtime
RUN $JAVA_HOME/bin/jlink 
--add-modules <modules, jdk.jcmd> 
--no-man-pages 
--no-header-files 
--compress=zip-9 
--output /javaruntime
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"
Performance and
Resource Consumption
Overview information about the Java VM and
monitored values.
Information about memory use.
Information about thread use.
Information about class loading.
Information about the Java VM.
Information about MBeans
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
When to Use Profiling
“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
FROM container-registry.oracle.com/java/openjdk:21-oraclelinux8 as jre-build
# Create a custom Java runtime
RUN $JAVA_HOME/bin/jlink 
--add-modules <modules, jdk.jfr> 
--no-man-pages 
--no-header-files 
--compress=zip-9 
--output /javaruntime
Add JFR To Your Container Image
Add jdk.jfr module
How to Use JFR
Enable JFR in JDK_JAVA_OPTIONS
kubectl set env deployment/app JDK_JAVA_OPTIONS=“--XX:StartFlightRecording:..”
For example, start a time fixed recording with default profile
-XX:StartFlightRecording=delay=10s,duration=10m,name=Default,settings=default
Use the diagnostic command:
kubectl exec pod_name –it --/bin/bash -c "jcmd 1 JFR.start…"
Monitor and React
…..
AppTarget 1
AppTarget 2
AppTarget n
Prometheus server
Pull metrics
Pull metrics
Pull metrics
Gathering metrics
Visualizing metrics
Alerting
Streaming selected metrics to your
monitoring service
Where to Use JFR
Streaming
Stream selected metrics to your
monitoring service
Send an average, min, max, etc of a metric
Where to Use JFR
Streaming
Stream selected metrics to your
monitoring service
Send an average, min, max, etc of a metric
Expose JFR data through other
management APIs
Where to Use JFR
Streaming
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/21/docs/specs/man/index.html
• jlink https://dev.java/learn/jlink/
• Troubleshoot Memory Leaks: https://docs.oracle.com/en/java/javase/21/troubleshoot/troubleshooting-memory-
leaks.html
• 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

Similar to A Glance At The Java Performance Toolbox

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

Openshift operator insight
Openshift operator insightOpenshift operator insight
Openshift operator insight
 
Java in a world of containers
Java in a world of containersJava in a world of containers
Java in a world of containers
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018
 
Commit to excellence - Java in containers
Commit to excellence - Java in containersCommit to excellence - Java in containers
Commit to excellence - Java in containers
 
Lean microservices through ahead of time compilation (Tobias Piper, Loveholid...
Lean microservices through ahead of time compilation (Tobias Piper, Loveholid...Lean microservices through ahead of time compilation (Tobias Piper, Loveholid...
Lean microservices through ahead of time compilation (Tobias Piper, Loveholid...
 
DevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux ContainersDevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux Containers
 
ContainerWorkloadwithSemeru.pdf
ContainerWorkloadwithSemeru.pdfContainerWorkloadwithSemeru.pdf
ContainerWorkloadwithSemeru.pdf
 
Master your java_applications_in_kubernetes
Master your java_applications_in_kubernetesMaster your java_applications_in_kubernetes
Master your java_applications_in_kubernetes
 
Jenkins Pipelines Advanced
Jenkins Pipelines AdvancedJenkins Pipelines Advanced
Jenkins Pipelines Advanced
 
Geode on Docker
Geode on DockerGeode on Docker
Geode on Docker
 
JVMs in Containers - Best Practices
JVMs in Containers - Best PracticesJVMs in Containers - Best Practices
JVMs in Containers - Best Practices
 
Vagrant or docker for java dev environment
Vagrant or docker for java dev environmentVagrant or docker for java dev environment
Vagrant or docker for java dev environment
 
Build Your Kubernetes Operator with the Right Tool!
Build Your Kubernetes Operator with the Right Tool!Build Your Kubernetes Operator with the Right Tool!
Build Your Kubernetes Operator with the Right Tool!
 
DCSF 19 Building Your Development Pipeline
DCSF 19 Building Your Development Pipeline  DCSF 19 Building Your Development Pipeline
DCSF 19 Building Your Development Pipeline
 
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
DCSF19 Docker Containers & Java: What I Wish I Had Been ToldDCSF19 Docker Containers & Java: What I Wish I Had Been Told
DCSF19 Docker Containers & Java: What I Wish I Had Been Told
 
JavaOne 2016: Life after Modularity
JavaOne 2016: Life after ModularityJavaOne 2016: Life after Modularity
JavaOne 2016: Life after Modularity
 
DockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best PracticesDockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best Practices
 
DCEU 18: Dockerfile Best Practices
DCEU 18: Dockerfile Best PracticesDCEU 18: Dockerfile Best Practices
DCEU 18: Dockerfile Best Practices
 
Introduction to JIB and Google Cloud Run
Introduction to JIB and Google Cloud RunIntroduction to JIB and Google Cloud Run
Introduction to JIB and Google Cloud Run
 
Run alone: a standalone application attempt by Gabriel Sor
Run alone: a standalone application attempt by Gabriel SorRun alone: a standalone application attempt by Gabriel Sor
Run alone: a standalone application attempt by Gabriel Sor
 

More from Ana-Maria Mihalceanu

DevoxxUK 2021 Techniques for maintainable Quarkus applications
DevoxxUK 2021 Techniques for maintainable Quarkus applicationsDevoxxUK 2021 Techniques for maintainable Quarkus applications
DevoxxUK 2021 Techniques for maintainable Quarkus applications
Ana-Maria Mihalceanu
 

More from Ana-Maria Mihalceanu (20)

Java 22 and Beyond- A Roadmap of Innovations
Java 22 and Beyond- A Roadmap of InnovationsJava 22 and Beyond- A Roadmap of Innovations
Java 22 and Beyond- A Roadmap of Innovations
 
Surveillance de la sécurité des applications Java avec les outils du JDK e...
Surveillance de la sécurité des applications Java  avec les outils du JDK e...Surveillance de la sécurité des applications Java  avec les outils du JDK e...
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
Monitoring Java Application Security with JDK Tools and JFR Events.pdfMonitoring Java Application Security with JDK Tools and JFR Events.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
Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
 
Java 21 Language Features and Beyond
Java 21 Language Features and BeyondJava 21 Language Features and Beyond
Java 21 Language Features and Beyond
 
From Java 17 to 21- A Showcase of JDK Security Enhancements
From Java 17 to 21- A Showcase of JDK Security EnhancementsFrom Java 17 to 21- A Showcase of JDK Security Enhancements
From Java 17 to 21- A Showcase of JDK Security Enhancements
 
Java 21 and Beyond- A Roadmap of Innovations
Java 21 and Beyond- A Roadmap of InnovationsJava 21 and Beyond- A Roadmap of Innovations
Java 21 and Beyond- A Roadmap of Innovations
 
How Java 19 Influences the Future of Your High-Scale Applications .pdf
How Java 19 Influences the Future of Your High-Scale Applications .pdfHow Java 19 Influences the Future of Your High-Scale Applications .pdf
How Java 19 Influences the Future of Your High-Scale Applications .pdf
 
The Automation Challenge Kubernetes Operators vs Helm Charts.pdf
The Automation Challenge Kubernetes Operators vs Helm Charts.pdfThe Automation Challenge Kubernetes Operators vs Helm Charts.pdf
The Automation Challenge Kubernetes Operators vs Helm Charts.pdf
 
Exploring Quarkus on JDK 17
Exploring Quarkus on JDK 17Exploring Quarkus on JDK 17
Exploring Quarkus on JDK 17
 
Cloud native resiliency patterns from the ground up
Cloud native resiliency patterns from the ground upCloud native resiliency patterns from the ground up
Cloud native resiliency patterns from the ground up
 
Cloud native resiliency patterns from the ground up
Cloud native resiliency patterns from the ground upCloud native resiliency patterns from the ground up
Cloud native resiliency patterns from the ground up
 
Cloud native resiliency patterns from the ground up
Cloud native resiliency patterns from the ground upCloud native resiliency patterns from the ground up
Cloud native resiliency patterns from the ground up
 
The automation challenge Kubernetes operators vs Helm charts
The automation challenge Kubernetes operators vs Helm chartsThe automation challenge Kubernetes operators vs Helm charts
The automation challenge Kubernetes operators vs Helm charts
 
Cloud native resiliency patterns from the ground up
Cloud native resiliency patterns from the ground upCloud native resiliency patterns from the ground up
Cloud native resiliency patterns from the ground up
 
DevoxxUK 2021 Techniques for maintainable Quarkus applications
DevoxxUK 2021 Techniques for maintainable Quarkus applicationsDevoxxUK 2021 Techniques for maintainable Quarkus applications
DevoxxUK 2021 Techniques for maintainable Quarkus applications
 
The automation challenge: Kubernetes Operators vs Helm Charts
The automation challenge: Kubernetes Operators vs Helm ChartsThe automation challenge: Kubernetes Operators vs Helm Charts
The automation challenge: Kubernetes Operators vs Helm Charts
 
Techniques for maintainable Quarkus applications
Techniques for maintainable Quarkus applicationsTechniques for maintainable Quarkus applications
Techniques for maintainable Quarkus applications
 
Techniques for maintainable Quarkus applications
Techniques for maintainable Quarkus applicationsTechniques for maintainable Quarkus applications
Techniques for maintainable Quarkus applications
 
Five tips for performant microservices on quarkus
Five tips for performant microservices on quarkusFive tips for performant microservices on quarkus
Five tips for performant microservices on quarkus
 

Recently uploaded

“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
Muhammad Subhan
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 

Recently uploaded (20)

UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 

A Glance At The Java Performance Toolbox

  • 1. A Glance at The Java Performance Toolbox
  • 2. Java Champion Alumni, Certified Architect Senior Developer Advocate at Oracle “DevOps Tools for Java Developers” guest author ammbra1508 ammbra1508.mastondon.social
  • 4. Performance experienced by end-users Computational resources used by the application
  • 5. Performance Metrics CPU Usage Memory Usage Error rates User satisfaction (Apdex scores) Average response time Request rates Latency and uptime Throughput
  • 6.
  • 7. More Questions Using Java Applications in Containers • Which JDK tools help you create container images with only what is needed at runtime? • How to run the JDK tools in containers and proxy their output? • Which tools help you fine tune the JVM flags and keep application overhead at minimum? • How to capture performance relevant JVM and application events? • How to correlate data from JVM monitoring tools with the one from tools like Prometheus, Grafana?
  • 8. Which tools help you create container images with only what is needed at runtime?
  • 9.
  • 10. Tools to build an OCI Compliant Image • Docker build • Buildpacks • Jib • kaniko • buildah • s2i • And many more J
  • 11. The Good Old Dockerfile FROM openjdk:10-jre-slim # Continue with your application deployment COPY ./target/spring-todo-app.jar /app.jar COPY entrypoint.sh /entrypoint.sh RUN groupadd -r appuser && useradd -r -g appuser appuser RUN chmod +x /entrypoint.sh USER appuser CMD ["/entrypoint.sh"] #CMD ["java", "-jar", "app.jar"]
  • 12. The Good Old Dockerfile FROM openjdk:10-jre-slim # Continue with your application deployment COPY ./target/spring-todo-app.jar /app.jar COPY entrypoint.sh /entrypoint.sh RUN groupadd -r appuser && useradd -r -g appuser appuser RUN chmod +x /entrypoint.sh USER appuser CMD ["/entrypoint.sh"] #CMD ["java", "-jar", "app.jar"] Use a small base image Create images with common layers
  • 13. The Good Old Dockerfile FROM openjdk:10-jre-slim # Continue with your application deployment COPY ./target/spring-todo-app.jar /app.jar COPY entrypoint.sh /entrypoint.sh RUN groupadd -r appuser && useradd -r -g appuser appuser RUN chmod +x /entrypoint.sh USER appuser CMD ["/entrypoint.sh"] #CMD ["java", "-jar", "app.jar"] Install only what is strictly needed
  • 14. JDK tools that shape efficient Java Runtimes for Container Images
  • 15. 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
  • 16. Jlink Packaging Legacy JDK image JDK > 9 generated image bin jre lib bin conf …….. Modular runtime image jlink
  • 17. Maintain The Good Old Dockerfile with jlink The runtime stage build • From a JDK base image • Create your own custom JRE with jlink
  • 18. 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
  • 19. The Runtime Stage Build FROM container-registry.oracle.com/java/openjdk:21-oraclelinux8 as jre-build # Create a custom Java runtime RUN $JAVA_HOME/bin/jlink --add-modules <modules> --no-man-pages --no-header-files --compress=zip-9 --output /javaruntime jdeps --ignore-missing-deps -q -recursive --multi-release 21 --print-module-deps --class-path 'target/libs/*’ target/spring-todo-app.jar
  • 20. The Runtime Stage Build FROM container-registry.oracle.com/java/openjdk:21-oraclelinux8 as jre-build # Create a custom Java runtime RUN $JAVA_HOME/bin/jlink --add-modules <modules> --no-man-pages --no-header-files --compress=zip-9 --output /javaruntime Exclude man pages and header files
  • 21. The Runtime Stage Build FROM container-registry.oracle.com/java/openjdk:21-oraclelinux8 as jre-build # Create a custom Java runtime RUN $JAVA_HOME/bin/jlink --add-modules <modules> --no-man-pages --no-header-files --compress=zip-9 --output /javaruntime Enable compression of resources zip[0-9]: zip-0: No compression zip-6: Default value zip-9: Best compression
  • 22. The Application Stage Build FROM oraclelinux:8-slim ENV JAVA_HOME /usr/java/openjdk-21 ENV PATH $JAVA_HOME/bin:$PATH COPY --from=jre-build /javaruntime $JAVA_HOME # Continue with your application deployment ENV JDK_JAVA_OPTIONS "--enable-preview" CMD ["/entrypoint.sh"] Copy the custom JRE
  • 23. The Application Stage Build FROM oraclelinux:8-slim ENV JAVA_HOME /usr/java/openjdk-21 ENV PATH $JAVA_HOME/bin:$PATH COPY --from=jre-build /javaruntime $JAVA_HOME # Continue with your application deployment ENV JDK_JAVA_OPTIONS "--enable-preview" CMD ["/entrypoint.sh"] Copy the artifacts needed by your application
  • 24. The Application Stage Build FROM oraclelinux:8-slim ENV JAVA_HOME /usr/java/openjdk-21 ENV PATH $JAVA_HOME/bin:$PATH COPY --from=jre-build /javaruntime $JAVA_HOME # Continue with your application deployment ENV JDK_JAVA_OPTIONS "--enable-preview" CMD ["/entrypoint.sh"] Run the application
  • 25. How about fine tuning JVM Flags?
  • 26. Conserving Dynamic Footprint by Minimizing Java Heap Size Start by looking at the JVM ergonomics
  • 27. Conserving Dynamic Footprint by Minimizing Java Heap Size Start by looking at the JVM ergonomics At initialization of the virtual machine, the entire space for the heap is reserved. Eg: setting for minimum and maximum heap size: -Xms768m -Xmx768m
  • 28. Conserving Dynamic Footprint by Minimizing Java Heap Size Start by looking at the JVM ergonomics At initialization of the virtual machine, the entire space for the heap is reserved. Eg: setting for minimum and maximum heap size: -Xms768m -Xmx768m Minimize Java heap size by lowering the values of the options: • -XX:MaxHeapFreeRatio (default value is 70%) -XX:MinHeapFreeRatio (default value is 40%) • Eg:-XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=70
  • 29. What if the problem is not the amount of resources allocated to/by the JVM?
  • 30. Tracking Native Memory With jcmd FROM container-registry.oracle.com/java/openjdk:21-oraclelinux8 as jre-build # Create a custom Java runtime RUN $JAVA_HOME/bin/jlink --add-modules <modules, jdk.jcmd> --no-man-pages --no-header-files --compress=zip-9 --output /javaruntime 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. Performance and Resource Consumption Overview information about the Java VM and monitored values. Information about memory use. Information about thread use. Information about class loading. Information about the Java VM. Information about MBeans
  • 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. When to Use Profiling “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
  • 41. FROM container-registry.oracle.com/java/openjdk:21-oraclelinux8 as jre-build # Create a custom Java runtime RUN $JAVA_HOME/bin/jlink --add-modules <modules, jdk.jfr> --no-man-pages --no-header-files --compress=zip-9 --output /javaruntime Add JFR To Your Container Image Add jdk.jfr module
  • 42. How to Use JFR Enable JFR in JDK_JAVA_OPTIONS kubectl set env deployment/app JDK_JAVA_OPTIONS=“--XX:StartFlightRecording:..” For example, start a time fixed recording with default profile -XX:StartFlightRecording=delay=10s,duration=10m,name=Default,settings=default Use the diagnostic command: kubectl exec pod_name –it --/bin/bash -c "jcmd 1 JFR.start…"
  • 43. Monitor and React ….. AppTarget 1 AppTarget 2 AppTarget n Prometheus server Pull metrics Pull metrics Pull metrics Gathering metrics Visualizing metrics Alerting
  • 44. Streaming selected metrics to your monitoring service Where to Use JFR Streaming
  • 45. Stream selected metrics to your monitoring service Send an average, min, max, etc of a metric Where to Use JFR Streaming
  • 46. Stream selected metrics to your monitoring service Send an average, min, max, etc of a metric Expose JFR data through other management APIs Where to Use JFR Streaming
  • 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/21/docs/specs/man/index.html • jlink https://dev.java/learn/jlink/ • Troubleshoot Memory Leaks: https://docs.oracle.com/en/java/javase/21/troubleshoot/troubleshooting-memory- leaks.html • 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/