Skip to content

Latest commit

 

History

History
74 lines (55 loc) · 1.66 KB

memoryleak.md

File metadata and controls

74 lines (55 loc) · 1.66 KB

MemoryLeak

Our dockerized Java application memory usage increases minute to minute. See %MEM and RES and Virt Memory smooth increase

  1. Run Test App
docker run -it --rm  pamir/jvm-cases MemoryLeak

  1. Check, that our app is idle(%CPU=~0.0):
top -c -p $(pgrep -d',' -f java)

Steps To Analyze

  1. Get id of container with our application(java application.jar ...):
docker ps
  1. 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
  1. Dump Heap with jattach
jattach 1 heapdump /tmp/memoryleak1.hprof
jattacj 1 heapdump /tmp/memoryleak2.hprof
  1. Be careful the dump files are not in in on jattach container. They are on java container's tmp directory
ls -lart /tmp
  1. 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
  1. Download Memory Dump Analzyer Tool

    http://www.eclipse.org/mat/

  2. Open memoryleak1.hprof Dump File and see leak suspect report

  3. Open Histogram and sort by retained heap size

  4. Go to incoming References and sort by Retained Heap Size

  5. Expand the top level Arraylist and see what is holding it

Todo

  • drop capabilities
  • Add Reference to Charlie Hunt Book Java Performance
  • Refer to Source Code