-
Notifications
You must be signed in to change notification settings - Fork 303
✨Add flags to allow customization of CPU shares and reservations #3607
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
base: main
Are you sure you want to change the base?
✨Add flags to allow customization of CPU shares and reservations #3607
Conversation
for each cloned VM Signed-off-by: Tommaso <[email protected]>
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Welcome @tommasopozzetti! |
Hi @tommasopozzetti. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
This seems incredibly useful, thank you for doing this! Any chance you could do something similar for memory reservations as well? |
I’d be happy to add to the PR similar logic for memory reservation and shares as well as potentially memory pinning I was hoping to first get a glance from a maintainer to see if this approach is reasonable given it’s my first contribution to this project! |
// CPUReservationMhz is the amount of CPU in MHz that is guaranteed available to the virtual machine. | ||
// Defaults to the eponymous property value in the template from which the | ||
// virtual machine is cloned. | ||
// +optional | ||
CPUReservationMhz int64 `json:"cpuReservationMhz,omitempty"` | ||
// CPUShares are a relative priority to other virtual machines used in case of resource contention. | ||
// Defaults to the eponymous property value in the template from which the | ||
// virtual machine is cloned. | ||
// +optional | ||
CPUShares int32 `json:"cpuShares,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to have something like:
resources:
reservation:
cpu: ...
memory: ...
shares:
...
Or maybe this should be modelled in the k8s wordings which has limits
and requests
? (might not match the things this PR currently sets).
This is e.g. done by the vm-operator APIs. However, vm-operator does not use shares.
Could someone research what the benefits are of setting shares? And should we also consider CPU Limit to be set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrischdi thanks for the review!
In terms of shares vs reservations, shares are a relative measure of prioritization while reservations are an absolute one. A VM with 2Ghz set for reservation will be guaranteed that even under host contention, it will always have 2Ghz of cpu power available to it. The vSphere admission controller will prevent a VM to power on if the total sum of reservations for VMs on a given host exceeds the total available cpu power of that host (no overprovisioning).
Shares on the other hand are just meaningful relative to shares of other VMs on that host. The host can be over provisioned and if it comes under cpu contention, VMs will be prioritized for cpu time relative to each other depending on their shares. So if a host has 3 VMs, one with 6000 shares, one with 3000 and one with 1000, if the host comes under cpu contention, the first will get 60% of cpu time, the second 30% and the third 10%. Each VM normally gets shares assigned by default proportional to its number of vCPUs but it is very useful to be able to tune that at will.
In terms of using cpu/memory limits, I have never had to implement these but they essentially would artificially cause the same effects as if the underlying host was under resource contention even if it is not, when the VM reaches said limit. More detailed info here. I'd be happy to add to this PR the limit as well as an optional configurable if desired.
Finally, in terms of the syntax, I'm open to suggestions! I personally feel like using the same syntax as standard Kubernetes containers might be misleading since the practical implementation of using reservations, shares and limits on VMs is very different than memory and cpu requests and limits for k8s pods.
I was going for a more flat mapping similar to the other properties that matches with the VM options and would look like
cpuReservationMhz: xxx
cpuShares: xxx
cpuLimitMhz: xxx
memoryReservationMB: xxx
memoryShares: xxx
memoryLimitMB: xxx
reserveAllMemory: false
but, if preferred, we could also go for something nested like
resourceManagement:
cpu:
reservationMhz:
shares:
limitMhz:
memory:
reservationMB:
shares:
limitMB:
reserveAll:
or similar
Hi @chrischdi, following up on your comment, do you have any thoughts on my reply? |
What this PR does / why we need it:
This PR adds flags to optionally customize CPU shares and reservations for cloned VMs as part of the vSphereMachine spec