0

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?

e.dan
  • 7,275
  • 1
  • 26
  • 29
  • Can you post the JVM flags in used? – gohm'c Dec 29 '21 at 02:57
  • @gohm'c - no java flags. just `java -classpath my.jar com.myorg.MainClass` – e.dan Dec 29 '21 at 05:05
  • Did you set in your spec resources.limits.cpu to 2? – gohm'c Dec 29 '21 at 05:41
  • @gohm'c no, it has `resources.requests` but not `limits`. And anyway my understanding is that `limits` does not limit the number of CPUs actually exposed in the container. In any case, `/proc/cpuinfo` shows 4, the mystery is why the JVM only sees 2. – e.dan Dec 29 '21 at 07:12
  • Try add `-XX:+PrintFlagsFinal` to see your jvm flags? – gohm'c Dec 29 '21 at 07:20
  • Also, you built your own image for `openjdk11 on alpine linux`, or can you tell which base image are you using? – gohm'c Dec 29 '21 at 07:22
  • I will try the flags. The thing is, when I run this same configuration on a local k8s cluster (`docker-desktop`), the JVM does see 4 CPUs. It seems to me like the way the 4 CPUs are exposed when running in EKS somehow fools the JVM into thinking there are 2. I built my own image. It's based on `FROM node:16-alpine` and java is installed with `RUN apk --no-cache add openjdk11-jre` – e.dan Dec 29 '21 at 07:25

0 Answers0