Skip to content

Commit 9623fa5

Browse files
authored
Merge pull request circleci#3949 from danielcompton/patch-1
Add information on UseContainerSupport in CircleCI
2 parents cb0f900 + 3e970ee commit 9623fa5

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

jekyll/_cci2/java-oom.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,40 @@ How to avoid and debug Java memory errors on CircleCI.
99
## Overview
1010

1111
The [Java Virtual Machine](https://en.wikipedia.org/wiki/Java_virtual_machine) (JVM) provides a portable execution environment for Java-based applications.
12-
Without any memory limits,
13-
the JVM pre-allocates a significant amount of memory.
12+
Without any memory limits, the JVM pre-allocates a fraction of
13+
the total memory available in the system.
14+
CircleCI runs container based builds on large machines with lots of memory.
15+
Each container has a smaller memory limit than the total amount available
16+
on the machine. This can lead to the JVM seeing a large amount of memory
17+
being available to it, and trying to use more than is allocated to the
18+
container.
19+
1420
This pre-allocation can produce Out of Memory (OOM) errors,
15-
which are difficult
16-
to debug because the error messages lack detail.
21+
which are difficult to debug because the error messages lack detail.
22+
23+
You can see how much memory your container is allowed to use by reading the file
24+
`/sys/fs/cgroup/memory/memory.max_usage_in_bytes`.
25+
26+
## UseContainerSupport
27+
28+
Recent versions of Java (JDK 8u191, and JDK 10 and up) include
29+
a flag `UseContainerSupport` which defaults on. This flag enables
30+
the JVM to use the CGroup memory constraints available to the container,
31+
rather than the much larger amount of memory on the machine.
32+
Under Docker and other container runtimes, this will let the JVM more accurately
33+
detect memory constraints, and set a default memory usage within those constraints.
34+
You can use the `MaxRAMPercentage` flag to customise the fraction of available RAM that is used,
35+
e.g. `-XX:MaxRAMPercentage=90.0`.
36+
37+
In CircleCI, containers are run using [Nomad](https://www.nomadproject.io).
38+
Nomad does set CGroup memory limits, but doesn't provide enough
39+
CGroup memory information to the container for the JVM to detect the container memory constraints.
40+
This means the JVM will set it's memory as a fraction of the total amount of RAM on the system.
41+
Nomad currently has an [enhancement request](https://github.com/hashicorp/nomad/issues/5376)
42+
open to provide this information. Once that is added, container builds in CircleCI will
43+
automatically pick up their container memory limits.
44+
45+
## Manual memory limits
1746

1847
To prevent the JVM from pre-allocating too much memory,
1948
declare memory limits
@@ -121,8 +150,6 @@ Ensure that your `-Xmxn` maximum size is large enough for your applications to
121150
completely build, while small enough that other processes can share the
122151
remaining memory of your CircleCI build container.
123152

124-
Please also note that +UseContainerSupport is currently not supported.
125-
126153
If you are still consistently hitting memory limits,
127154
consider [increasing your project's RAM](https://circleci.com/docs/2.0/configuration-reference/#resource_class).
128155

0 commit comments

Comments
 (0)