【问题标题】:How can I increase memory and fix a "GC overhead limit exceeded" error in Grails?如何增加内存并修复 Grails 中的“超出 GC 开销限制”错误?
【发布时间】:2015-01-22 11:14:03
【问题描述】:

我已尝试在 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 行数字(最多八个字符),我们不希望单独处理它

【问题讨论】:

  • “处理”是什么意思?您是否将文件视为一个大块?
  • 是的,将所有 500k 行提取到字符串列表中。我们不能使用数据库来临时存储这个数据。

标签: grails out-of-memory


【解决方案1】:

使用您的 JVM 内存设置,当您在本地计算机上以开发/测试模式运行时,它可能在尝试创建对象时内存不足,因此正在运行 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 标志。

从我的生产 Tomcat 7 实例的 setenv.sh 文件中:

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"

【讨论】:

  • 这让我知道要调查什么。抱歉,由于我需要更多声望点,因此无法将其投票作为感谢。欢呼
猜你喜欢
  • 1970-01-01
  • 2010-11-26
  • 1970-01-01
  • 1970-01-01
  • 2016-10-23
  • 1970-01-01
  • 2018-04-10
  • 2021-01-07
相关资源
最近更新 更多