简体   繁体   中英

Grails Tomcat OutofMemory error

I have a Grails app that I have packed with the war command: grails war . I need to deploy it to a remote machine running Tomcat.

When I do the drop deploy (copying the WAR file into C:\\Program Files (x86)\\apache-tomcat-7.0.37\\webapps ) and run C:\\Program Files (x86)\\apache-tomcat-7.0.37\\bin\\startup.bat I am getting several OutofMemory errors with PermGem and Heap space.

How can I fix this?

What I usually do when starting tomcat :

export JAVA_OPTS="-Xms1024m -Xmx2024m -XX:MaxPermSize=512m"; export CATALINA_OPTS="-Xms1024m -Xmx2024m -XX:MaxPermSize=512m"; /etc/init.d/tomcat6 restart; tail -f /var/lib/tomcat6/logs/catalina.out

That fixes all memory problems. I have 6 Grails applications running with that configuration.

On the Tomcat server, add a system environment variable: JAVA_OPTS -Xmx512m

Also, in your Grails app in the conf/BuildConfig.groovy add the line at the following line at the top: grails.tomcat.jvmArgs= ["-Xms256m", "-Xmx1024m", "-XX:PermSize=512m", "-XX:MaxPermSize=512m"]

This seems to have solved many of the issues I was facing.

If you are using Ubuntu, I'd recommend editing /etc/default/tomcat6 (or tomcat7 depending on what you're running).

Around line 20 is a sample JAVA_OPTS line; uncomment it, and edit it to suit your hardware.

I've got mine running as:

 JAVA_OPTS="-Djava.awt.headless=true -Xmx1024m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC"

Which caps the RAM in use at a gig, and sets permsize to 512m.

Use the default values on Grails Build.config Change on this point:

grails.project.fork = [
// configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
//  compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],

// configure settings for the test-app JVM, uses the daemon by default
test: [maxMemory: 768, minMemory: 64, debug: true, maxPerm: 256, daemon:true],
// configure settings for the run-app JVM
run: [maxMemory: 500, minMemory: 64, debug: true, maxPerm: 256, forkReserve:false],
// configure settings for the run-war JVM
war: [maxMemory: 500, minMemory: 64, debug: true, maxPerm: 256, forkReserve:false],
// configure settings for the Console UI JVM
console: [maxMemory: 500, minMemory: 64, debug: true, maxPerm: 256]

]

if you are using service based tomcat then you may not have catalina.bat file in bin folder. Then try to add these java options. 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM