简体   繁体   English

Docker和DC / OS的JVM优化

[英]JVM Optimizations for Docker and DC/OS

I'm moving a bare metal java application (jar jdk8) to docker containers and DC/OS. 我正在将裸机java应用程序(jar jdk8)移动到docker容器和DC / OS。 I am noticing an odd pattern on the dockers, we set -XMX to 32 gig and allocate a 36 gig docker container. 我注意到码头工人的奇怪模式,我们将-XMX设置为32 gig并分配一个36 gig的docker容器。 Every few hours or so the application will spike in old gen mem allocation and the GC will get stuck in a loop ( maxing CPU) while it tries to do the heap dump. 每隔几个小时左右,应用程序将在旧的内存分配中出现峰值,并且当GC尝试执行堆转储时,GC将陷入循环(最大CPU)。

Are there any optimizations or things I can use to see why in that 1-5 second interval we are spiking so fast? 是否有任何优化或事物我可以用来了解为什么在1-5秒的时间间隔内我们的速度如此之快? Are there any gotchas I might need to be aware of with Docker and JVM? 使用Docker和JVM可能需要注意哪些问题?

We are using default GC 我们正在使用默认GC

Just for future reference: 仅供将来参考:

We are using JDK 8 and it seems as if Oracle has just recently added some experimental flags for using Docker. 我们正在使用JDK 8,似乎Oracle刚刚添加了一些使用Docker的实验标志。 I believe the case could have been when GC was allocating threads it wasn't respecting the docker thread count from cgroup. 我相信这个案例可能是在GC分配线程时它不尊重来自cgroup的docker线程数。 The experimental flags seemed to have fixed our "off the rails issue" 实验性标志似乎修复了我们的“脱轨问题”

https://blogs.oracle.com/java-platform-group/java-se-support-for-docker-cpu-and-memory-limits https://blogs.oracle.com/java-platform-group/java-se-support-for-docker-cpu-and-memory-limits

Usually you would like to avoid this gigantic applications with > 30GB of memory and split your application into smaller parts with less memory requirements if you have the possibility to use a container platform like DC/OS. 通常,您希望避免使用大于30GB内存的巨大应用程序,并且如果您可以使用DC / OS等容器平台,则可以将应用程序拆分为具有较少内存要求的较小部分。

In general about GC and heap size: If you have big heap sizes, full GC can take a long time. 一般来说,关于GC和堆大小:如果您有大堆大小,完整的GC可能需要很长时间。 Personally I experienced full GC freezes up to a minute or more with a quite similar heap size to your mentioned 30GB. 就个人而言,我经历了完整的GC冻结,最长可达一分钟或更长时间,其堆大小与您提到的30GB相当。

About Java in containers: The JVM actually needs more memory than you configure with -Xmx . 关于容器中的Java:JVM实际上需要的内存比使用-Xmx配置的内存多。 So, if you specify a memory limit of 2GB within your DC/OS (Marathon) application, you can not set -Xmx2G , because this memory restriction is a hard limitation. 因此,如果在DC / OS(Marathon)应用程序中指定了2GB的内存限制,则无法设置-Xmx2G ,因为此内存限制是一个严格的限制。 If your process inside the container will exceed these memory limit, the container will be killed. 如果容器内的进程超出这些内存限制,容器将被终止。 By the fact that the JVM will reserve temporary more memory than in -Xmx configured, this is really likely to happen. 由于JVM将保留比-Xmx配置的临时更多内存,因此很可能会发生这种情况。 In general I would suggest to use around 75% of your configured memory as value for -Xmx . 一般情况下,我建议使用大约75%的已配置内存作为-Xmx值。

You could have a look at newer JRE versions, which support -XX:+UseCGroupMemoryLimits . 您可以查看较新的JRE版本,它们支持-XX:+UseCGroupMemoryLimits This is a JRE flag to use cgroup container limitations for memory consumption, see https://developers.redhat.com/blog/2017/04/04/openjdk-and-containers/ for more informations. 这是使用cgroup容器限制进行内存消耗的JRE标志,有关更多信息,请参阅https://developers.redhat.com/blog/2017/04/04/openjdk-and-containers/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM