[英]Java process as non-root consumes 100% CPU, but as root is fine
I've been attempting to containerize a Java application with Docker. 我一直试图用Docker封装Java应用程序。 When I have the container run this process as a user other than root, CPU usage goes to 100% and stays there.
当我让容器以非root用户身份运行此进程时,CPU使用率将达到100%并保持不变。 However, with root, it is much more well behaved, sitting around 2%.
然而,对于root来说,它表现得更好,约占2%。
# docker run -d -p 8006:8006 -u root --name root app:latest
# docker run -d -p 8007:8006 -u nonroot --name nonroot app:latest
# ps aux | grep java
root 26537 9.2 4.1 174800 115636 ? Sl 10:14 0:02 /opt/app/jvm16/bin/java -Xmx128M -Xms128M […]
nonroot 26808 94.8 6.2 202744 175368 ? Sl 10:15 0:08 /opt/app/jvm16/bin/java -Xmx128M -Xms128M […]
The application functions identically with either root or a non-root user (it's not hung). 应用程序与root用户或非root用户完全相同(它没有挂起)。 But if I run this same application on a real (not inside a container) server, the CPU usage is fine for either root or non-root, hinting at a container-related cause.
但是,如果我在真实(不在容器内)服务器上运行相同的应用程序,则对于root或非root用户来说CPU使用率都很好,暗示了与容器相关的原因。
Nothing (that I could find) on the Docker host lends insight, and java dumps inside the container don't point me to anything. Docker主机上没有(我能找到的)提供了洞察力,容器内的java转储并没有指向任何东西。
My question is: what could be an explanation for this? 我的问题是:对此可以解释什么?
My question is: what could be an explanation for this?
我的问题是:对此可以解释什么?
One possible explanation is that the application is repeatedly retrying something that works when the JVM is run as root
and fails when tun as a normal user; 一种可能的解释是,应用程序反复重试一些在JVM以
root
身份运行时有效的东西,而在以普通用户身份运行时失败; ie it is a combination of a poorly designed application and a permission problem. 即它是设计不良的应用程序和权限问题的组合。
I would try the following to try to figure out what is happening: 我会尝试以下方法来弄清楚发生了什么:
jstack
to see what threads are active and what they are doing. jstack
查看哪些线程处于活动状态以及它们正在执行的操作。 If the CPU is 100% and is is the JVM using the CPU, then there should be active threads. strace
to see what syscalls the JVM is doing. strace
查看JVM正在执行的系统调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.