I have an enterprise application on which i am working and currently its on staging environment. Server has 24 GB of RAM. But after average of 15-20 days server goes down and we see out of memory space error in server logs. I am using J2EE, spring, hibernate, memcache, ehcache, mysql and tomcat8.
I have used nginx for clustering and there are 3 nodes of tomcat server.
Please suggest/help what should i do because i am unable to trace/get where this error is coming from and from where this memory leakage is occurring.
Thanks
2
Answers
Take a heap dump using how-to-collect-a-heap-dump, analyze it using eclipse tool called Mat. This will gives you clear cut picture of your memory and will let you know what is going wrong in your code that is causing OOM error.
It’s possible your program is allocating many objects in the heap, and never allowing the Garbage Collector to release them.
To diagnose you can do a heap dump of your service, this is done with the command:
where
<pid>
is the process id of your Java service (which you can find with the commandps faux | grep java
).Then you can VisualVM to open the file
dump.bin
and inspect it to see which objects are using most of your heap.Because the heap dump will be big and will include objects that are ready for Garbage Collection, you might want to tell
jmap
to only put in the heap dump those objects that can’t be garbage collected, this is done adding the flaglive
to thejmap
command:Here are instructions for using VisualVM to inspect a heap dump: https://docs.oracle.com/javase/8/docs/technotes/guides/visualvm/heapdump.html