如何增加内存并修复 Grails 中的 "GC overhead limit exceeded" 错误?

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

我试过更改 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],
]

与“运行”相同。

但是,我的堆栈跟踪中仍然出现 GC 开销限制超出错误。我对 BuildConfig 所做的是正确的还是遗漏了什么?

PS:场景是我正在处理一个文件中的 500,000 行数字(最多八个字符),我们不希望单独处理它

使用 JVM 的内存设置,当本地计算机上 运行 处于 development/test 模式时,它可能 运行 在尝试创建对象时内存不足,因此运行 GC 试图回收内存并抛出异常。这是一个 grails.project.fork 项目的示例,我必须在 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]

另一件要尝试的事情是 运行 Tomcat 中的应用程序具有更大、更大的堆,例如 2 GB,然后查看您的 GC 错误是否消失。顺便说一下,我发现 Grails 使用新的 G1 垃圾收集器和 JVM 上的 -server 标志工作得更好。

来自我的 setenv.sh 生产文件 Tomcat 7 个实例:

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"