Increase Tomcat memory settings [duplicate]
Asked Answered
P

1

83

Possible Duplicate:
Dealing with “java.lang.OutOfMemoryError: PermGen space” error

I have 8GB RAM in my development machine, and am trying to run Apache Tomcat (7.0.29) to host both Artifactory (2.6.3) and Jenkins (1.479) at the same time. I tried to find the memory requirements for Jenkins but it looks like their wiki is down.

In ${TOMCAT_HOME}/bin/catalina.sh, I have added the following command:

CATALINA_OPTS="$CATALINA_OPTS -server -Xms1024m -Xmx3052m"

This should keep Tomcat's JVM between (essentially) 1 and 3 GB in size, leaving me plenty of room for other stuff, and giving Tomcat enough memory for Artifactory/Jenkins, and even others if I wanted.

(For what it's worth I've tried the same with JAVA_OPTS only to get the same exact result). I save that change and run startup.sh. Tomcat begins to start up, and then dies with OOMEs complaining that Tomcat has ran out of PermGen space:

Exception in thread "SocketListener(<hex-stuff>.local.)"
java.lang.OutOfMemoryError: PermGen space
java.lang.OutOfMemoryError: PermGen space
java.lang.OutOfMemoryError: PermGen space
Exception in thread "hudson initialization thread" java.lang.OutOfMemoryError: PermGen space
java.lang.OutOfMemoryError: PermGen space

Where am I going awrye here? I have read multiple articles on how to do this and (believe!) I'm following them precisely. Any thoughts, or ideas as to how I could debug this further? Thanks in advance!

Paolo answered 2/10, 2012 at 10:38 Comment(2)
Have you tried increasing the permgen space? e.g. -XX:MaxPermSize=128mConfirmation
Hi @Confirmation - please see my comment underneath sgpalit's answer - I have the same question for you! Thanks again!Paolo
S
145

try setting this

CATALINA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 
-server -Xms1536m -Xmx1536m
-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"

in {$tomcat-folder}\bin\setenv.sh (create it if necessary).

See http://www.mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-space/ for more details.

Samsara answered 2/10, 2012 at 10:43 Comment(9)
Hi, please refrain from link-only answers, and try to get as much as possible into the main answerAnswer
Thanks @Samsara (+1) - I'll give it a try here soon. Just curious, if I want my Java heap to be ~3GB in size, how big should my PermGen be?Paolo
The PermGem memory is used to compile and optimize classes. So it dependes on your application how much perm gen you should use. It should be as little as possible (to leave as much for the heap), but not too small that it runs out.Confirmation
As Augusto mentioned your PermGen size should not too big. Usually I use 256m for artifactory and hudson, it is enough. For detailed information you can look to the below article. integratingstuff.com/2011/07/24/…Samsara
In my case I didn't modify the sh file. I was a bit discouraged by the fact that on the server there is yum repo and Tomcat was installed from there. I just modified /usr/share/tomcat7/conf/tomcat7.conf and added the aforementioned options.Gregarine
The RUNNING.txt that comes with Tomcat states: "Note: Do not use JAVA_OPTS to specify memory limits. You do not need much memory for a small process that is used to stop Tomcat. Those settings belong to CATALINA_OPTS." As this seems to be a well read answer, you may add that.Trifle
A 1.5 Gig stack is excessive -Xms1536m. A much smaller -Xms128m or -Xms256m should be plenty. This would allow the heap size -Xmx1536m could be increased to say -Xmx2048mLilybelle
@MartinSpamer - -Xms has nothing to do with stack size. See java -X for a description of what these settings actually do. Using -Xms1536m is perfectly reasonable, and having -Xms set to the same as -Xmx makes the process more efficient if you know it is eventually going to use all or nearly all of its heap.Adjunct
Also if tomcat is running on windows as a windows service the catalina.bat says this: "The configuration that controls Windows Services is stored in the Windows Registry, and is most conveniently maintained using the "tomcatXw.exe" maintenance utility, where "X" is the major version of Tomcat you are running."Austinaustina

© 2022 - 2024 — McMap. All rights reserved.