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.
- Open a shell on the Linux server.
- Locate PID of application
ps -fwww -u <user>
or perhapsps -fwww -p $(pgrep java)
. Also make note of the path to the java install e.g./usr/jdk64/jdk1.8.0_121
. - 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.
- As the user who owns the process
PATH_TO_JAVA/bin/jmap -dump:format=b,file=FILE_LOCATION/APP_heap.bin PID
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.
While a nice UI is a big part of the Eclipse Memory Analyzer it is actually not required to generate the reports.
- Since the server is Linux, download the Memory Analyzer Linux release.
- Move the file onto the server, extract, make executable, etc.
- Within the mat folder modify MemoryAnalyzer.ini adding
-Xmx
large enough to process the heap dump. - 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
- In my scenario the Leak suspects report provided the most direction.
Resource: ASHWIN JAYAPRAKASH'S BLOG