Docker统计100%内存 [英] Docker stats 100% memory
问题描述
-XX:+ UseG1GC - Xms512m -Xmx2048m -XX:MaxPermSize = 256m
我使用docker内存限制选项:
docker run -it -m 2304m foo bash
在容器初始化后,运行 docker stats myApp
CONTAINER CPU%MEM使用/限制MEM%NET I / O
myApp 0.17%660.5 MB / 2.416 GB 27.34%240.8 kB / 133.4 kB
但是经过几个小时,我有以下统计资料:
CONTAINER CPU%MEM使用/限制MEM%NET I / O
/ pre>
myApp 202.18%2.416 GB / 2.416 GB 100.00%27.67 GB / 19.49 GB
虽然,如果我查看容器内正在运行的应用程序的进程执行细节,我使用了
〜735M B
和myApp继续计算请求没有任何问题:我@ docker-container〜] $ ps aux
用户PID%CPU%MEM VSZ RSS TTY STAT START TIME COMMAND
me + 1 0.0 0.0 11636 1324? Ss 13:44 0:00 / bin / bash /home/bar/service/start-myApp.sh
me + 6 113 4.5 5014152 735736? Sl 13:44 438:46 java -XX:+ UseG1GC -Xms512m -Xmx2048m -XX:MaxPermSize = 256m -jar myApp-service-1.0-final.jar
me + 481 0.0 0.0 11768 1820? Ss 20:09 0:00 bash
me + 497 0.0 0.0 35888 1464? R + 20:10 0:00 ps aux
值得一提的是我已经使用jconsole来监视进程
为什么docker容器使用所有内存可用,如果其内容不需要?
我预计docker会比myApp使用更多的内存,而不是100%的可用内存。解决方案从此开始:
-XX:+ UseG1GC -Xms512m -Xmx2048m -XX:MaxPermSize = 256m
,使用一个以0.5Gb开始并可以增长到2GB的堆,以及0.25GB的permgen堆。这不包括JVM的其他非堆用法;例如内存映射文件,线程堆栈,缓存JAR文件等。
然后你说docker报告容器正在使用2.416 GB。这并不奇怪2.42 - 2.25是0.17GB,对于非堆内存使用情况来说,这不是太多。
最后,735736 RSS值告诉你驻留集的大小;即该进程正在使用的当前物理RAM量。 JVM参数和docker
stats
命令是虚拟内存大小的度量。
为什么docker容器使用所有内存可用,如果其内容不需要它?我预计docker会比myApp使用更多的内存,而不是100%的可用内存。
我认为你误读了
ps aux
输出。 RSS只是正在使用的物理内存。事实上,您的进程的总内存使用情况由VSZ ...提供5GB。现在,看起来很大,为什么它是那么大,这不是很明显。但是把它看成是面值,这意味着Docker是容器的真实内存/虚拟内存使用。
另一件事是Docker容器不会将容器中的应用程序与容器外部的其他东西的资源需求隔离开来。 JVM将与容器内外的其他应用程序竞争物理RAM。
有关详细信息:
-
https ://goldmann.pl/blog/2014/09/11/resource-management-in-docker/ 解释了Docker资源管理如何工作,以及它可以做什么和不能做什么。
I've a container which is running a java application with the following jvm arguments:
-XX:+UseG1GC -Xms512m -Xmx2048m -XX:MaxPermSize=256m
I'm using docker memory limit option:
docker run -it -m 2304m foo bash
Running docker stats myApp
right after the container initialization will give me:
CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O
myApp 0.17% 660.5 MB/2.416 GB 27.34% 240.8 kB/133.4 kB
But after a few hours I've the following stats:
CONTAINER CPU % MEM USAGE/LIMIT MEM % NET I/O
myApp 202.18% 2.416 GB/2.416 GB 100.00% 27.67 GB/19.49 GB
Although, If I look into the process execution details of the running application inside the container, I have an usage of ~735MB
and myApp continues to compute requests without any problems:
me@docker-container ~]$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
me+ 1 0.0 0.0 11636 1324 ? Ss 13:44 0:00 /bin/bash /home/bar/service/start-myApp.sh
me+ 6 113 4.5 5014152 735736 ? Sl 13:44 438:46 java -XX:+UseG1GC -Xms512m -Xmx2048m -XX:MaxPermSize=256m -jar myApp-service-1.0-final.jar
me+ 481 0.0 0.0 11768 1820 ? Ss 20:09 0:00 bash
me+ 497 0.0 0.0 35888 1464 ? R+ 20:10 0:00 ps aux
Worthy to mention that I've used jconsole to monitor process 6
and everything looks good.
Why is docker container using all the memory available if its content does not need it? I expected that docker would use a little more memory than myApp... not 100% of the available memory.
Lets start with this:
-XX:+UseG1GC -Xms512m -Xmx2048m -XX:MaxPermSize=256m
That says, use a heap that starts at 0.5Gb and can grow to 2GB, and also a permgen heap of 0.25GB. And that does not include the JVM's other non-heap usage; e.g. memory mapped files, thread stacks, cached JAR files, etc.
Then you say that docker is reporting that the container is using 2.416 GB. That is not surprising. 2.42 - 2.25 is 0.17GB, and that is not excessive for non-heap memory usage.
Finally, the 735736 RSS value is telling you the resident set size; i.e. the current amount of physical RAM that that process is using. The JVM arguments and the docker stats
command are measures of virtual memory size.
Why is docker container using all the memory available if its content does not need it? I expected that docker would use a little more memory than myApp... not 100% of the available memory.
I think that you are misreading the ps aux
output. The RSS is just the physical memory being used. In fact, the total memory usage of your process is given by the VSZ ... which is 5GB. Now that >does< look large, and it is not obvious why its is that large. But taking it on face value, that implies that Docker is under-reporting the containers true memory / virtual memory usage.
The other thing is that a Docker container does not isolate an application in the container from resource demands by other things outside of the container. The JVM will be competing for physical RAM with other applications inside and outside of the container.
For more information:
https://goldmann.pl/blog/2014/09/11/resource-management-in-docker/ explains how Docker resource management works, and what it can and cannot do.
这篇关于Docker统计100%内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!