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


i'm running java app inside of docker container, restricted 4 cpu , machine on docker container runs, has 10 cpu.

when calling nproc inside docker container, result 4, when call runtime.getruntime().availableprocessors() 10 result.

  • why happening? how come java see cpu?
  • is there way of getting in java same result asa nproc, besides using runtime.getruntime().exec("nproc")?

according ken sipe (link below) there bug in java showing wrong no of cpus/cores when using shared cpus (default in docker) instead of cpusets (pinned cpus process).

i myself see wrong number regardless setting:

runtime.availableprocessors(), no docker: 8 in docker 4,

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

see https://vimeo.com/138955223


Comments