在容器中运行作业一小时后,由于内存不足导致Java进程被终止

时间:2018-03-27 18:22:24

标签: docker circleci

我已经在CircleCI(https://hub.docker.com/r/jiteshsojitra/docker-headless-vnc-container)中设置了运行自动化测试的工作,它工作正常,但在运行测试一小时后达到内存限制并突然杀死正在运行的Java / ant作业。那么有没有办法增加容器内存,所以测试可以在容器或其付费功能中运行5-6小时?

我尝试将- JAVA_OPTS: -Xms512m -Xmx1024m放在YAML脚本中,但整体容器内存大小达到了~4GB。

的参考文献:

https://circleci.com/gh/jiteshsojitra/zm-selenium/231
https://circleci.com/api/v1.1/project/github/jiteshsojitra/zm-selenium/231/output/106/0?file=true

日志记录:

BUILD FAILED
/headless/zm-selenium/build.xml:348: Java returned: 137

Total time: 76 minutes 26 seconds
Exited with code 137

Hint: Exit code 137 typically means the process is killed because it was running out of memory
Hint: Check if you can optimize the memory usage in your app
Hint: Max memory usage of this container is 4286337024
according to /sys/fs/cgroup/memory/memory.max_usage_in_bytes

2 个答案:

答案 0 :(得分:2)

我们遇到了这个问题。 It is a limit in CircleCI (or the VM, really)。唯一的解决方案是让您的应用使用更少的内存。

答案 1 :(得分:0)

菲斯凯本是对的。我认为你提到的容器是我们consol/docker-headless-vnc-container图像的分支。因此,您可以在启动脚本中添加以下行。

# set correct java startup
export _JAVA_OPTIONS="-Duser.home=$HOME -Xmx${JVM_HEAP_XMX}m"
# add docker jvm flags, can maybe removed with JDK9
export _JAVA_OPTIONS="$_JAVA_OPTIONS -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"

现在,您可以将环境变量JVM_HEAP_XMX设置为您的JVM应使用的兆字节数,例如

docker run -e JVM_HEAP_XMX=512 ... 

如果要动态确定大小,请查看该脚本jvm_options.sh