Large/Incorrect Memory Allocation on Confluence Process
Asked by Chris Lange:

I've setup my Confluence memory allocations as follows:

```
-Xms256m-Xmx768m
```

verified by

    ps -aux | grep java

```
?/opt/atlassian/confluence/jre//bin/java -Djava.util.logging.config.file=/opt/atlassian/confluence/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dsynchrony.port=9004 -Dconfluence.context.path= -Datlassian.plugins.startup.options= -Dorg.apache.tomcat.websocket.DEFAULT_BUFFER_SIZE=32768 -Dsynchrony.enable.xhr.fallback=true -Xms256m -Xmx768m -XX:+UseG1GC -Datlassian.plugins.enable.wait=300 -Djava.awt.headless=true -XX:G1ReservePercent=20 -Xloggc:/opt/atlassian/confluence/logs/gc-2018-01-05_12-35-28.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M -XX:-PrintGCDetails -XX:+PrintGCDateStamps -XX:-PrintTenuringDistribution -Djava.endorsed.dirs=/opt/atlassian/confluence/endorsed -classpath /opt/atlassian/confluence/bin/bootstrap.jar:/opt/atlassian/confluence/bin/tomcat-juli.jar -Dcatalina.base=/opt/atlassian/confluence -Dcatalina.home=/opt/atlassian/confluence -Djava.io.tmpdir=/opt/atlassian/confluence/temp org.apache.catalina.startup.Bootstrap start
```

However, when running, I see two processes which appear to be hogging quite a bit of RAM:

```
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
32016 8166 14.7 44.3 22797120 1395344 pts/0 Sl 12:35 7:04 /opt/atlassian/confluence/jre//bin/java -Djava.util.logging.config.file=/opt/atlassian/confluenc
32016 8522 2.1 22.1 16810088 696832 pts/0 Sl 12:36 1:00 /opt/atlassian/confluence/jre/bin/java -classpath /opt/atlassian/confluence/temp/2.1.0-release-c
```

What am I doing wrong?


Answers:
author: Nic Brough -Adaptavist-
body: One of them is Confluence, the other is Synchrony, the service needed to support the collaborative editing function.

You've not done anything wrong, but you will need to think about the memory Synchrony needs on top of Confluence (unless you turn it off and use the old editor)

comments: author: Chris Lange
body: Thanks for the reply!

So, I tried to pare down the memory usage of Synchrony by adding

    CATALINA_OPTS="-Dsynchrony.memory.max=512m ${CATALINA_OPTS}"

to setenv.sh.

Now I see a slight change to my memory usage:

```
32016 16786 169 49.6 22861176 1560800 pts/1 Sl 14:51 6:32 /opt/atlassian/confluence/jre//bin/java -Djava.util.logging.config.file=/opt/atlassian/confluenc
32016 17148 24.4 15.3 10234912 481608 pts/1 Sl 14:53 0:39 /opt/atlassian/confluence/jre/bin/java -classpath /opt/atlassian/confluence/temp/2.1.0-release-c
```

However, the Confluence process is still taking 1.5GB...

I would have expected the Confluence process to be limited to 768 MB and the Synchrony process limited to 512MB. Perhaps I'm misunderstanding?


author: Nic Brough -Adaptavist-
body: Memory handling in OS's is "fun" (meaning it's not, and after decades in the industry, I still hate the so-called experts who have failed miserably to make it either not matter or at least understandable to the end user)

Could you have a quick look at what the allocations for the processes are?

ps -ef \| grep confluence

should return three lines, but whatever the result, just paste the whole lot here


author: Chris Lange
body: Haha exactly! Not only that, these days, memory is assumed to be infinite and every problem can be solved by even more RAM... However, those of us with limited resources ($$) and only a few users should have other options...

Here is the output of ps -ef \| grep confluence:

```
32016 16786 1 2 Jan05 ? 00:21:53 /opt/atlassian/confluence/jre//bin/java -Djava.util.logging.config.file=/opt/atlassian/confluence/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dsynchrony.memory.max=512m -Dsynchrony.port=9004 -Dconfluence.context.path= -Datlassian.plugins.startup.options= -Dorg.apache.tomcat.websocket.DEFAULT_BUFFER_SIZE=32768 -Dsynchrony.enable.xhr.fallback=true -Xms256m -Xmx768m -XX:+UseG1GC -Datlassian.plugins.enable.wait=300 -Djava.awt.headless=true -XX:G1ReservePercent=20 -Xloggc:/opt/atlassian/confluence/logs/gc-2018-01-05_14-52-00.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M -XX:-PrintGCDetails -XX:+PrintGCDateStamps -XX:-PrintTenuringDistribution -Djava.endorsed.dirs=/opt/atlassian/confluence/endorsed -classpath /opt/atlassian/confluence/bin/bootstrap.jar:/opt/atlassian/confluence/bin/tomcat-juli.jar -Dcatalina.base=/opt/atlassian/confluence -Dcatalina.home=/opt/atlassian/confluence -Djava.io.tmpdir=/opt/atlassian/confluence/temp org.apache.catalina.startup.Bootstrap start
32016 17148 16786 0 Jan05 ? 00:07:10 /opt/atlassian/confluence/jre/bin/java -classpath /opt/atlassian/confluence/temp/2.1.0-release-confluence_6.5-1a01ab2d.jar:/opt/atlassian/confluence/confluence/WEB-INF/lib/mysql-connector-java-5.1.45-bin.jar -Xss2048k -Xmx512m synchrony.core sql
```

Additionally, I see the options inside start-synchrony.sh:

```
# Optionally configure JVM
JAVA_BIN="java"
JAVA_OPTS="-Xss2048k -Xmx2g"
```

Are those settings overwritten by my addition to setenv.sh below?

    CATALINA_OPTS="-Dsynchrony.memory.max=512m ${CATALINA_OPTS}"


author: Nic Brough -Adaptavist-
body: I'm not sure what is overriding what, but the two lines you've got tell us what you are ending up running, the most important bits being:

Confluence: -Xmx768m

Synchrony: -Xmx512m

These define the maximum heap size for the processes, and are perfectly healthy values for a small Confluence in my experience, as long as there's some room left for the OS to run as well as other processes. Confluence, with Synchrony, should consume at most 1.25Gb RAM, leaving .75Gb for the OS on a 2Gb server. That's consistent with the % memory use values you saw earlier.


Tags: memory