I am starting a Java
app as follows
JAVA_OPTS=-Xmx7g -Xms512m -Xss1m -XX:+UseCompressedOops -XX:-OmitStackTraceInFastThrow
The pod I am using for this, has
resources:
limits:
cpu: 4096m
memory: 9Gi
requests:
cpu: 1024m
memory: 512Mi
However, I see once and then, pods being killed with
"Memory cgroup out of memory: Kill process 3284727 (java) score 1982 or sacrifice child
Killed process 3284727 (java) total-vm:15318320kB, anon-rss:9380388kB, file-rss:20180kB, shmem-rss:0kB"
Why does this take place?
How come the memory usage surpasses 9G
given that I set Xmx=7G
With -Xmx
you only specify the Java heap size - there is a lot of other memory that the JVM uses (like stack, native memory for the JVM, direct buffers, etc.).
In our experience the correct size for total usage of the JVM is 1.5 to 2 times the heap size but this depends heavily on your use case (for example some applications using direct buffers may have 32GB of RAM using only 1GB of heap).
So run your app with more limits, check the actual usage and then define that + 5% as a container limit.
You should also adapt your request to at least 1Gi
with -Xms512m
.