3

On our Windows Server 2019, we have 36 cores and 72 logical processors, as seen in Task Manager CPU performance window. And, also, if from command prompt, if I run the command.

echo %NUMBER_OF_PROCESSORS%

It tells me 72.

However, from within Java program, if I run the following code snippet,

public class NoOfCPUs {  
    public static void main(String[] args) {
        String envName = "NUMBER_OF_PROCESSORS";
        String noOfP = System.getenv(envName);
        System.out.format("%s (from env) = %s%n", envName, noOfP);
    }
}

the output comes as:

NUMBER_OF_PROCESSORS (from env) = 36

Compiled with 64-bit Java 8 compiler on Windows in Netbeans IDE. Made an executable jar. Ran the jar, as:

java -jar NoOfCPUs.jar

Same system environment variable, NUMBER_OF_PROCESSORS is showing me different result from a command prompt vs from within Java program.

Why?

Is it because of logical processor group that Windows use after 2009 version? Logical processor group holds maximum of 64 processors in a group.

Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
  • @StephenC, This is giving me a different result. That;s why asking. – Dr. Debasish Jana May 08 '20 at 13:54
  • Do you launch your application directly using `java`, or are you launching it through a script? – Mark Rotteveel May 08 '20 at 14:00
  • Maybe 32-bit vs 64-bit? – beat May 08 '20 at 14:04
  • @beat, that's the question I have. Edited my qs to explain what I did. I am also looking for an explanation and answer myself. Thats why needed help of you, the experts. – Dr. Debasish Jana May 08 '20 at 14:07
  • 2
    Answer: according to the source code, it is impossible. Please read [How do I create a minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). I don't think we can investigate something that is impossible unless you can provide us a way to reproduce what you are seeing. (Then someone with a Windows machine needs to run your example.) – Stephen C May 08 '20 at 14:09
  • We now have a minrep. If someone else is able to reproduce what Dr. is seeing, please comment. (I am unable to run it as I don't have a Windows machine.) – Stephen C May 08 '20 at 15:12

1 Answers1

2

This seems related to other questions like these:

and this bug report says it will not be supported (won't fix):

https://bugs.openjdk.java.net/browse/JDK-6942632

The bug report says that is should be the responsibility of the user to configure the right amount of CPU's to Java, this is possible with:

  1. https://bitsum.com/portfolio/groupextend/
  2. Possibly other ones because of affinity inheritance like start /affinity, see this answer but I cannot test/confirm because my laptop does not have that many cores

I think you should consider running multiple instances of your application (and Java) instead of just one to gain maximum performance anyway because of NUMA locality, although different Java Virtual Machines have support for NUMA it still might have scalability issues depending on the configured Garbage Collection algorithm (non-concurrent, thus Stop-the-World) see: Amdahls Law

If the limit is specific to the HotSpotVM (originates from Sun/Oracle) you may want to take a look at a different Java Virtual Machine OpenJ9 (originates from IBM) and others like Azul Zing JVM

If it is a Windows specific limit, you may want to consider switching to a different Operating System or running multiple instances of Windows through a hypervisor of your choice.

JohannesB
  • 2,214
  • 1
  • 11
  • 18