To improve the CPU performance of a virtual machine (VM), you can prioritize CPU time allocation for that VM, by using the CPU weight setting.
About this task
The CPU weight setting controls how much CPU time a virtual machine (VM) receives compared to other running VMs. When you increase the CPU weight of a specific VM, that VM receives more CPU time relative to other VMs.
To configure the CPU weight of a VM, adjust its cpu_shares parameter. The possible CPU weight values range from 0 to 262144 and the default value for a new VM is 1024.
Procedure
-
Check the current CPU weight of a VM.
# virsh schedinfo <vm_name>
Scheduler : posix
cpu_shares : 1024
vcpu_period : 0
vcpu_quota : 0
emulator_period: 0
emulator_quota : 0
global_period : 0
global_quota : 0
iothread_period: 0
iothread_quota : 0
-
Adjust the CPU weight to a preferred value.
# virsh schedinfo <vm_name> --set cpu_shares=2048
Scheduler : posix
cpu_shares : 2048
vcpu_period : 0
vcpu_quota : 0
emulator_period: 0
emulator_quota : 0
global_period : 0
global_quota : 0
iothread_period: 0
iothread_quota : 0
In this example, cpu_shares is set to 2048. This means that if all other VMs have the value set to 1024, this VM receives approximately twice the amount of CPU time.
You can also use the --live --config options to configure a running VM without restarting it.