-1

In our application we have both, Apache Server (For frond end only) & JBoss 4.1 (For business end). We are using Ubuntu 12 as server OS. Our application is throwing "java.lang.OutOfMemoryError: Java heap space" continuously almost after every 2-3 Hours interval(So application start throwing Out of memory heap for hour or so and then again start working normally for next 2-3 hours then again start throwing Out of memory exception). Our Java memory settings are

-Xms512m -Xmx1024m

Our server has 6 GB of Ram physically. Please guide us do we need to increse java Heap size. If yes, what should be the ideal size considering physical 6GB of Ram.

Regards, Prateek

Alex
  • 111
  • 1
  • 5
  • It is also very important the technologies used in the application. Do you use any JDO/Entity beans? Please make sure that those are implemented properly as sometimes developers forget not to cache history data. Please also check the suggestion given by Sebastian. Please also do remember that OOM is not only for JVM memory , it can happen for no of open files. PLease check that too – Niks Apr 20 '16 at 05:48

3 Answers3

5

Have your application debugged. If you get an OOM after a couple hours, then chances are that something is really wrong with it, and you won't fix it by adding more memory. You'll just add more time until it dies. Furthermore, JBoss 4.1 is very old, so I assume nothing really fancy is running on it. Check the logs for connection leaks, heap dumps and stack traces for clues of leaks ant it's origin, run different usage tests on a non-production environment and measure how memory behaves upon each request. You can even use jmap and jdump to generate heap dumps and stack traces before and after a test to compare how the test affected the state of things, or schedule them to run at certain intervals and then check which objects are not being correctly cleaned-up by the GC. Also, turn on GC logging and dumping with these options:

set JAVA_OPTS=%JAVA_OPTS% -XX:OnOutOfMemoryError="%JAVA_HOME%\bin\jmap -dump:format=b,file=%JBOSS_HOME%\bin\heap_%%p.bin" -XX:ErrorFile=%JBOSS_HOME%\bin\hs_err_pid%%p.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=%JBOSS_HOME%\bin -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -Xloggc:%JBOSS_HOME%\bin\gc-%DATE:~-8,-4%%DATE:~-14,-12%%DATE:~-11,-9%.log -XX:-TraceClassUnloading

This will general heap dumps (heap_PID.bin), stack traces (hs_err_pidPID.log) and garbage collection logs (gc_DATE.log) on your JBOSS_HOME\bin folder (you can tune that at will).

The vast majority of the OOM's out there are due to application bugs, so always start looking at the application before throwing hardware to it. The hardware comes after you made sure everything else is right. Even when you get PM's and developers to hate you.

Sebastian

1

If doubling heap size wont solve issue, as joe suggests, I recommend to add

-XX:+HeapDumpOnOutOfMemoryError

argument to get post-mortem heapdump, which you should analyze carefully later for memory leaks with tool like Eclipse MAT memory analyzer, or jvisualvm from JDK.

Dmitry V.
  • 111
  • 2
0

Try doubling it. If you don't have many other processes using up the 6GB of ram then giving 1-2GB of RAM to the JVM should be fine.

-Xms1024m -Xmx2048m

You can also run your app using the following:

java -Xmx2g yourapp

You can also try profiling the application to spot possible memory leaks or to find out what is causing the app to use up so much memory.

See: jconsole

joe
  • 49
  • 2
  • I'd even say giving 2 to 3 GB of heap to your java app is fine, if that is the only big app on that server. You could even dare to give it 4 GB. Only, if you further increase memory to the java app above 2/3 of total memory, then you'll likely end up swapping to disk and thus slowing down the server. – Kai Petzke Jan 15 '15 at 10:37