Skip to content

Instantly share code, notes, and snippets.

@DaveyDevOps
Last active July 22, 2022 09:58
Show Gist options
  • Save DaveyDevOps/438746bd123dc3313810d09c0056e42e to your computer and use it in GitHub Desktop.
Save DaveyDevOps/438746bd123dc3313810d09c0056e42e to your computer and use it in GitHub Desktop.
Large Java Heap Dump Analysis

Just wanted to document the steps taken in a specific scenario. There are plenty of references covering the different parts (feel free to Google if you don't believe me).

Scenario:
Problematic Java application running on a Linux server with a large heap (~16 GB).
My devices, Windows Laptop/Desktop with a limited number of RAM.

Goal:
Take a heap dump and analyze with Eclipse Memory Analyzer.

Heap Dump

  1. Open a shell on the Linux server.
  2. Locate PID of application ps -fwww -u <user> or perhaps ps -fwww -p $(pgrep java). Also make note of the path to the java install e.g. /usr/jdk64/jdk1.8.0_121.
  3. Think about where to store the heap dump. If heap is 16GB you will need at least 16GB in local storage. This location should also be accessible to the owner of the process.
  4. As the user who owns the process
PATH_TO_JAVA/bin/jmap -dump:format=b,file=FILE_LOCATION/APP_heap.bin PID

Analysis

First attempt was to copy heap dump file to my devices (~1 hour to download) and open with the Eclipse Memory Analyzer (MAT). This resulted Out of Memory errors. There are some FAQ about how to provide more memory to MAT which I followed, but my devices still didn't have enough to make it.

Running the analysis on the server.

While a nice UI is a big part of the Eclipse Memory Analyzer it is actually not required to generate the reports.

  1. Since the server is Linux, download the Memory Analyzer Linux release.
  2. Move the file onto the server, extract, make executable, etc.
  3. Within the mat folder modify MemoryAnalyzer.ini adding -Xmx large enough to process the heap dump.
  4. Generate index files
./ParseHeapDump.sh FILE_LOCATION/APP_heap.bin

This will take a while... but is where the majority of analysis is done. The index files could be download for use with a local MAT UI. But I went ahead and generated all the reports and downloaded the resulting zip files.

./ParseHeapDump.sh FILE_LOCATION/APP_heap.bin org.eclipse.mat.api:suspects 
./ParseHeapDump.sh FILE_LOCATION/APP_heap.bin org.eclipse.mat.api:overview
./ParseHeapDump.sh FILE_LOCATION/APP_heap.bin org.eclipse.mat.api:top_components 
  1. In my scenario the Leak suspects report provided the most direction.

Resource: ASHWIN JAYAPRAKASH'S BLOG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment