如何增加内存并修复grails中"超出GC开销限制"错误

gra*_*bie 3 grails out-of-memory

我尝试在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],
Run Code Online (Sandbox Code Playgroud)

]

与"跑步"相同

但是,我仍然在堆栈跟踪中遇到GC开销限制超出错误.不确定我正在使用BuildConfig做什么是正确的还是我错过了什么 - 但请随时发表评论.谢谢

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

小智 6

通过内存设置,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]
Run Code Online (Sandbox Code Playgroud)

另一件事是在tomcat中运行应用程序,使用更大的堆,例如2gb,然后查看GC错误是否消失.顺便说一下,我发现,Grails的工作方式要好得多,新的G1垃圾收集器和JVM上的-server标志.

从我的setenv.sh我的生产Tomcat7实例:

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"
Run Code Online (Sandbox Code Playgroud)