5

I have below out put from one of VM.

So, as per link, the parallel streams use the default ForkJoinPool.commonPool which by default has one less threads as you have processors, as returned by Runtime.getRuntime().availableProcessors().

If I do Runtime.getRuntime().availableProcessors(), then it always returns 1, but looking at below output, number should have been more. What I am missing here?

lscpu command output is :-

2019-02-05T20:20:33.813+05:30 [APP/PROC/WEB/0] [OUT] Architecture: x86_64
2019-02-05T20:20:33.813+05:30 [APP/PROC/WEB/0] [OUT] CPU op-mode(s): 32-bit, 64-bit
2019-02-05T20:20:33.813+05:30 [APP/PROC/WEB/0] [OUT] Byte Order: Little Endian
2019-02-05T20:20:33.813+05:30 [APP/PROC/WEB/0] [OUT] CPU(s): 4
2019-02-05T20:20:33.813+05:30 [APP/PROC/WEB/0] [OUT] On-line CPU(s) list: 0-3
2019-02-05T20:20:33.814+05:30 [APP/PROC/WEB/0] [OUT] Thread(s) per core: 1
2019-02-05T20:20:33.814+05:30 [APP/PROC/WEB/0] [OUT] Core(s) per socket: 1
2019-02-05T20:20:33.819+05:30 [APP/PROC/WEB/0] [OUT] Socket(s): 4
2019-02-05T20:20:33.819+05:30 [APP/PROC/WEB/0] [OUT] NUMA node(s): 1
2019-02-05T20:20:33.819+05:30 [APP/PROC/WEB/0] [OUT] Vendor ID: GenuineIntel
2019-02-05T20:20:33.819+05:30 [APP/PROC/WEB/0] [OUT] CPU family: 6
2019-02-05T20:20:33.819+05:30 [APP/PROC/WEB/0] [OUT] Model: 58
2019-02-05T20:20:33.819+05:30 [APP/PROC/WEB/0] [OUT] Stepping: 0
2019-02-05T20:20:33.820+05:30 [APP/PROC/WEB/0] [OUT] CPU MHz: 2599.998
2019-02-05T20:20:33.820+05:30 [APP/PROC/WEB/0] [OUT] BogoMIPS: 5199.99
2019-02-05T20:20:33.820+05:30 [APP/PROC/WEB/0] [OUT] Hypervisor vendor: VMware
2019-02-05T20:20:33.820+05:30 [APP/PROC/WEB/0] [OUT] Virtualization type: full
2019-02-05T20:20:33.820+05:30 [APP/PROC/WEB/0] [OUT] L1d cache: 32K
2019-02-05T20:20:33.820+05:30 [APP/PROC/WEB/0] [OUT] L1i cache: 32K
2019-02-05T20:20:33.821+05:30 [APP/PROC/WEB/0] [OUT] L2 cache: 256K
2019-02-05T20:20:33.821+05:30 [APP/PROC/WEB/0] [OUT] L3 cache: 40960K
Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
Rahul Singh
  • 781
  • 11
  • 27
  • Not really sure what the question is. Is it that why you get `1` as output while the number of processors is `4`? And where are the streams involved currently in the question? – Naman Feb 05 '19 at 15:06
  • 2
    @nullpointer streams are useless indeed, but I really wonder if that is *really* what the OP seems when running `Runtime.getRuntime().availableProcessors()` or `lscpu`... – Eugene Feb 05 '19 at 15:08
  • 4
    Could it be that you are running `Runtime.getRuntime().availableProcessors()` in the VM but `lscpu` in the host system (not VM)? – Karol Dowbecki Feb 05 '19 at 15:17
  • 1
    @Eugene true, that's what made the question unclear to me actually. – Naman Feb 05 '19 at 15:17
  • @KarolDowbecki exactly my thought... is docker involved may be? – Eugene Feb 05 '19 at 15:17
  • sorry for unclear questions:- So, I have app deployed on pcf and in that app I am trying to find out number of cores from "Runtime.getRuntime().availableProcessors()". lscpu, I did programatically again in the same app. Like "Runtime.getRuntime().exec(command);" and command passed is lscpu – Rahul Singh Feb 05 '19 at 16:30
  • what is `pcf` btw? – Eugene Feb 05 '19 at 16:56
  • Pivotal cloud foundry – Rahul Singh Feb 05 '19 at 17:10

1 Answers1

7

You are most likely running the Java code inside a VM with limited number of vCPUs or in a container restricted by control groups (cgroups) while your lscpu command is run on the host machine.

Unless your JVM is affected by a bug (e.g. JDK-8188310 or JDK-6515172), these numbers should be the same.

Do note that Java 10 improved resource management as per Java Improvements for Docker Containers and introduced -XX:ActiveProcessorCount option. Javas 8 that you are currently using definitely doesn't handle all edge cases correctly.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111