Configuring Hudson Java Memory Settings When Running It As A Service

The default hudson installation as a windows or linux service is configured to use 256MB of system memory. While the memory might be good enough to start with, it might not be high enough to do complex or larger builds. If your application build process is memory intensive, you will probably start seeing the build failures with Hudson complaining about heap space.

For example, when I try to run the Cobertura code coverage, which is a memory intensive process as it requires loading of several thousands of JUnit XML reports for my fairly large project, into the Hudson server that is running as a service, here is the exception stack trace that I encountered.

Publishing Cobertura coverage report...
Publishing Cobertura coverage results...
FATAL: Java heap space
java.lang.OutOfMemoryError: Java heap space
	at com.sun.org.apache.xerces.internal.util.XMLStringBuffer.append(XMLStringBuffer.java:205)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.refresh(XMLDocumentScannerImpl.java:1522)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.invokeListeners(XMLEntityScanner.java:2070)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(XMLEntityScanner.java:1415)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2793)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
	at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
	at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
	at hudson.plugins.cobertura.CoberturaCoverageParser.parse(CoberturaCoverageParser.java:81)
	at hudson.plugins.cobertura.CoberturaCoverageParser.parse(CoberturaCoverageParser.java:52)
	at hudson.plugins.cobertura.CoberturaPublisher.perform(CoberturaPublisher.java:265)
	at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36)
	at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:630)
	at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:608)
	at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:584)
	at hudson.model.Build$RunnerImpl.post2(Build.java:159)
	at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:553)
	at hudson.model.Run.run(Run.java:1391)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
	at hudson.model.ResourceController.execute(ResourceController.java:88)
	at hudson.model.Executor.run(Executor.java:145)


Where does hudson define the memory settings for the service?

The memory settings for service are generally located in hudson.xml file in the same directory as your hudson.war.

Here is what a default memory configuration looks like (the content is formatted to remove the comments)

<service>
  <id>hudson</id>
  <name>Hudson</name>
  <description>This service runs Hudson continuous integration system.</description>
  <env name="HUDSON_HOME" value="%BASE%"/>
  <executable>java</executable>
  <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%hudson.war" --httpPort=8080</arguments>
  <logmode>rotate</logmode>
</service>



How the change the memory setting?

Just by looking at the hudson.xml file above, you must have noted that the memory settings are located in the element.

Edit the arguments to change the memory. For example, if you want the hudson to run with 1GB memory,

replace -Xmx256m with -Xmx1048m

Make sure to restart the hudson windows service once you have made the changes.

Tagged , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *