问题描述
我在这个容器中运行了一个带有的Java REST应用程序,但我注意到每个请求都是在请求完成后添加内存使用量而不是减少。我的第一个猜测是我忘记关闭一些流/缓冲区(这个应用程序处理了大量文件操作),但我查看了所有代码,看起来所有内容都已关闭。
I'm running a Java REST app with Apache JavaSpark in this container, but I noticed that each request is adding the memory usage and not decreasing after the request is done. My first guess was that I had forgotten to close some stream/buffer (this app deal with a lot of file manipulation), but I reviewed all the code and looks like everything is being closed.
这是我的Dockerfile:
Here is my Dockerfile:
FROM maven:3.5-jdk-8-alpine
WORKDIR /code
ADD pom.xml /code/pom.xml
RUN ["mvn", "dependency:resolve"]
ADD src /code/src
RUN ["mvn", "package"]
EXPOSE 1337
CMD exec java -jar "target/app.jar"
这是码头工具统计数据:
Here is the docker stats:
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
2db8b2f5fd72 0.16% 66.36 MiB / 1.952 GiB 3.32% 12.9 kB / 106 kB 0 B / 0 B 23
推荐答案
Java通常会分配内存以前保留的,它只在重新启动进程时释放它。你可以看到这篇文章给出了完整的解释。
Java usually allocates memory that has previously reserved, it only frees it when you restart the process. You can see this post that gives the full explanation.
这篇关于为什么docker容器内存使用量不会减少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!