-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Container memory limits, Java -Xms, any recommendation? #57
Comments
Is it possible that Java's |
Hi, thanks for the hint but no, it's a single process application. I finally set my memory limits to Xmx + 120mb and it seems safe, it may be too much but it's really difficult to tell. It may also be relevant to note that I am setting swap limits to "0". Perhaps that's not the best idea for a stable container but on the other hand I would not want my apps to silently rely on memory swapping to stay operational. I am going to give another try with the most recent version of docker and only Xmx values specified, without container-level memory limits, and check what docker stats say. |
@stefcl we seem to have similar issues with Java running in docker on AWS. Pretty much describes our problem to a T. I tried exactly what you have here, Xmx + around 120mb. However long running tasks still have an issue and the Java process RES memory grows and ends up hitting the limit. We still haven't found a great solution other than increasing that 120mb buffer but the container still ends up crashing on long running tasks. |
The jvm will always consume memory off heap, and depending on your application the off heap memory can be more. For instance ElasticSearch will use at least twice as much. |
@carlossg ah, thanks for clarifying 👍 Sounds like we can't really create a generic solution to this 😞 |
I have added a script in #71 that will allow setting Xmx easily when running inside a container. With |
I am looking for answers as well... But I think there is no magic number, I dont know exactly if java 8 has the same behavior but before it you should consider:
|
See also moby/moby#15020 which may be relevant..? |
No one mentioned this blog post, so I thought I'd share as I found it very helpful/informative |
Hi, there might be a related a memory leak in openjdk 8 "HotSpot leaking memory in long-running requests":
|
Thanks megastef 👍, this bug report could well be related to our issue here. However, the issue is marked as fixed in a future release due in... Q4 :-(. I tested adding the -Xint flag, but it did not seem to make any difference (I am running java 8 latest). I found another related issue here : Along with some documentation found elsewhere on the web, it seems to indicate that there is a general problem with java in cgroups, partly because the JVM may make wrong assumptions regarding the ressources available to it. Somebody suggested setting In earlier posts, I mentioned the formula |
JDK 8u131 has a experimental new VM option that maybe solves this: Experimental support for cgroup memory limits in container (ie Docker) environments |
From one of the linked JDK issues from @ant8e's link:
There's no 8u131 docker releases yet, but trying with 9-b161:
|
Related docs PR: docker-library/docs#900 |
Closing given the great upstream features / recommendations that are now documented from docker-library/docs#900. 👍 |
Hello,
Until recently, I used to run my dockerized java apps without specifying
--memory
and--memory-swap
parameters. I thought passing Xms and Xmx to the containerized java app and settings them to the same value (eg: 1024m) would be enough to keep memory usage predictable and under good control.However, doing so, after a few days of intense activity (our apps are tomcat-based web services),
docker stats
would report many times the Xmx amount under the MEM USAGE column.I started specifying limits the following way :
70m may seem a bit restrictive but it seems that the actual container memory limit (which you can see in
docker stats
) is always 40-50M larger than the number you specify. But I encountered stability issues, the app would eventually crash without notice. Not sure what would be a safe margin...Any advice for setting these limits?
The text was updated successfully, but these errors were encountered: