-
I’m using Sonarqube 8.2 Docker image
-
I have been receiving java heap errors when users tryo to check in large projects like this:
java.lang.OutOfMemoryError: Java heap space
at java.base/java.lang.StringCoding.encodeUTF8_UTF16(Unknown Source)
at java.base/java.lang.StringCoding.encodeUTF8(Unknown Source)
at java.base/java.lang.StringCoding.encode(Unknown Source)
at java.base/java.lang.String.getBytes(Unknown Source)
at org.sonar.core.hash.SourceHashComputer.addLine(SourceHashComputer.java:37)
at org.sonar.ce.task.projectanalysis.source.FileSourceDataComputer.compute(FileSourceDataComputer.java:57)
at org.sonar.ce.task.projectanalysis.source.PersistFileSourcesStep$FileSourceVisitor.visitFile(PersistFileSourcesStep.java:99) -
I want to Increase the Compute engine Java heap memory from the default 512MB to 1GB using environment variables on the docker run command line.
-
I tried by adding the environment variable to the Docker Run Command like this:
--env SONAR_CE_JAVAADDITIONALOPTS="-Xmx=1G -Xms=1G"
and it did not do anything to the heap space.
How exactly should I specify the JVM memory using the environment variable? I also saw @ceDefaultHeapSize@ referenced in the documentation, but not sure what this is?
Hi,
Welcome to the community!
According to the docs it looks like you need a -e
flag instead of -env
…?
HTH,
Ann
Thanks for the reply Ann. Actually it seems the markdown munged my two dashes “–” into one. I did indeed use “–env” (which is equivalent to “-e”).
Hi @robfocht,
ceDefaultHeapSize
is 512MB. This is indeed a copy-paste issue in our doc, we will need to fix it. FYI, you can see all default values in /opt/sonarqube/conf/sonar.properties
. You can use the following command to see it:
docker exec [CONTAINER_ID] -it cat /opt/sonarqube/conf/sonar.properties
SONAR_CE_JAVAADDITIONALOPTS
is for specifying any Java options, except memory. This is what is meant by the phrase:
Same as previous property, but allows to not repeat all other settings like -Xmx
I agree this might not be the simplest way to phrase that particular bit of info . But basically, setting memory arguments in
SONAR_CE_JAVAADDITIONALOPTS
will result in a call that looks something like this:
-Djava.awt.headless=true -Dfile.encoding=UTF-8 (...) -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Xmx1G -Xms1G
Notice the duplicate -Xmx
and -Xms
options. This is why it doesn’t work. Only the defaults are taken into account, because they come first.
However, if you use SONAR_CE_JAVAOPTS
instead, it will work. Example:
docker run --rm --env SONAR_CE_JAVAOPTS="-Xmx1G -Xms1G" -p 9000:9000 sonarqube:8.2-community
You should see a line like this in your Docker logs:
INFO app[][o.s.a.ProcessLauncherImpl] Launch process[[key='ce', ipcIndex=3, logFilenamePrefix=ce]] from [/opt/sonarqube]: /usr/local/openjdk-11/bin/java (...defaults you cannot override) -Xmx1G -Xms1G
This is the way to set memory for the CE using Docker. Hope this helps.
Thanks for the help and the clarification. Adding the environment variable as you mentioned worked.