Java VisualVM CPU usage and processor affinity

痴心易碎 提交于 2019-12-04 04:13:29
apangin

According to VisualVM source code, CPU usage is indeed calculated as total CPU time divided by number of processors:

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

where processorsCount is obtained from OperatingSystemMXBean:

    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, i.e. getAvailableProcessors always returned the total number of CPUs regardless of tasksets. This was specific to Linux and BSD; worked normally on Solaris and Windows.

About a month ago this bug has been finally resolved. The fix, however, is only for JDK 9.

Look at this question for possible workarounds. They are somewhat ugly though.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!