Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve resource duration accuracy. Fixes #12468 #12492

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

AloysAqemia
Copy link
Contributor

@AloysAqemia AloysAqemia commented Jan 9, 2024

Fixes #12468

Motivation

Fix cpu ressources consumption estimation.

Modifications

Change the use of the .Values() function (which rounds ressources up to an integer) to .MilliValues() which is more accurate for CPU resources, which can be fractional.
The MilliValues() documentation mentions that this function may overflow, but the return value is stored in an int64, so the overflow will happen if a container requests more than 9*10^(15) of a ressource. I assume this should be fine for a while.

Verification

Tested by submitting the workflow attached to the issue this PR fixes. The result is now what is expected:

      resourcesDuration:
        cpu: 63
        memory: 101

Copy link
Member

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM, nice catch!

I think this doesn't require any changes to the docs either

The unit tests need some modifications now though as they are failing due to different expected values.
The E2E test failure seems like an unrelated test flake at a glance (c.f. #10807)

@AloysAqemia
Copy link
Contributor Author

Thanks for taking a look @agilgur5 !
I think there's an issue in the code, the memory shouldn't be 0. I'll look into it.

The `.Values()` function rounds cpu ressources up to an integer. As a result, containers with small cpu requests (like the sidecar that requests 10m cores) are counted as requiring one full core, making the resources duration computation quite inaccurate.
This changes uses `.MilliValues()` instead. The `MilliValues()` documentation mentions that this function may overflow, but the return value is stored in an int64, so the overflow will happen if a container requests more than 9*10^(15) of a ressource. I assume this should be fine for a while.

Signed-off-by: Aloÿs Augustin <[email protected]>
@AloysAqemia
Copy link
Contributor Author

It turns out removing the conversion of age into seconds caused an overflow as time.Second == 1e9. This is now fixed, this PR should be good now.

@AloysAqemia AloysAqemia marked this pull request as ready for review January 9, 2024 17:48
@agilgur5
Copy link
Member

agilgur5 commented Jan 9, 2024

Oh, good find! I would not have expected an overflow and did not know that time.Second is that big 😮 (edit: apparently time is measured in nanoseconds in Go)

Copy link
Member

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a small style comment and a question for clarification

util/resource/summary.go Show resolved Hide resolved
util/resource/summary.go Show resolved Hide resolved
@terrytangyuan terrytangyuan merged commit 09edbf7 into argoproj:main Feb 5, 2024
29 checks passed
isubasinghe pushed a commit to isubasinghe/argo-workflows that referenced this pull request Feb 20, 2024
isubasinghe pushed a commit to isubasinghe/argo-workflows that referenced this pull request Feb 27, 2024
isubasinghe pushed a commit to isubasinghe/argo-workflows that referenced this pull request Feb 28, 2024
@agilgur5 agilgur5 changed the title fix(resources): improve ressource accounting. Fixes #12468 fix: improve ressource duration accuracy. Fixes #12468 Feb 29, 2024
@agilgur5 agilgur5 changed the title fix: improve ressource duration accuracy. Fixes #12468 fix: improve resource duration accuracy. Fixes #12468 Feb 29, 2024
isubasinghe pushed a commit to isubasinghe/argo-workflows that referenced this pull request Mar 12, 2024
isubasinghe pushed a commit to isubasinghe/argo-workflows that referenced this pull request May 6, 2024
isubasinghe pushed a commit to isubasinghe/argo-workflows that referenced this pull request May 7, 2024
@agilgur5 agilgur5 added this to the v3.4.x patches milestone May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resource duration is overestimated for cpu
3 participants