Bitbucket Container 'Build' exceeded memory limit - When taking android build [solved] Bitbucket Container 'Build' exceeded memory limit - When taking android build [solved] docker docker

Bitbucket Container 'Build' exceeded memory limit - When taking android build [solved]


First we tried to increase docker memory size 7128mb.

But with configuration, we allocated 7128mb for the docker service. This leaves only 1024mb for the build container, which is not sufficient for the successful completion of the build.

We did reduce the docker service memory to 1024mb as shown below.

definitions:  services:    docker:      memory: 1024

But still we getting error.

We check which process is taking how much memory and what is causing the failure.

Here is the ps -aux output from build:

> .... root          78  2.3  1.1 4853812 381648 ?      Sl   07:47  > 0:09 /usr/lib/jvm/java-8-openjdk-amd64//bin/java> -Dorg.gradle.app....... root         314  182 12.2 10295652 3970496 ?    Ssl  07:47  13:00 /usr/lib/jvm/java-8-openjdk-amd64/bin/java> -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError -Xmx4096m -Dfile.encoding=UTF-8 -Duser........... root        2744  145 11.0 10389720 3591488 ?    Sl   07:48   8:52> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -cp> /root/.gradle........ ...

From the output above, java process has -XX:MaxPermSize=4096m which limits the process to go over the 4gb limit and the other java process is spun up without the limit (and has 4gb memory usage as well). These two processes use 4gb RAM each.

Therefore we try to lower org.gradle.jvmargs to 2gb.

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError

And added JAVA_OPTS environment variable.

script:  - JAVA_OPTS="-Xmx2048m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8"    

Finally we’ve got a successful build.