简体   繁体   English

当运行 JVM 的 docker 容器达到内存限制时会发生什么?

[英]What happens when docker container running JVM reaches memory limit?

Let us say, a docker container has JVM running inside it in a server with 16G RAM, 2 core CPU and following are the memory limits on container:比方说,一个 docker 容器在一个具有 16G RAM、2 核 CPU 的服务器中运行着 JVM,以下是容器的内存限制:

mem_limit: 14G
max_mem: 13G
threads: 1
max_pool_size: 20

max_mem is max heap size used by JVM and mem_limit is max memory used by container. max_mem是 JVM 使用的最大堆大小, mem_limit是容器使用的最大内存。 I am trying to understand following things:我试图理解以下事情:

  1. What happens when JVM reaches it max_mem limit?当 JVM 达到max_mem限制时会发生什么?
  2. What happens when container reaches it mem_limit ?当容器达到mem_limit时会发生什么?
  3. Does it restarts with or without OOM errror log messages?它是否会在有或没有 OOM 错误日志消息的情况下重新启动? Where can we see these logs?我们在哪里可以看到这些日志?
  4. How much memory should we leave for container after max_mem ?max_mem之后我们应该为容器留多少内存?
  5. How does threads effect the memory limit?线程如何影响内存限制?

1. What happens when JVM reaches it max_mem limit? 1. 当 JVM 达到 max_mem 限制时会发生什么?
It has to crash.它必须崩溃。 If you have a live-restore or on docker-swarm or on kubernetes it will bring up another container swiftly.如果您有实时恢复或在 docker-swarm 或 kubernetes 上,它会迅速启动另一个容器。

2. What happens when container reaches it mem_limit? 2. 当容器达到 mem_limit 时会发生什么?
It has to report and crash.它必须报告并崩溃。 Answer remains same as above.答案和上面一样。

3. Does it restarts with or without OOM errror log messages? 3.它是否重新启动有或没有OOM错误日志消息?
It gives OOM error.它给出了 OOM 错误。 Question 1, error log is inside the container, so you need to log in into the dead container and see the logs.问题1,错误日志在容器内,需要登录死容器查看日志。 Question 2, error log is from docker, docker logs must show it.问题2,错误日志来自docker,docker日志必须显示。 Docker logs will show your container log also. Docker 日志也​​会显示您的容器日志。

4. Where can we see these logs? 4. 在哪里可以看到这些日志?
Answered in above question在上面的问题中回答

5. How much memory should we leave for container after max_mem? 5. max_mem 之后我们应该为容器留多少内存?
Do a memory model design for your application and add a buffer and limit your container according to that.为您的应用程序进行内存模型设计,并添加一个缓冲区并根据此限制您的容器。 Make sure you fix your application code if your container keeps crashing because of OOM如果您的容器因 OOM 而不断崩溃,请确保修复您的应用程序代码

6. How does threads effect the memory limit? 6. 线程如何影响内存限制?
Thread is a runner, which uses the resources in your memory or disk.线程是一个运行器,它使用内存或磁盘中的资源。 The number of threads choke memory not because they are large in number, but because of the native data in memory they carry along when they are created.线程的数量阻塞内存并不是因为它们数量太多,而是因为它们在创建时携带的内存中的本机数据。


Hope i have answered your questions.希望我已经回答了你的问题。

Looking at the docs it seems there is a memswap_limit option so I recon it's safe to assume swap would be used.查看文档,似乎有一个 memswap_limit 选项,所以我认为可以安全地假设将使用交换。 It could crash cause jvm is good at that however, I imagine it'd just run slow.它可能会崩溃,因为 jvm 擅长于此,但我想它只会运行缓慢。

The thread itself would not slow down but it would essentially be bottlenecked by slow read/write speed due to swap.线程本身不会变慢,但它本质上会因交换而导致读/写速度变慢而成为瓶颈。

Your max mem question is quite a difficult one to answer without messing about with it a bit.你的 max mem 问题是一个很难回答的问题,而不会搞砸它。 You might find somewhere someone recommends 10-20% headroom but you should really try to find the sweet spot your self.你可能会发现有人推荐 10-20% 的空间,但你真的应该试着找到你自己的最佳点。

Note: 14gb ram is a lot for a single container.注意:14gb ram 对于单个容器来说已经很多了。 If possible, you should consider distributing work loads over multiple containers.如果可能,您应该考虑在多个容器上分配工作负载。 Docker run allows you to scale containers using --scale arg and orchestration platforms such as kubernetes can manage the process for you. Docker run 允许您使用 --scale arg 扩展容器,并且诸如 kubernetes 之类的编排平台可以为您管理该过程。

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

相关问题 如何检测Docker容器何时达到其配置的内存限制 - How to detect when a Docker container reaches its configured memory limit 在Docker容器中运行时,JVM无法映射保留的内存 - JVM cant map reserved memory when running in Docker container 限制Docker容器中的JVM内存消耗 - Limit JVM memory consumption in a Docker container 当旧的docker容器达到指定的内存限制时,是否可以运行相同图像的新docker容器 - Is it possible to run a new docker container of same image when the old one reaches a specified memory limit 达到一组内存使用量或CPU限制时如何杀死Docker容器 - How to kill a docker container when it reaches set of memory usage or CPU limit Docker:在启​​用内存限制和禁用内存过量使用的情况下运行容器会有哪些负面影响? - Docker: what are negative impacts of running container with memory limit enabled and memory overcommit disabled? 当docker容器崩溃时,数据会发生什么 - What happens to the data when a docker container crashes 当 HEALTHCHECK 失败时,Docker 容器会发生什么情况 - What happens to a Docker Container when HEALTHCHECK fails Docker:如何在运行 Z05B6053C41A2130AFD6FC3B158BDA4 时打印 jvm memory 信息 - Docker : how to print jvm memory informations when running docker logs 容器停止时由容器创建的Docker卷会发生什么 - What happens to docker volumes created by container when the container is stopped
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM