0

We have a PermGen Out of memory exception in our Java EE web application:

java.lang.OutOfMemoryError: PermGen space

We have read so many posts about how to solve it and almost all of them say that we have to increase PermSize (default and maximum). But we are not able to change them. We have tried to modify setenv.sh, catalina.sh and startup.sh adding this code:

export JAVA_OPTS="-XX:PermSize=M -XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled"

And we also try to do it using the terminal:

export JVM_ARGS="-XX:PermSize=256m-XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled"

But when we check it using "jstat -gcpermcapacity " nothing changes; the memory is always the same. Our enviroment is Centos 6, Apache 2.2, Tomcat 5.5, Java 6 and we have done our app deploy installing servlets by WHM in our account.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
xmunch
  • 15
  • 1
  • 7
  • You will probably want to use CATALINA_OPTS and not JAVA_OPTS: CATALINA_OPTS will be used for both startup and shutdown (you probably don't need a huge heap and extra permgen space just to send "SHUTDOWN" to the shutdown port). Also, JVM_ARGS does not affect anything. – Christopher Schultz May 22 '12 at 15:57
  • How do you actually launch Tomcat? Using CentOS scripts, or using bin/startup.sh? – Christopher Schultz May 22 '12 at 15:58
  • Thanks Christopher! Actually our server run Tomcat through WHM and cPanel. We use an account function to install servlets and when we change something in our webapp we use the "restart Tomcat" option in WHM (which is a webhost manager, a cPanel's layer). We can't locate Tomcat's start script!! – xmunch May 23 '12 at 11:32
  • You'll have to find out how cPanel and the webhost manager does its stuff... otherwise, you can set all the environment variables you want and it probably won't affect the JVM. – Christopher Schultz May 23 '12 at 19:11

2 Answers2

2

Try changing it in your tomcat.conf. Actually, check with ps ax | grep java to see what command line has been run to generate your parameters. Mine produces:

26552 pts/1 Sl 0:36 /usr/lib/jvm/jre/bin/java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n -Xmx1024m -XX:MaxPermSize=128m -classpath :/usr/share/tomcat6/bin/bootstrap.jar:/usr/share/tomcat6/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat6 -Dcatalina.home=/usr/share/tomcat6 -Djava.endorsed.dirs= -Djava.io.tmpdir=/var/tmp/tomcat6 -Djava.util.logging.config.file=/usr/share/tomcat6/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager org.apache.catalina.startup.Bootstrap start

this is on tomcat6, java6, centos 5.5

Woody
  • 5,052
  • 2
  • 22
  • 28
  • Thanks, Woody! But we can´t find tomcat.conf in /usr/local/jakarta/tomcat/bin and /usr/local/jakarta/tomcat/conf. Where is it? – xmunch May 22 '12 at 11:56
  • On my system it is in /usr/share/tomcat6/conf, but I would imagine it could be instance specific. I found mine by looking in /etc/init.d/tomcat6 – Woody May 22 '12 at 12:28
  • I have not any tomcat reference in /etc/init.d/ :-( – xmunch May 22 '12 at 13:20
  • /usr/local/jdk/bin/java -Djava.util.logging.config.file=/usr/local/jakarta/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/jakarta/tomcat/common/endorsed -classpath /usr/local/jakarta/tomcat/bin/bootstrap.jar -Dcatalina.base=/usr/local/jakarta/tomcat -Dcatalina.home=/usr/local/jakarta/tomcat -Djava.io.tmpdir=/usr/local/jakarta/tomcat/temp org.apache.catalina.startup.Bootstrap -server -XX:PermSize=1024m -XX:MaxPermSize=1024m -XX:+DisableExplicitGC -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled start – xmunch May 22 '12 at 13:22
  • ok, the thing that starts your tomcat service (init.d/tomcatx would start the service if it was setup). In your process list of the item that ran tomcat, can you see what your catalina.base is? – Woody May 22 '12 at 13:24
  • This is the response. That seems all is ok, is not? But the problem continues. – xmunch May 22 '12 at 13:25
  • As you can see above, something happened and permSizeMemory is big (1024m) but the problem remains – xmunch May 22 '12 at 13:29
  • your MaxPermSize is very large. How much memory do you have on this machine, as that size is reserved out of your total, so that 1024 is taken off your total memory. I would bring it down a bit, and play with the other settings. I had a hell of a job getting it sorted until I ended up at those settings – Woody May 22 '12 at 13:31
  • We have 8 GB RAM memory. We are testing, but the problem persist. Sorry, I don't understand your last words, ¿did you had a hell in your job with the same problem we have? How did you do it? We don't know what to do after the increase of the memory!..Thank you very much! – xmunch May 22 '12 at 14:16
  • Yes, I had a big problem with it. I sat down with a profiler and worked out exactly how much memory I needed. I would reduce your permsize and use -Xmx1024m -XX:MaxPermSize=128m to start with, see what the response is. – Woody May 22 '12 at 14:46
  • @xmunch Are you restarting your webapp without restarting Tomcat? If so, you may be leaking a WebappClassLoader if your webapp does not shut down properly. – Christopher Schultz May 22 '12 at 16:04
  • No, I'm restarting Tomcat using WHM. – xmunch May 23 '12 at 11:51
  • Solved! I found starttomcat file in usr/sbin/ – xmunch May 23 '12 at 15:05
0

We have solved the problem! Our application runs on WHM, and the script that execute the restart of Tomcat does not use the startup.sh file. In our case, the reset is performed by "starttomcat", a file found in /usr/bin. We have modified the file, leaving the variable my @ cmd as follows:

my @cmd = (

"./jsvc",
"-user",
"$user",
"-XX:PermSize=64M",
"-XX:MaxPermSize=512m",
"-cp",
"$jars",
"-Djava.endorsed.dirs=../common/endorsed",
"-outfile",
"${logdir}/catalina.out",
"-errfile",
"${logdir}/catalina.err",
"-verbose",
@options,
"org.apache.catalina.startup.Bootstrap",
#"-security",
"start",
);

It runs!

xmunch
  • 15
  • 1
  • 7