How to obtain a heap dump on OutOfMemoryError
Can be used to obtain a heap dump of the module running on Docker and Vagrant in case the application crashes with OutOfMemoryError.
Step-by-step guide
- Add the -XX:+HeapDumpOnOutOfMemoryError option to the docker-DeploymentDescriptor.json in case you're deploying modules using How to automate new modules’ registration within folio/testing-backend Vagrant box guide
2. Simulate the condition that leads to the OutOfMemoryError and wait for the heap dump file to be written. That should be reflected in the container's log - docker logs -f {container_id}
3. Run docker exec -it {container_id} bash and find the heap dump file. Run realpath {file_name} and copy the path.
4. Copy the heap dump file to the vagrant folder docker cp {container_id}:{file_path} /vagrant
5. The heap dump file now should be accessible from the host machine
6. Open the file with your favorite analyzer, for example Eclipse Memory Analyzer, and dig deep to find the root cause. Good luck!
To find out about other ways to get a heap dump check out the useful link provided below. Learn How to connect Java profiler to the module running on Docker + Vagrant guide for monitoring the heap state on the fly.