SlideShare a Scribd company logo
Java Memory Leak
Agenda
1. Supported JDK Versions in Mule
2. Introduction to JVM Memory Management
3. What is memory leak and what behaviours do you observe?
4. Tools for memory analysis
5. What is Heap Dump?
6. Basic theory
7. Example
8. Summary
Supported Java Versions
 Mule Runtime Environments:
 3.8 (Extended Support till Nov/2021) -> JDK 1.7 and recommended 1.8.0_91/92
 3.9 (Extended Support till Mar/2024) -> JDK 1.8.0_144
 4.1 (Extended Support till Nov/2022) -> JDK 1.8.0_151/52
 4.2 (Extended Support till May/2022) -> OpenJDK 8 recommended over Java
11/other JDK 8 versions
Links:
https://www.mulesoft.com/legal/versioning-back-support-policy
https://docs.mulesoft.com/release-notes/mule-runtime/mule-4.2.0-release-notes
Java 8 JVM Memory Management
Java 8 Memory Management
 There are three main parts in JVM:
1. Young/New Generation:
 Newly created/started objects are stored in this region.
 When the young generation fills up, a minor garbage collection happens and either objects get cleaned
or moved to the Survivor region.
 World Stop Events
2. Old Generation:
 Long surviving objects get stored in this region.
 A threshold is set in the Young Generation and when objects are met, they get moved to the Old
Generation.
 When a garbage collection happens in the Old Generation, it is called a major garbage collection.
 World Stop Events: Longer than a minor garbage collection
3. Metaspace:
 Store meta information about loaded classes.
 No instances of class Class.
Two Main Memory Leaks
 Memory Leak in HEAP (What we are going to look at)
[Exception in thread "main" java.lang.OutOfMemoryError: Java heap space]
 Used objects are no longer required and supposed to be garbage collected.
 Somewhere they are being referenced during the life time of the JVM process.
 This results in consuming more memory.
 Memory Leak in METASPACE
[java.lang.OutOfMemoryError: Metaspace]
 This could be due to the inadequate sizing of the Metaspace.
 There is a classloader/classes leak.
 This is quite rare in Mule.
Behaviours in Anypoint Platform
 Used objects are not de-referenced and some active objects are referencing the used
objects. Therefore the conditions for the JVM garbage collector to delete used objects
are no longer met.
 In Anypoint platform, Memory Usage goes up and CPU Usage goes up too.
 Slow down the application and responses from the application take longer.
How do we get Heap Dump?
 Download and install the on-prem runtime environment from MuleSoft.
 Set JVM Config under mule-enterprise-standalone-4.1.5-
hf1/conf/wrapper.conf
wrapper.java.additional.19=-XX:+PrintGCDetails
wrapper.java.additional.20=-XX:+PrintGCDateStamps
wrapper.java.additional.21=-Xloggc:%MULE_HOME%/logs/gc.log
wrapper.java.additional.22=-XX:+UseGCLogFileRotation
wrapper.java.additional.23=-XX:NumberOfGCLogFiles=5
wrapper.java.additional.24=-XX:GCLogFileSize=10M
 Set JAVA_HOME and other environment variables (Linux):
MULE_HOME=/home/jee/Tools/Environments/mules/mule-enterprise-standalone-4.1.5-hf1.nolicense/
JAVA_HOME=/home/jee/Tools/JDK/jdk1.8.0_131
PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$HOME/bin:$HOME/.local/bin:$PATH"
 Deploy app under $MULE_HOME/apps
 To Start Mule locally: cd $MULE_HOME/bin
./mule start
Taking Heap Dumps
 Several ways to take Heap Dumps from Java processes and HPROF is a
preferred format.
1. jmap -dump:format=b,file=cheap.hprof <PID>
2. jcmd <PID> GC.heap_dump <full path/filename.hprof>
3. VisualVM: GUI to generate a heap dump
Tools For Heap Dump Analysis
There are many tools available online and here are free ones listed.
 Eclipse Java Memory Analyser Tool
https://www.eclipse.org/mat/
I prefer using MAT.
 VisualVM
https://visualvm.github.io/
 Netbeans Profiler
https://netbeans.org/kb/docs/java/profiler-intro.html
Understanding of Heap Dump
 The snapshot contains information about the Java objects and classes in the
heap at the moment the snapshot is triggered.
 Typical information in a heap dump
 All Objects: Class, fields, primitive values, and references.
 All Classes: Class loader, name, super class, and static fields.
 Garbage collection roots: Objects defined to be reachable by the JVM.
 Thread Stacks and Local variables
 The data structure of Java heap is a directed graph of object references.
 Think of it as a graph structured data containing references that may have
primitives such as byte, integers, longs, etc.
Understanding of Heap Dump
 Incoming References: Think of it as Parents
 Outgoing References: Think of it as Children
 These terms can’t really be used as the definite terms as they can be referenced
to each other.
Understanding of Heap Dump
 Shallow heap is the size of an Object and its primitives.
 Retained heap (effective size of an object) is the shallow heap + the retained
heaps of lifetime dependent outgoing references.
 Retained Set is the set of objects that would be removed by garbage
collection when an object, or multiple objects, is garbage collected.
Understanding of Heap Dump
 Dominator Tree: Transform object graph to identify the biggest parts of
retained memory and the keep-alive dependencies among objects.
Finding Leaks
 Eclipse Memory Analyzer Tool
1. Open Heap Dump File:
2. Select “Leak Select Suspects”.
This will give suspected memory leaks
and it does a great job to find one.
3. List Objects with incoming or outgoing
references.
4. If the name is prefixed with “class”, it is
the static instance of that class or just
referencing to that class. So every
instance has a reference to its class.
Generally skip that.
5. If you see unreachable objects, that
means they are eligible for garbage
collection and by default MAT shows live
HEAP.
Finding Leaks
 Inspector: This shows a complete information of an live object.
Finding Leaks
 Thread Stacks and many other information available.
Practical Example
Summary
 Understand Heap Dump: A directed graph referencing from/to objects.
 Using local environment, obtain Heap Dump after reproducing the leak
problem.
 Using MAT, just click memory leak suspect or use dominator tree. This will tell
what the problem is most of times.

More Related Content

What's hot

Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...Vietnam Open Infrastructure User Group
 
Automate Your Kafka Cluster with Kubernetes Custom Resources
Automate Your Kafka Cluster with Kubernetes Custom Resources Automate Your Kafka Cluster with Kubernetes Custom Resources
Automate Your Kafka Cluster with Kubernetes Custom Resources confluent
 
Mule 4 migration + Common Integration Challenges : MuleSoft Virtual Muleys Me...
Mule 4 migration + Common Integration Challenges : MuleSoft Virtual Muleys Me...Mule 4 migration + Common Integration Challenges : MuleSoft Virtual Muleys Me...
Mule 4 migration + Common Integration Challenges : MuleSoft Virtual Muleys Me...Angel Alberici
 
Containers Anywhere with OpenShift by Red Hat
Containers Anywhere with OpenShift by Red HatContainers Anywhere with OpenShift by Red Hat
Containers Anywhere with OpenShift by Red HatAmazon Web Services
 
Prometheus - basics
Prometheus - basicsPrometheus - basics
Prometheus - basicsJuraj Hantak
 
Mule Runtime: Performance Tuning
Mule Runtime: Performance Tuning Mule Runtime: Performance Tuning
Mule Runtime: Performance Tuning MuleSoft
 
Infrastructure-as-Code with Pulumi - Better than all the others (like Ansible)?
Infrastructure-as-Code with Pulumi- Better than all the others (like Ansible)?Infrastructure-as-Code with Pulumi- Better than all the others (like Ansible)?
Infrastructure-as-Code with Pulumi - Better than all the others (like Ansible)?Jonas Hecht
 
Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft
Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft
Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft Akshata Sawant
 
Introduction to Red Hat OpenShift 4
Introduction to Red Hat OpenShift 4Introduction to Red Hat OpenShift 4
Introduction to Red Hat OpenShift 4HngNguyn748044
 
Prometheus design and philosophy
Prometheus design and philosophy   Prometheus design and philosophy
Prometheus design and philosophy Docker, Inc.
 
Object Store V2 Workshop
Object Store V2 WorkshopObject Store V2 Workshop
Object Store V2 WorkshopMuleSoft
 
Monitoring Kubernetes with Prometheus
Monitoring Kubernetes with PrometheusMonitoring Kubernetes with Prometheus
Monitoring Kubernetes with PrometheusGrafana Labs
 
Apache Camel with Spring boot
Apache Camel with Spring bootApache Camel with Spring boot
Apache Camel with Spring bootKnoldus Inc.
 
Kubernetes 101 - an Introduction to Containers, Kubernetes, and OpenShift
Kubernetes 101 - an Introduction to Containers, Kubernetes, and OpenShiftKubernetes 101 - an Introduction to Containers, Kubernetes, and OpenShift
Kubernetes 101 - an Introduction to Containers, Kubernetes, and OpenShiftDevOps.com
 
MuleSoft Surat Meetup#48 - Anypoint API Governance (RAML, OAS and Async API) ...
MuleSoft Surat Meetup#48 - Anypoint API Governance (RAML, OAS and Async API) ...MuleSoft Surat Meetup#48 - Anypoint API Governance (RAML, OAS and Async API) ...
MuleSoft Surat Meetup#48 - Anypoint API Governance (RAML, OAS and Async API) ...Jitendra Bafna
 
Kubernates vs Openshift: What is the difference and comparison between Opensh...
Kubernates vs Openshift: What is the difference and comparison between Opensh...Kubernates vs Openshift: What is the difference and comparison between Opensh...
Kubernates vs Openshift: What is the difference and comparison between Opensh...jeetendra mandal
 
Designing Apps for Runtime Fabric: Logging, Monitoring & Object Store Persist...
Designing Apps for Runtime Fabric: Logging, Monitoring & Object Store Persist...Designing Apps for Runtime Fabric: Logging, Monitoring & Object Store Persist...
Designing Apps for Runtime Fabric: Logging, Monitoring & Object Store Persist...Eva Mave Ng
 

What's hot (20)

Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
 
Prometheus 101
Prometheus 101Prometheus 101
Prometheus 101
 
Automate Your Kafka Cluster with Kubernetes Custom Resources
Automate Your Kafka Cluster with Kubernetes Custom Resources Automate Your Kafka Cluster with Kubernetes Custom Resources
Automate Your Kafka Cluster with Kubernetes Custom Resources
 
Mule 4 migration + Common Integration Challenges : MuleSoft Virtual Muleys Me...
Mule 4 migration + Common Integration Challenges : MuleSoft Virtual Muleys Me...Mule 4 migration + Common Integration Challenges : MuleSoft Virtual Muleys Me...
Mule 4 migration + Common Integration Challenges : MuleSoft Virtual Muleys Me...
 
Containers Anywhere with OpenShift by Red Hat
Containers Anywhere with OpenShift by Red HatContainers Anywhere with OpenShift by Red Hat
Containers Anywhere with OpenShift by Red Hat
 
Prometheus - basics
Prometheus - basicsPrometheus - basics
Prometheus - basics
 
Logstash
LogstashLogstash
Logstash
 
Mule Runtime: Performance Tuning
Mule Runtime: Performance Tuning Mule Runtime: Performance Tuning
Mule Runtime: Performance Tuning
 
Infrastructure-as-Code with Pulumi - Better than all the others (like Ansible)?
Infrastructure-as-Code with Pulumi- Better than all the others (like Ansible)?Infrastructure-as-Code with Pulumi- Better than all the others (like Ansible)?
Infrastructure-as-Code with Pulumi - Better than all the others (like Ansible)?
 
Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft
Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft
Manchester MuleSoft Meetup #6 - Runtime Fabric with Mulesoft
 
Introduction to Red Hat OpenShift 4
Introduction to Red Hat OpenShift 4Introduction to Red Hat OpenShift 4
Introduction to Red Hat OpenShift 4
 
Prometheus design and philosophy
Prometheus design and philosophy   Prometheus design and philosophy
Prometheus design and philosophy
 
Object Store V2 Workshop
Object Store V2 WorkshopObject Store V2 Workshop
Object Store V2 Workshop
 
Monitoring Kubernetes with Prometheus
Monitoring Kubernetes with PrometheusMonitoring Kubernetes with Prometheus
Monitoring Kubernetes with Prometheus
 
Apache Camel with Spring boot
Apache Camel with Spring bootApache Camel with Spring boot
Apache Camel with Spring boot
 
Building APIs with Mule and Spring Boot
Building APIs with Mule and Spring BootBuilding APIs with Mule and Spring Boot
Building APIs with Mule and Spring Boot
 
Kubernetes 101 - an Introduction to Containers, Kubernetes, and OpenShift
Kubernetes 101 - an Introduction to Containers, Kubernetes, and OpenShiftKubernetes 101 - an Introduction to Containers, Kubernetes, and OpenShift
Kubernetes 101 - an Introduction to Containers, Kubernetes, and OpenShift
 
MuleSoft Surat Meetup#48 - Anypoint API Governance (RAML, OAS and Async API) ...
MuleSoft Surat Meetup#48 - Anypoint API Governance (RAML, OAS and Async API) ...MuleSoft Surat Meetup#48 - Anypoint API Governance (RAML, OAS and Async API) ...
MuleSoft Surat Meetup#48 - Anypoint API Governance (RAML, OAS and Async API) ...
 
Kubernates vs Openshift: What is the difference and comparison between Opensh...
Kubernates vs Openshift: What is the difference and comparison between Opensh...Kubernates vs Openshift: What is the difference and comparison between Opensh...
Kubernates vs Openshift: What is the difference and comparison between Opensh...
 
Designing Apps for Runtime Fabric: Logging, Monitoring & Object Store Persist...
Designing Apps for Runtime Fabric: Logging, Monitoring & Object Store Persist...Designing Apps for Runtime Fabric: Logging, Monitoring & Object Store Persist...
Designing Apps for Runtime Fabric: Logging, Monitoring & Object Store Persist...
 

Similar to Mule memory leak issue

Java programing considering performance
Java programing considering performanceJava programing considering performance
Java programing considering performanceRoger Xia
 
Eclipse Memory Analyzer
Eclipse Memory AnalyzerEclipse Memory Analyzer
Eclipse Memory Analyzernayashkova
 
Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)Robert Scholte
 
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12sidg75
 
Eclipse Memory Analyzer - More Than Just a Heap Walker
Eclipse Memory Analyzer - More Than Just a Heap WalkerEclipse Memory Analyzer - More Than Just a Heap Walker
Eclipse Memory Analyzer - More Than Just a Heap Walkerguest62fd60c
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK toolsHaribabu Nandyal Padmanaban
 
77739818 troubleshooting-web-logic-103
77739818 troubleshooting-web-logic-10377739818 troubleshooting-web-logic-103
77739818 troubleshooting-web-logic-103shashank_ibm
 
Apache Maven supports ALL Java (Javaland 2019)
Apache Maven supports ALL Java (Javaland 2019)Apache Maven supports ALL Java (Javaland 2019)
Apache Maven supports ALL Java (Javaland 2019)Robert Scholte
 
Salesforce lwc development workshops session #6
Salesforce lwc development workshops  session #6Salesforce lwc development workshops  session #6
Salesforce lwc development workshops session #6Rahul Gawale
 
OOP with Java
OOP with JavaOOP with Java
OOP with JavaOmegaHub
 
Advanced liferay architecture clustering and high availability
Advanced liferay architecture clustering and high availabilityAdvanced liferay architecture clustering and high availability
Advanced liferay architecture clustering and high availabilityBordin Kijsirijareonchai
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfnofakeNews
 
Opendaylight SDN Controller
Opendaylight SDN ControllerOpendaylight SDN Controller
Opendaylight SDN ControllerSumit Arora
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Introboyw165
 
Cloudera Impala Internals
Cloudera Impala InternalsCloudera Impala Internals
Cloudera Impala InternalsDavid Groozman
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsEfficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsPhillip Koza
 
Perfomatix - Java Coding Standards
Perfomatix - Java Coding StandardsPerfomatix - Java Coding Standards
Perfomatix - Java Coding StandardsPerfomatix Solutions
 
Exploit Frameworks
Exploit FrameworksExploit Frameworks
Exploit Frameworksphanleson
 

Similar to Mule memory leak issue (20)

Java programing considering performance
Java programing considering performanceJava programing considering performance
Java programing considering performance
 
Eclipse Memory Analyzer
Eclipse Memory AnalyzerEclipse Memory Analyzer
Eclipse Memory Analyzer
 
Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)Apache Maven supports all Java (JokerConf 2018)
Apache Maven supports all Java (JokerConf 2018)
 
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
 
Eclipse Memory Analyzer - More Than Just a Heap Walker
Eclipse Memory Analyzer - More Than Just a Heap WalkerEclipse Memory Analyzer - More Than Just a Heap Walker
Eclipse Memory Analyzer - More Than Just a Heap Walker
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
 
77739818 troubleshooting-web-logic-103
77739818 troubleshooting-web-logic-10377739818 troubleshooting-web-logic-103
77739818 troubleshooting-web-logic-103
 
Apache Maven supports ALL Java (Javaland 2019)
Apache Maven supports ALL Java (Javaland 2019)Apache Maven supports ALL Java (Javaland 2019)
Apache Maven supports ALL Java (Javaland 2019)
 
Salesforce lwc development workshops session #6
Salesforce lwc development workshops  session #6Salesforce lwc development workshops  session #6
Salesforce lwc development workshops session #6
 
OOP with Java
OOP with JavaOOP with Java
OOP with Java
 
Advanced liferay architecture clustering and high availability
Advanced liferay architecture clustering and high availabilityAdvanced liferay architecture clustering and high availability
Advanced liferay architecture clustering and high availability
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
 
Opendaylight SDN Controller
Opendaylight SDN ControllerOpendaylight SDN Controller
Opendaylight SDN Controller
 
Frc java5-8andeclipse
Frc java5-8andeclipseFrc java5-8andeclipse
Frc java5-8andeclipse
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Intro
 
Cloudera Impala Internals
Cloudera Impala InternalsCloudera Impala Internals
Cloudera Impala Internals
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsEfficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java Applications
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
Perfomatix - Java Coding Standards
Perfomatix - Java Coding StandardsPerfomatix - Java Coding Standards
Perfomatix - Java Coding Standards
 
Exploit Frameworks
Exploit FrameworksExploit Frameworks
Exploit Frameworks
 

Recently uploaded

Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...Product School
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoTAnalytics
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backElena Simperl
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlPeter Udo Diehl
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxDavid Michel
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀DianaGray10
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
 

Recently uploaded (20)

Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 

Mule memory leak issue

  • 2. Agenda 1. Supported JDK Versions in Mule 2. Introduction to JVM Memory Management 3. What is memory leak and what behaviours do you observe? 4. Tools for memory analysis 5. What is Heap Dump? 6. Basic theory 7. Example 8. Summary
  • 3. Supported Java Versions  Mule Runtime Environments:  3.8 (Extended Support till Nov/2021) -> JDK 1.7 and recommended 1.8.0_91/92  3.9 (Extended Support till Mar/2024) -> JDK 1.8.0_144  4.1 (Extended Support till Nov/2022) -> JDK 1.8.0_151/52  4.2 (Extended Support till May/2022) -> OpenJDK 8 recommended over Java 11/other JDK 8 versions Links: https://www.mulesoft.com/legal/versioning-back-support-policy https://docs.mulesoft.com/release-notes/mule-runtime/mule-4.2.0-release-notes
  • 4. Java 8 JVM Memory Management
  • 5. Java 8 Memory Management  There are three main parts in JVM: 1. Young/New Generation:  Newly created/started objects are stored in this region.  When the young generation fills up, a minor garbage collection happens and either objects get cleaned or moved to the Survivor region.  World Stop Events 2. Old Generation:  Long surviving objects get stored in this region.  A threshold is set in the Young Generation and when objects are met, they get moved to the Old Generation.  When a garbage collection happens in the Old Generation, it is called a major garbage collection.  World Stop Events: Longer than a minor garbage collection 3. Metaspace:  Store meta information about loaded classes.  No instances of class Class.
  • 6. Two Main Memory Leaks  Memory Leak in HEAP (What we are going to look at) [Exception in thread "main" java.lang.OutOfMemoryError: Java heap space]  Used objects are no longer required and supposed to be garbage collected.  Somewhere they are being referenced during the life time of the JVM process.  This results in consuming more memory.  Memory Leak in METASPACE [java.lang.OutOfMemoryError: Metaspace]  This could be due to the inadequate sizing of the Metaspace.  There is a classloader/classes leak.  This is quite rare in Mule.
  • 7. Behaviours in Anypoint Platform  Used objects are not de-referenced and some active objects are referencing the used objects. Therefore the conditions for the JVM garbage collector to delete used objects are no longer met.  In Anypoint platform, Memory Usage goes up and CPU Usage goes up too.  Slow down the application and responses from the application take longer.
  • 8. How do we get Heap Dump?  Download and install the on-prem runtime environment from MuleSoft.  Set JVM Config under mule-enterprise-standalone-4.1.5- hf1/conf/wrapper.conf wrapper.java.additional.19=-XX:+PrintGCDetails wrapper.java.additional.20=-XX:+PrintGCDateStamps wrapper.java.additional.21=-Xloggc:%MULE_HOME%/logs/gc.log wrapper.java.additional.22=-XX:+UseGCLogFileRotation wrapper.java.additional.23=-XX:NumberOfGCLogFiles=5 wrapper.java.additional.24=-XX:GCLogFileSize=10M  Set JAVA_HOME and other environment variables (Linux): MULE_HOME=/home/jee/Tools/Environments/mules/mule-enterprise-standalone-4.1.5-hf1.nolicense/ JAVA_HOME=/home/jee/Tools/JDK/jdk1.8.0_131 PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$HOME/bin:$HOME/.local/bin:$PATH"  Deploy app under $MULE_HOME/apps  To Start Mule locally: cd $MULE_HOME/bin ./mule start
  • 9. Taking Heap Dumps  Several ways to take Heap Dumps from Java processes and HPROF is a preferred format. 1. jmap -dump:format=b,file=cheap.hprof <PID> 2. jcmd <PID> GC.heap_dump <full path/filename.hprof> 3. VisualVM: GUI to generate a heap dump
  • 10. Tools For Heap Dump Analysis There are many tools available online and here are free ones listed.  Eclipse Java Memory Analyser Tool https://www.eclipse.org/mat/ I prefer using MAT.  VisualVM https://visualvm.github.io/  Netbeans Profiler https://netbeans.org/kb/docs/java/profiler-intro.html
  • 11. Understanding of Heap Dump  The snapshot contains information about the Java objects and classes in the heap at the moment the snapshot is triggered.  Typical information in a heap dump  All Objects: Class, fields, primitive values, and references.  All Classes: Class loader, name, super class, and static fields.  Garbage collection roots: Objects defined to be reachable by the JVM.  Thread Stacks and Local variables  The data structure of Java heap is a directed graph of object references.  Think of it as a graph structured data containing references that may have primitives such as byte, integers, longs, etc.
  • 12. Understanding of Heap Dump  Incoming References: Think of it as Parents  Outgoing References: Think of it as Children  These terms can’t really be used as the definite terms as they can be referenced to each other.
  • 13. Understanding of Heap Dump  Shallow heap is the size of an Object and its primitives.  Retained heap (effective size of an object) is the shallow heap + the retained heaps of lifetime dependent outgoing references.  Retained Set is the set of objects that would be removed by garbage collection when an object, or multiple objects, is garbage collected.
  • 14. Understanding of Heap Dump  Dominator Tree: Transform object graph to identify the biggest parts of retained memory and the keep-alive dependencies among objects.
  • 15. Finding Leaks  Eclipse Memory Analyzer Tool 1. Open Heap Dump File: 2. Select “Leak Select Suspects”. This will give suspected memory leaks and it does a great job to find one. 3. List Objects with incoming or outgoing references. 4. If the name is prefixed with “class”, it is the static instance of that class or just referencing to that class. So every instance has a reference to its class. Generally skip that. 5. If you see unreachable objects, that means they are eligible for garbage collection and by default MAT shows live HEAP.
  • 16. Finding Leaks  Inspector: This shows a complete information of an live object.
  • 17. Finding Leaks  Thread Stacks and many other information available.
  • 19. Summary  Understand Heap Dump: A directed graph referencing from/to objects.  Using local environment, obtain Heap Dump after reproducing the leak problem.  Using MAT, just click memory leak suspect or use dominator tree. This will tell what the problem is most of times.

Editor's Notes

  1. Worst case example to be mentioned.
  2. If you take multiple dumps and try to compare the growth of object size, you won’t find the same object references/addresses as GC moves the references/addresses. https://www.ibm.com/support/knowledgecenter/SS3KLZ/com.ibm.java.diagnostics.memory.analyzer.doc/shallowretainedheap.html For example, the right hand side of graph represents all heaps from GC root, which is a, and if b were to be garbage collected, any retained set will be garbage collected provided that there is/are no references into one of retained heap. B, a shallow heap, is to be collected along with the retained set. If h is referenced by c, is C a shallow heap that has a retained set of h?, no the shallow heap that retains h shallow heap is a because only h will be garbage collected if a gets collected.