当它作为守护程序在Ubuntu上运行时,如何给Jenkins更多的堆空间? [英] How do I give Jenkins more heap space when it's running as a daemon on Ubuntu?

查看:190
本文介绍了当它作为守护程序在Ubuntu上运行时,如何给Jenkins更多的堆空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Jenkins作业内存不足,在构建日志中给出了java.lang.OutOfMemoryError消息.但是我使用Ubuntu Package Manager,aptitudeapt-get来安装Jenkins,但我不知道在哪里寻找更改分配给Jenkins的堆空间的数量.

解决方案

在Jenkins作业运行时,您可能会遇到两种类型的OutOfMemoryError消息:

  • java.lang.OutOfMemoryError: Heap space –这意味着您 需要增加分配给Jenkins的堆空间量 守护程序启动.
  • java.lang.OutOfMemoryError: PermGen space –这意味着您需要增加 分配用于存储Java对象元数据的生成空间量.越来越多 -Xmx参数的值对此错误没有影响.

在Ubuntu 12.04 LTS上,取消注释/etc/default/jenkins的第10行上的JAVA_ARGS设置:

  • 要添加更多的Java堆空间,请增加-Xmx Java参数的值.设置内存分配池(垃圾收集堆)的最大大小.
  • 要添加更多的PermGen空间,请添加参数XX:MaxPermSize=512m(如果需要更多的内容,请用其他内容代替512.永久生成堆保存有关用户类的元信息.

例如,此摘录来自全新安装的Jenkins之后的默认/etc/default/jenkins:

 # arguments to pass to java
#JAVA_ARGS="-Xmx256m"
 

这是将堆空间设置为1 GB时的外观:

 # arguments to pass to java
JAVA_ARGS="-Xmx1048m"
 

请注意不要将堆大小设置得太大,因为分配的任何内容都会减少操作系统和其他程序可用的内存量,这可能会导致过多的页面调度(RAM和交换磁盘之间来回交换内存,这会降低您的系统速度).

如果还设置了MaxPermSpace,则需要在参数之间添加一个空格):

 # arguments to pass to java
JAVA_ARGS="-Xmx1048m -XX:MaxPermSize=512m"
 

进行更改后,可以从Jenkins Web界面正常重启Jenkins,或者使用sudo /etc/init.d/jenkins restart从命令行强制立即重启.

我发现以下站点对于理解Java最大和永久生成堆大小很有用: 解决方案

There are two types of OutOfMemoryError messages that you might encounter while a Jenkins job runs:

  • java.lang.OutOfMemoryError: Heap space – this means that you need to increase the amount of heap space allocated to Jenkins when the daemon starts.
  • java.lang.OutOfMemoryError: PermGen space – this means you need to increase the amount of generation space allocated to store Java object metadata. Increasing the value of the -Xmx parameter will have no affect on this error.

On Ubuntu 12.04 LTS, uncomment the JAVA_ARGS setting on line ten of /etc/default/jenkins:

  • To add more Java heap space, increase the value of the -Xmx Java parameter. That sets the maximum size of the memory allocation pool (the garbage collected heap).
  • To add more PermGen space, add the parameter XX:MaxPermSize=512m (replace 512 with something else if you want more. The permanent generation heap holds meta information about user classes.

For example, this extract is from the default /etc/default/jenkins after a fresh install of Jenkins:

# arguments to pass to java
#JAVA_ARGS="-Xmx256m"

This is how it would look if you set the heap space to be 1 GB:

# arguments to pass to java
JAVA_ARGS="-Xmx1048m"

Be careful not to set the heap size too large, as whatever you allocate reduces the amount of memory available to the operating system and other programs, which could cause excessive paging (memory swapped back and forth between RAM and the swap disc, which will slow your system down).

If you also set MaxPermSpace, you need to add a space between the parameters):

# arguments to pass to java
JAVA_ARGS="-Xmx1048m -XX:MaxPermSize=512m"

After making a change, restart Jenkins gracefully from the Jenkins web interface, or force an immediate restart from the command-line with sudo /etc/init.d/jenkins restart.

I found the following site useful for understanding Java maximum and permanent generation heap sizes: http://www.freshblurbs.com/blog/2005/05/19/explaining-java-lang-outofmemoryerror-permgen-space.html.

这篇关于当它作为守护程序在Ubuntu上运行时,如何给Jenkins更多的堆空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆