Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I know I could test this, but I don't have the time right now to setup pristine test conditions to learn something that should be in documented form - and that I cannot find in an authoritative form.

I am thinking that the CPU% consumed on a VM is relative to the total CPU allotted to the VM and that spare CPU cycles on the host are allotted to all running VMs in a host equally.

So given 2 VMs on a host, where VM1 is consuming 50% of the host CPU capacity and VM2 is consuming 10% of the host CPU capacity. So 40% CPU capacity is available and divided equally into the running VMs.

VM1 sees a CPU potentiality 70% of the total host CPU (50% actual CPU consumed + 20% -or half- of the spare cycles). So VM1 records CPU consumption of 71.42% (50% actual / 70% allotted total * 100 = 71.42% and 28% CPU free.

VM2 sees a CPU potentiality of 30% of the total host CPU (10% actual CPU consumed + 20% -or the other half- of the spare cycles). So, VM2 records CPU consumption of 33.333% and 66.666% free.

Stopping any one of the VMs should immediately increase the spare CPU available to the other and this should show up as a drop in the CPU consumption of the other.

True or False? If False, what don't I understand?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

You've used a few tags here, and it seems you're looking for a generic answer. That may not be possible: KVM and Vmware handle things differently.

In ESXi, CPU is allocated to virtual machines using two methods:

  • CPU core count
  • Restriction in raw MHz

A single CPU core can use up to the physical core's speed, or the MHz restriction, whichever is lower.

ESXi records the amount of MHz used by a VM. If it's multi-core, it'll have more head-room. However, single-thread performance will never exceed the speed of a single physical core's performance.

Inside the VM itself, it'll see as many cores as are assigned to it and will compute performance based on that.


It looks like you're feeling around the "how do CPU consumption metrics look when VMs are oversubscribed for compute" problem.

For ESXi, this is how it would work:

Host machine:

  • 4 cores, 2.9GHz each

VM1 & 2:

  • 3 cores assigned, no MHz restrictions

Which is a 50% over-subscription.

Given that VM1 is using 50% of it's allocated resources, VMware would report that as 4350 MHz consumed and the CPU monitor in the VM would see 50% used. For VM2 using 10% of assigned resources, VMware would report 870 MHz consumed, and the VM would see 10% used.

In short, the VMs wouldn't notice each other.

Now for the case where there is a true over-usage. Add a third VM, configured the same as the other two, and assume all three are trying to use 50% of their CPU allocation. We have three VMs attempting to use 13050 MHz, but there are only 1160MHz to go around. How does this work, and how does it manifest?

Again, for ESXi, it'll down-clock the VMs so they're using fewer actual CPU cycles. They'll actually be using 3800ish MHz each of their 8700MHz allocation, and will therefore report a usage of 43%.

share|improve this answer
    
+1 there is no generic answer here, KVM does not handle things the same way ESX does –  dyasny Jan 19 '13 at 4:57
add comment

I am thinking that the CPU% consumed on a VM is relative to the total CPU allotted to the VM and that spare CPU cycles on the host are allotted to all running VMs in a host equally.

No, not necessarily. First part is correct, but non-stupid VM hosts can prioritize VM's, so the distribution will / may not be equally.

True or False?

False.

100% cpu on a VM is whatever slice it CAN use, as CPU consumption you see in a VM is measured IN A VM:

When over VM's turn off, there is more available for you. Granted.

But whether this results in a lower CPU usage on your VM, or simply tasks getting done faster (and the usage staying at 100%) is depending on your software. If you are CPU bound, you may put the larger allocation to use. If you are NOT cpu bound, you WILL see a drop as you use less of your "available" slice.

share|improve this answer
    
Thank you. I understand that VM CPU is measured within a VM, and that VMs are given slices of the CPU. However, I cant imagine that VMWare and KVM are non-preemptive. Put in other words, it has been several decades since the last non-preemptive scheduler was used in an operating system. The only non-preemptive systems around that I know of are all real-time systems. This means that the VM Host will not allocate slices to VMs if the VMs have nothing to do. A slice is therefore not a set size and is relinquished if the guest has no work to do. Therefore Spare cycles must be allocated somehow. –  Ravenor Jan 18 '13 at 21:26
    
@Ravenor: The VM does not care what the CPU does when the VM doesn't want to use it. Whether it's asleep or working for another VM makes no difference to that VM. From the VM's point of view, the CPU is idle. –  David Schwartz Jan 19 '13 at 0:42
    
Exactly. It does not HAVE to use the slice, but as all timing is interrupt controlled, it can not SEE that - when it does not USE the CPU, it does not actually HAVE it. Nothing non-preemtive here. As a VM simulates hardware, it also simulates the clock. "CPU was not in use for 2ms" means - IN the VM FOR The VM. The VM has no idea that something else may have used the CPU in this time. At the same time, "CPU In use for 3ms without interruption" is nice for the VM, but it may not be the truth as the VM can not see the interuptions and that the CPU was used by another VM. –  TomTom Jan 19 '13 at 2:46
    
Thanks guys, I understand no. +1 TomTom. –  Ravenor Jan 21 '13 at 17:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.