Patrick White
Patrick White

Reputation: 882

JVM Memory Allocation In Docker (LXC) Container

We've dockerized a JVM (Scala) application, Java 1.7, and are trying to decide how to allocate memory. We have a single application running in the docker container. If the docker container is allocated 4GB of RAM, should we allocate 4GB (or maybe a little less just to be safe) to the JVM?

As I understand it, there aren't other processes running inside the docker container besides what's called from the entry point, so we shouldn't need to worry about non-JVM memory usage - is that true, or an over simplification? Are there any other questions we should be asking?

EDIT We're using Mesos / Marathon to deploy the docker images - I believe it does set cgroup limits on memory (at least, it gives the impression that it does) but I could definitely be wrong.

Upvotes: 7

Views: 3328

Answers (3)

Rafaeska
Rafaeska

Reputation: 1

You cannot give -Xmx same value as container memory, because Java is going to need some more space for permanent generation (permgen), code cache, etcetera. There is one tool for other container environment, Warden. Tool is here: I think it can be used inside Docker as well. Need to test.

Upvotes: 0

Clayton SIlva
Clayton SIlva

Reputation: 45

I have same scenario, and i use 90% of reserved memory to jvm, and work very well

Upvotes: 1

Bryan
Bryan

Reputation: 12190

For the purposes of your question, treat your container as you would a process running on the host machine.

It is a process running on the host machine, albeit with its own namespaces for network, process, etc.

You don't even "allocate" memory to a container; you can limit if if you like via cgroups, but since the JVM has its own limit this is unnecessary.

Lastly, in this situation you're controlling virtual memory usage, not RAM.

Upvotes: 0

Related Questions