Our dockerized Java application memory usage increases minute to minute. See %MEM and RES and Virt Memory smooth increase
- Run Test App
docker run -it --rm pamir/jvm-cases MemoryLeak
- Check, that our app is idle(%CPU=~0.0):
top -c -p $(pgrep -d',' -f java)
- Get id of container with our application(java application.jar ...):
docker ps
- Run container with jattach utility:
docker run --rm -it \
--net=container:8b0970e1aa99 \
--pid=container:8b0970e1aa99 \
-v /tmp:/tmp \
--privileged \
adriantodt/alpine-zlib-jattach \
/bin/sh
- Dump Heap with jattach
jattach 1 heapdump /tmp/memoryleak1.hprof
jattacj 1 heapdump /tmp/memoryleak2.hprof
- Be careful the dump files are not in in on jattach container. They are on java container's tmp directory
ls -lart /tmp
- Copy Dump files from java container to host machine
docker cp 8b0970e1aa99:/tmp/memoryleak1.hprof /tmp/memoryleak1.hprof
docker cp 8b0970e1aa99:/tmp/memoryleak2.hprof /tmp/memoryleak2.hprof
-
Download Memory Dump Analzyer Tool
http://www.eclipse.org/mat/ -
Open memoryleak1.hprof Dump File and see leak suspect report
-
Open Histogram and sort by retained heap size
-
Go to incoming References and sort by Retained Heap Size
-
Expand the top level Arraylist and see what is holding it
- drop capabilities
- Add Reference to Charlie Hunt Book Java Performance
- Refer to Source Code