RFR: 8265836: OperatingSystemImpl.getCpuLoad() returns incorrect CPU load inside a container [v4]
Severin Gehwolf
sgehwolf at openjdk.java.net
Tue May 25 11:42:42 UTC 2021
On Tue, 25 May 2021 06:25:23 GMT, Hao Tang <github.com+7947546+tanghaoth90 at openjdk.org> wrote:
>> OperatingSystemImpl.getCpuLoad() may return 1.0 in a container, even though the CPU load is obviously below 100%.
>>
>> We created a 5-core container and run 4 "while (true)" loops in the container. OperatingSystemImpl.getCpuLoad() returned 1.0, which is incorrect (0.8 is correct).
>> "systemLoad" in getCpuLoad() is exactly 4.0 before "systemLoad = Math.min(1.0, systemLoad);". The problem is caused by using the elapsed time (specified by "cpu.cfs_period_us") instead of the total CPU time (specified by "cpu.cfs_quota_us"). Therefore, it is more reasonable to divide cpu usage time by "quotaNanos" instead of "elapsedNanos".
>
> Hao Tang has updated the pull request incrementally with one additional commit since the last revision:
>
> Fix compile errors on MacOS
LGTM. Nit: Please remove `PER_CPU_SHARES` constant as it's no longer used.
src/jdk.management/unix/classes/com/sun/management/internal/OperatingSystemImpl.java line 44:
> 42:
> 43: private static final int MAX_ATTEMPTS_NUMBER = 10;
> 44: private static final int PER_CPU_SHARES = 1024;
I think this is no longer used anywhere so can get removed.
-------------
Marked as reviewed by sgehwolf (Reviewer).
PR: https://git.openjdk.java.net/jdk/pull/3656
More information about the serviceability-dev
mailing list