-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Update VM priority (cpu_shares) when live scaling it #6031
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,8 +39,10 @@ public Answer execute(ScaleVmCommand command, LibvirtComputingResource libvirtCo | |
|
|
||
| long newMemory = ByteScaleUtils.bytesToKib(vmSpec.getMaxRam()); | ||
| int newVcpus = vmSpec.getCpus(); | ||
| int newCpuSpeed = vmSpec.getMinSpeed() != null ? vmSpec.getMinSpeed() : vmSpec.getSpeed(); | ||
| int newCpuShares = newVcpus * newCpuSpeed; | ||
| String vmDefinition = vmSpec.toString(); | ||
| String scalingDetails = String.format("%s memory to [%s KiB] and CPU cores to [%s]", vmDefinition, newMemory, newVcpus); | ||
| String scalingDetails = String.format("%s memory to [%s KiB], CPU cores to [%s] and cpu_shares to [%s]", vmDefinition, newMemory, newVcpus, newCpuShares); | ||
|
|
||
| try { | ||
| LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper(); | ||
|
|
@@ -51,6 +53,7 @@ public Answer execute(ScaleVmCommand command, LibvirtComputingResource libvirtCo | |
| logger.debug(String.format("Scaling %s.", scalingDetails)); | ||
| scaleMemory(dm, newMemory, vmDefinition); | ||
| scaleVcpus(dm, newVcpus, vmDefinition); | ||
| updateCpuShares(dm, newCpuShares); | ||
|
|
||
| return new ScaleVmAnswer(command, true, String.format("Successfully scaled %s.", scalingDetails)); | ||
| } catch (LibvirtException | CloudRuntimeException e) { | ||
|
|
@@ -68,6 +71,22 @@ public Answer execute(ScaleVmCommand command, LibvirtComputingResource libvirtCo | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sets the cpu_shares (priority) of the running VM. This is necessary because the priority is only calculated when deploying the VM. | ||
| * To prevent the cpu_shares to be manually updated by using the command virsh schedinfo or restarting the VM. This method updates the cpu_shares of a running VM on the fly. | ||
| * @param dm domain of the VM. | ||
| * @param newCpuShares new priority of the running VM. | ||
| * @throws org.libvirt.LibvirtException | ||
| **/ | ||
| protected void updateCpuShares(Domain dm, int newCpuShares) throws LibvirtException { | ||
| int oldCpuShares = LibvirtComputingResource.getCpuShares(dm); | ||
|
|
||
| if (oldCpuShares < newCpuShares) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only up, never down? is this like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In ACS, the live scale process does not allow to reduce the resource of a running VM. Therefore, it can only occur upwards and the cpu_shares is calculated as follow:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks the new speed >= current speed, new cpu core >= current cpu core |
||
| LibvirtComputingResource.setCpuShares(dm, newCpuShares); | ||
| logger.info(String.format("Successfully increased cpu_shares of VM [%s] from [%s] to [%s].", dm.getName(), oldCpuShares, newCpuShares)); | ||
| } | ||
| } | ||
|
|
||
| protected void scaleVcpus(Domain dm, int newVcpus, String vmDefinition) throws LibvirtException { | ||
| long runningVcpus = LibvirtComputingResource.countDomainRunningVcpus(dm); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.