简体   繁体   English

Java VisualVM CPU使用率和处理器关联性

[英]Java VisualVM CPU usage and processor affinity

In my experience today, I find that Oracle's Java VisualVM shows cpu usage as a percent of total machine cores, even when the JVM being monitored has a limited process affinity set in the OS. 根据我今天的经验,即使受监视的JVM在OS中设置的进程亲和力有限,Oracle的Java VisualVM仍将CPU使用率显示为占整个计算机内核的百分比。 This is in the "monitor" tab. 这是在“监视”选项卡中。

Limiting the monitored jvm with taskset (on linux, Ubuntu), when the processors allowed to that jvm are near 100% utilization in htop , the cpu percentage shown in VisualVM is clearly equal to the total number of cpus divided by the number of processors allowed to the monitored jvm. taskset (在Linux,Ubuntu上)限制受监视的jvm,当允许该jvm的处理器在htop利用率接近100%时,VisualVM中显示的cpu百分比显然等于cpus的总数除以允许的处理器数到受监控的JVM。 The resolution of the scale is therefore inadequate for this case. 因此,秤的分辨率对于这种情况是不足的。

Can you confirm you observed the same on other operating systems or in general? 您能否确认您在其他操作系统上或总体上也观察到了同样的情况?

Is there a way to have VisualVM account for only affinity-assigned cores when showing cpu usage? 显示cpu使用情况时,是否有一种方法仅将VisualVM帐户用于关联性分配的核心?

According to VisualVM source code , CPU usage is indeed calculated as total CPU time divided by number of processors: 根据VisualVM源代码 ,CPU使用率的确计算为总CPU时间除以处理器数量:

    long processCpuTime = tracksProcessCpuTime ?
        model.getProcessCpuTime() / processorsCount : -1;

where processorsCount is obtained from OperatingSystemMXBean : OperatingSystemMXBean获得processorsCount的位置:

    OperatingSystemMXBean osbean = mxbeans.getOperatingSystemMXBean();
    if (osbean != null) processorsCount = osbean.getAvailableProcessors();

There was a long-standing JVM bug JDK-6515172 , that the process affinity was not taken into account, ie getAvailableProcessors always returned the total number of CPUs regardless of tasksets. 有一个长期存在的JVM错误JDK-6515172 ,未考虑进程亲和性,即,无论任务集如何, getAvailableProcessors总是返回CPU的总数。 This was specific to Linux and BSD; 这是特定于Linux和BSD的; worked normally on Solaris and Windows. 在Solaris和Windows上正常工作。

About a month ago this bug has been finally resolved. 大约一个月前,此错误终于得到解决。 The fix, however, is only for JDK 9. 但是,此修复程序仅适用于JDK 9。

Look at this question for possible workarounds. 查看此问题以获取可能的解决方法。 They are somewhat ugly though. 他们虽然有些丑陋。

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

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