Using Java VisualVM CPU and processor proximity

In my experience today, I find that Oracle Java VisualVM shows processor utilization as a percentage of the total number of machine cores, even if the monitored JVM has a limited affinity for the process installed in the OS. This is on the "Monitor" tab.

Limitation of controlled jvm using taskset (on linux, Ubuntu), when the processors allowed for this jvm are almost 100% loaded into htop , the percentage of processor shown in VisualVM is clearly equal to the total number of processors divided by the number of processors allowed for controlled jvm. Therefore, the resolution of the scale is not suitable for this case.

Can you confirm that you have observed the same on other operating systems or in general?

Is there a way to have a VisualVM account only for affinity cores when showing processor usage?

+8
java jvisualvm
source share
1 answer

According to the VisualVM source code , processor load is actually calculated as the total processor time divided by the number of processors:

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

where processorCount is obtained from OperatingSystemMXBean:

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

There was a long-standing JVM error JDK-6515172 that the affinity for the process was not taken into account, that is, getAvailableProcessors always returned the total number of CPUs, regardless of task sets. This has been linked to Linux and BSD; worked fine on Solaris and Windows.

About a month ago, this error was finally resolved. The fix, however, is for JDK 9 only.

See this question for possible workarounds. They are somewhat ugly though.

+5
source share

All Articles