Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I increase memory and fix a "GC overhead limit exceeded" error in Grails?

I have tried changing the memory usage configuration in BuildConfig:

grails.project.fork = [

    // Configure settings for the test-app JVM, uses the daemon by default
    test: [maxMemory: "changedThis", minMemory: 64, debug: false, maxPerm: 256, daemon:true],
]

The same as with "run".

However, I'm still getting the GC overhead limit exceeded error in my stacktrace. Is what I'm doing with the BuildConfig is right or am missing something?

PS: The scenario is I'm processing a 500,000 lines of number (at most eight characters at length) from a file and that we don't want it be processed separately

like image 794
grails newbie Avatar asked Mar 17 '23 07:03

grails newbie


1 Answers

With your memory settings the JVM, when running in development/test mode on your local computer, it is probably running out of memory when trying to create the objects and therefore is running GC trying to reclaim memory and throwing the exception. Here is an example of a grails.project.fork from a project where I have to create a lot of objects on startup in BootStrap.groovy:

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: 768, debug: false, maxPerm: 768, daemon:true],
// Configure settings for the run-app JVM
run: [maxMemory: 4560, minMemory: 1024, debug: false, maxPerm: 2560, forkReserve:false],
// Configure settings for the run-war JVM
war: [maxMemory: 4560, minMemory: 2560, debug: false, maxPerm: 2560, forkReserve:false],
// Configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]

Another thing to try is running the application in Tomcat with a much, much larger heap, such as 2 GB, then see if your GC error goes away. By the way, Grails works much better, I have found, with the new G1 garbage collector and the -server flag on the JVM.

From my setenv.sh file for my production Tomcat 7 instance:

export CATALINA_OPTS="$CATALINA_OPTS -Xms6g"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx6g"
export CATALINA_OPTS="$CATALINA_OPTS -XX:+UseG1GC"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=768m"
like image 167
Gregory D. Dickson Avatar answered Apr 06 '23 22:04

Gregory D. Dickson