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 deploy cpus issue and support pids limit #9552

Merged
merged 2 commits into from
Jun 14, 2022

Conversation

glours
Copy link
Contributor

@glours glours commented Jun 10, 2022

What I did
deploy.limits.cpus value could be a float value, you may want to use only 0.5 or 1.4 cpus for your containers, so I changed the parsing of the property to match those cases

I also add the deploy.limit.pids property to the container configuration when this one is setup

Related issue
fix #9542 #9501

(not mandatory) A picture of a cute animal, if possible in relation with what you did
image

@glours glours requested a review from a team June 10, 2022 09:14
@glours glours self-assigned this Jun 10, 2022
Copy link
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

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

Tested and code LGTM 🥳

Comment on lines 598 to 599
f, _ := strconv.ParseFloat(limits.NanoCPUs, 64)
resources.NanoCPUs = int64(f * 1e9)
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps overly paranoid/defensive, but I wonder if it's worth only doing the assignment if err == nil.

Also, this is probably overly pedantic, but the other CPU limit types appear to be float32, so I wonder if this should be ParseFloat(limits.NanoCPUs, 32) instead.


Beyond the scope of this PR, but the model here from compose-go seems inaccurate in both name + type.

It feels like either:

  • NanoCPUs int64 (and thus no parse or unit conversion needed here)
    OR
  • CPUs float32 (and keep the unit conversion * 1e9 here)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No right that's seems legit to assign only if there is no error 👍
Otherwise the NanoCPUs is coming from the Docker API and is different from the CPUs property of Compose services
And the Compose specification define deploy.resources.limits.cpus as the number of cpus, so user should define them like 0.5 or 2.4 if they want

f, _ := strconv.ParseFloat(limits.NanoCPUs, 64)
resources.NanoCPUs = int64(f * 1e9)
}
if limits.PIds > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Another potential fix in compose-go (s/PIds/PIDs/) we should make at some point 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! We definitely should fix that 😅

@glours glours merged commit 5797509 into docker:v2 Jun 14, 2022
@nexcode nexcode mentioned this pull request Dec 13, 2022
@glours glours deleted the fix-deploy-cpus-issue branch January 11, 2023 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deploy.resources.limits.cpus not effective?
3 participants