This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Tomcat and the fly likes Unable to change permgen memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Unable to change permgen memory" Watch "Unable to change permgen memory" New topic
Author

Unable to change permgen memory

Diego Munch
Greenhorn

Joined: May 22, 2012
Posts: 5

Hi!!

We have a PermGen Out of memory exception in our J2EE 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.

Thank you very much!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Welcome to the JavaRanch, Diego!

Here's one I'm using successfully. It's in my setenv.sh file:

The JVM in question is a Sun Java 6 JDK.


Customer surveys are for companies who didn't pay proper attention to begin with.
Diego Munch
Greenhorn

Joined: May 22, 2012
Posts: 5
Thank you!
How can I check if this configuration is being applied? Is there any command to know how much PermGen memory is the maximum? We have tried "ps ax | grep tomcat" and "jstat -gcpermcapacity <PID>". The last one allways shows the same value for PGCMX(maximum memory): 83968.0, so we think that none of our configurations have been succesful.
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), so we don't know the exactly script which run Tomcat, that's the reason (we think) becouse our attempts failed.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Actually, the way I knew it worked was that Tomcat stopped throwing PermGenSpace errors!

I noticed that you were attempting to set PermGenSpace to a very large value. PermGenSpace is a separate memory space from Heap/Stack space and it doesn't need to be that large. Just larger than the default in cases like ours. I was using memory-statistics to determine requirements:


ps shows the memory usage for the entire VM, of which PermGenSpace is just a subset. I can't vouch for what WHM does, although hopefully it isn't so far off-track that it doesn't honor setenv.sh. If you can, try jprofiler. I believe that it can display PermGenSpace in real time graphically.
Diego Munch
Greenhorn

Joined: May 22, 2012
Posts: 5
We have using smaller values but the problem is the same. We don´t know if our modifications in the configutation files (setenv.sh or startup.sh or catalina.sh) have been applied.
Diego Munch
Greenhorn

Joined: May 22, 2012
Posts: 5
¡We have solved the problem!
Our application runs on WHM, and the script that runs 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!
Diego Munch
Greenhorn

Joined: May 22, 2012
Posts: 5
Wow! Without "¡", of course!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

¡Stellar!

Keep an eye on WHM, though. That particular configuration is for Tomcat 5. It works (for the moment) on Tomcat 6, but ¿quien sabe? on Tomcat 7.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Unable to change permgen memory