Paul
Paul

Reputation: 1355

java Runtime.getRuntime().availableProcessors() and nproc return different values

I'm running a Java app inside of a docker container, which is restricted to 4 CPU and the machine on which the docker container runs, has 10 CPU.

When calling nproc inside the docker container, I get as a result 4, but when I call Runtime.getRuntime().availableProcessors() I get 10 as result.

Upvotes: 3

Views: 2993

Answers (1)

Sander Hautvast
Sander Hautvast

Reputation: 31

According to Ken Sipe (link below) there is a bug in java for showing the wrong no of cpus/cores when using shared cpus (default in docker) instead of cpusets (pinned cpus for a process).

I myself however see the wrong number regardless this setting:

Runtime.availableProcessors(), no docker: 8 in docker I always get 4,

whereas nproc says 1 (when using --cpuset-cpus=0 <- pinned on cpu0)

see https://vimeo.com/138955223

Upvotes: 1

Related Questions