7

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.

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the answer! We're doing something similar, and it's working, but I'm really curious about the internals - is there any overhead from the container itself that would effect memory assignment
Leaving 90% of reserved memory to Java is very risky. My suggestion so far is to test your application and see how much memory the JVM is taking. Keep in mind this is the memory reported by the OS as it can be significantly higher than memory you assigned to the heap + perm space + threads stack. Just to give you some idea, we were assigning 75% of the memory of the container to the heap. Then we lowered it to 65% and finally to 50% because Docker was killing the container due to memory limits. With 50% we were good. It means that if in Docker we assigned 2G, JVM heap was 1G (this is JDK 8).
Keep in mind ratios will be different according to the app you are running. For example we have an application that needs just little heap, around 64m, however if we create a Docker container with 128m, it will be killed at some point due to memory limits. In this case we had to assign 256m to the container even when the app was using 64m of heap. As I pointed out in my previous comment, probably what you need to do is test your apps.
Here is a great article about this: plumbr.eu/blog/memory-leaks/…
0

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.

1 Comment

We're using mesos / marathon, so I believe it is limiting the memory via cgroups (though I could be mistaken). At the very least, we have memory expectations for the docker containers, as numerous containers will get deployed side by side. All add some clarification, but I'm not sure this really answers my question - if it is limited, should we max out java memory to the cgroup limit?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.