I'm running openjdk11
on alpine linux in a container in an AWS EKS cluster.
The application determines the size of a threadpool based on the number of CPUs as returned by Runtime.getRuntime().availableProcessors()
This call is returning 2 processors even though the container shows that 4 CPUs are available:
# cat /proc/cpuinfo | grep processor
processor : 0
processor : 1
processor : 2
processor : 3
Any idea why and how to solve the problem?
Update
Doing some more digging (prompted by some great questions from @gohm'c in the comments), I found a way to add some trace log prints to the JVM with -Xlog:os+container=trace
[0.001s][trace][os,container] CPU Shares is: 1536
[0.001s][trace][os,container] CPU Share count based on shares: 2
Now, I defined in resources.requests.cpu: "1500m"
.
I don't know why the slight discrepancy but I changed the value of the CPU request, and indeed the CPU Shares
in the log trace changes accordingly.
I understand how the resources.limits.cpu
value could affect the CPUs that the JVM sees. But why is the resources.requests.cpu
value doing that! This seems like a bug to me? Any thoughts?