kasdega
kasdega

Reputation: 18786

How to debug a java heap OutOfMemory error in a production environment?

Our web app is running in tomcat7 and we're using java 1.7.0_55....In the past when we've had problems we've been able to debug in our development environments using Eclipse and a profiler (the name escapes me at the moment).

Now we're getting an OutOfMemory exception in our production environment. I'm quite leery of running a profiler in a production environment so my question is...Is there any way to debug this problem in the production environment without using a profiler or is there something that is light-weight enough that I could run it in production?

Upvotes: 5

Views: 1759

Answers (4)

amith
amith

Reputation: 409

If you are very much concern with running a profiler in production environment run the jmap -histo:live pid

histogram is the summary of the heap, its very lite weight and will take very less time to generate data for you. This will be of good use if you dont have HeapDumpOnOutOfMemoryError is not set.

Its always better to take a heap dump on OOME Java provides a system switch to do this by flag -XX:+HeapDumpOnOutOfMemoryError this will generate heap dump file.

Heap dump file contain all the objects related information in it. It can be easily analysed using jhat . This will open the dump file and analyze the data and listen to a port that will be displayed in console.

If the GC logs are configured have a look at the GC logs and identify the time from when the memory consumption increased significantly. From the logs try to identify the actions done/requests processed by your tomcat, go through the code and try to identify if there are any memory leaks caused in the code. You can use the histogram as reference since histo provides the objects count as well.

If you are using some cache in your application check what is the max size configured for cache, or is cache is cleared at regular intervals ....

Hope this is helpful.

Upvotes: 1

techPackets
techPackets

Reputation: 4504

Just take a heap dump of production server & analyse it with Eclipse Memory analysis tool. You can copy the heapdump to your local. Eclipse Memory Analyzer is the best tool for this job. However, trying to get the UI to run remotely is very painful. Launching Eclipse and updating the UI is an extra load on the JVM that is already busy analyzing a 30G heap dump. Fortunately, there is a script that comes with MAT to parse the the heap dump and generate HTML reports without ever having to launch Eclipse!

Check this out.

Upvotes: 2

codeaholicguy
codeaholicguy

Reputation: 1691

If you want to profile your application on production you can use jConsole for real histogram from your production system. If you can pay, you should try jProfiler (https://www.ej-technologies.com/products/jprofiler/overview.html). Its really helpful for dumping data of JVM on production enviroment.

Upvotes: 1

Gaurav Mahawar
Gaurav Mahawar

Reputation: 534

Set a higher Xmx limit.

-Xmx2048M or more if needed.

Upvotes: -2

Related Questions