Tomcat memory consumption issue - java

I have a java application running on tomcat with xmx=2GB
I see memory consumption slowly raises on tomcat, exceeding the 2GB heap limit.
Going through this forum I know that there more than just the heap consuming the memory.
The problem is that memory keeps raising above 3 and even 4GB until no more memory is available on the machine, and I need to restart tomcat.
Looking at the GC log, I see that the heap does not exceed 2GB.
My question is how can I find and analyze the memory been used.
Also, can it be code related?
It is obviously some kind of leak, but I don't know how to locate and fix it, or even identify the source (my code, tomcat, etc).
Thanks
Maayan

Since it is more likely to be a memory leak in your code than in tomcat, I'd start here.
Create a heap dump using JMap, and try to analyze it using a tool like the Eclipe Memory Analyzer

Related

Managing Java Memory with Xms and Xmx

I had a java application that runs as a daemon process. Initially, I discovered that after about a week, the applicaiton would throw an out of memory error. I researching, I discovered that I could manage the memory and avoid the problem by setting the -Xms and -Xmx flags at startup to specify how much memory the application would have. This ultimately resolved my memory problem.
However, later on, I discovered that the application was causing performance issues on some machines that only had 1GB of memory, 1GB of memory was how much I had allocated for -Xmx. So the java application took all of available memory.
So using jconsole, I was about to determine that the application ran at about 150mb. So using that information, I dropped the -Xmx value to 300mb. Thinking that it would be plenty. But then I discovered that the application was only using about 15mb. Why? Why does the application use 150mb when its allocated 1GB, but only 15mb when its allocated 300mb?
And how do I go about figuring out what I should be using?

Java memory usage via linux top keep increasing in small percentage?

We have a socket listener programme running on centos machine. What is worrying is that the memory usage for the application via the top keep showing come minor increment. On the other hand the if we use the jstat gcutil it shows some minor increase in the Permanent Generation but so far they have been no FGC but many YGC. Could this be indicating any memory issue? Both max and initial memory have been set to 256M.
Could this be indicating any memory issue?
Maybe. What you are describing could be a memory leak caused by a bug in your application. If that is the problem, then eventually the application will fill up the Java heap .... and die with an OutOfMemoryError.
If you want to confirm this, try running the application with a much smaller heap; i.e. a smaller max heap size. If you have a leak, the application will crash after a shorter time.
There are lots of resources on finding Java memory leaks. Here are some:
General strategy to resolve Java memory leak?
How to find a Java Memory Leak
http://netbeans.org/kb/articles/nb-profiler-uncoveringleaks_pt1.html
http://rejeev.blogspot.com.au/2009/04/analyzing-memory-leak-in-java.html
There are other possible explanations for this ... including "there is no problem". But if you get OOME's then you do have a real problem.

Is my Glassfish setup leaking memory?

I've got a Glassfish v3 server running a few web applications (servlets, JSP, JDBC). I'd been noticing that if I let Glassfish run for a long time, it will consume all of the memory available (this is running on a server with 750 MB of memory).
I figured that there must be a memory leak, so I ran the server while monitoring it with JProfiler and noticed that when I get a peak in traffic, my memory usage shoots up (as expected), but then quickly drops back down.
I'm wondering if the issue is less of a memory leak, and more that Glassfish expands its heap size when the spikes occur (this does seem to be happening) but never decreases the heap size when the actual memory usage declines.
However, based on this graph, it does seem like the memory usage (blue) is trending upwards as the server runs longer.
My question is two-fold:
Is there any way to have the heap size decreased when the actual memory usage drops after a spike?
Is it probable that I do have a memory leak, or is this normal? What can I do to investigate this memory usage further?
It does not look like a memory leak, as memory would keep on growing forever and it would really start blowing up with OOM errors, this is most likely the HotSpot compiler turning interpreted code into native code and this is surely going to claim memory and never give it back, as this memory goes to the eternal generation.
You should probably use a tool like JConsole or VisualVM to make sure that this is a leak and not something else.
For 1. There is no way to do this.
For 2. you can use VisualVm to see where you are actually using memory.

Jboss memory problem

I am facing "Out Of Memory Error Exception" while running a web service application over jboss 4.2
how can I increase the memory of jboss ? and will this solve the problem ?
You should first confirm if the memory usage is not abnormal. If it is not, it is probably a good idea to increase the memory allocation. JBoss default memory allocation is rather small at the default setting.
You want to confirm that the memory shortage is heap shortage (it could be permgen etc. if it is permgen, please refer to general OOME (OutOfMemoryError) questions). If you are using Java 1.6 you just need to read the exception message to determine this.
Once you confirm it is a heap shortage, it is advisable to confirm that there is no memory leak occurring before you go for a bigger heap size. To do this, you can attach a heap monitor like visualVM and monitor heap usage under stress (for more information see this: http://olex.openlogic.com/wazi/2009/how-to-fix-memory-leaks-in-java/).
Once you are done with this, and you are sure that you have a legitimate heap shortage, you can edit run.conf (Linux) or run.bat (Windows) to allocate more heap. You can search for JAVA_OPTS and change -Xmx512m to something like -Xmx1024m.
You can increase the memory for JBoss, but make sure to find out why it uses more memory than expected to make sure the problem doesn't come back to bite you.
Set this in your shell before launching JBoss while experimenting:
JAVA_OPTS="-Xms512m -Xmx1024m"

JAVA Heap stack Error

I have developed a barcode billing and inventory software using netbeans 6.5. I dont know why when the application runs for some time then some times it gives a JAVA Heap stack (Out of Memory) err. I know there is some way to handle the memory allocation in netbeans. Could anyone please help me on this..
Thankx
You need to figure out if your application needs a bigger working memory than the default setting, or if it is just leaking. If there is a memory leak (which is a common problem), then increasing the total memory will only give your application more time before it crashes. It's easy to do (as other posters have suggested) and it will show you if there is a bad leak, so try it first. If it keeps growing in memory, you need to look at what your application is holding onto in memory. Have a look at JConsole (which comes with Java6) or JHat or other tools.
You should pass the argument -Xmx1024m when starting your program, so that the jvm can use more heap for your application. This -Xmx will give your programm 1024mb of ram.
Use java -Xmx<size>m to set the maximum size for the heap. And use a memory profiler like JMP(Java Memory Profiler) to figure out the memory consumption.
Similar questions on SO:
java-lang-outofmemoryerror-java-heap-space-with-netbeans
java-heap-space-in-netbeans-but-ive-increased-the-heap-size-already

Categories

Resources