Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I give Jenkins more heap space when it's running as a daemon on Ubuntu?

My Jenkins jobs are running out of memory, giving java.lang.OutOfMemoryError messages in the build log. But I used the Ubuntu Package Manager, aptitude, or apt-get to install Jenkins, and I don't know where to look to change the amount of heap space allocated to Jenkins.

like image 967
Steve HHH Avatar asked Feb 07 '13 22:02

Steve HHH


People also ask

How do I increase the amount of heap space allocated to Jenkins?

In your Jenkins installation directory there is a jenkins. xml, where you can set various options. Add the parameter -Xmx with the size you want to the arguments-tag (or increase the size if its already there).

How can we increase the size of heap in a running process?

Just use a function like malloc() or calloc() to allocate memory dynamically. To deallocate the memory and return it to the heap, use free() . These functions will manage the size of the heap by expanding or shrinking it as needed.


1 Answers

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.

like image 160
Steve HHH Avatar answered Oct 06 '22 20:10

Steve HHH