openJDK 17.0.4 and 17.0.6 behave differently for docker --cpu-shares

Nils Breunese nils at breun.nl
Tue May 7 11:01:51 UTC 2024



Op 8 apr 2024, om 08:59 heeft andyz <zhanglc77 at gmail.com> het volgende geschreven:

> Recently I tried to upgrade my project from openjdk 17.0.4 to 17.0.6, and after upgrading, I found that one of the opensearch containers had doubled the number of threads it was using. After investigating, I found that it seems that --cpu-shares is not working for 17.0.6, But I haven't seen any relevant updates in the release notes for 17.0.6.
> 
> I have attempted a reproduction(see below), Does openjdk no longer support --cpu-shares? If I want to use a newer version of openjdk, do I have to use some other parameter like cpu-limit ?

Have you checked if `Runtime.getRuntime().availableProcessors()` maybe returns a different value with the different JDK versions you tried?

I don’t know much about --cpu-shares, but https://docs.docker.com/config/containers/resource_constraints/#cpu shows Docker’s runtime flags for configuring the amount of access to CPU resources. It seems there is a --cpus=<value> flag if you want to directly control the number of CPUs a container has access to.

You can also set the processor count for the JVM inside the container specifically via the -XX:ActiveProcessorCount=<value> flag. Note that this flag affects the calculation of thread pool sizing, but does not actually restrict the access to CPUs.

----
java -XX:ActiveProcessorCount=10 -XX:+PrintFlagsFinal -version | grep ActiveProcessorCount
      int ActiveProcessorCount                     = 10                                        {product} {command line}
openjdk version "17.0.11" 2024-04-16 LTS
OpenJDK Runtime Environment Zulu17.50+19-CA (build 17.0.11+9-LTS)
OpenJDK 64-Bit Server VM Zulu17.50+19-CA (build 17.0.11+9-LTS, mixed mode, sharing)
----

There are typically also be more direct ways to control the sizes of the thread pools created by an application, if you don’t want those to be derived from the number of available CPUs.

Nils.


More information about the container-discuss mailing list