VMware Cloud Community
marypoppins
Contributor
Contributor
Jump to solution

cpu time question

Dear All,

I meet with dificulties again with vcpu allocation. As I know every vcpu (or logical cpu) share the host hardver cpu time if I have two guest (A,B) with 1-1 vcpu they share the full host cpu time (I ignored the hypervisor cpu demand for the simplicity). The guest cpu usage depends on its tasks. So if one of my guest (A) have so much things to do, that it wants more cpu time, then I have to allocate one more vcpu for it. In this case I have a guest A with two vcpu, and the other (B) with one vcpu. Now guest A requires the bigger piece from the host cpu time. It seems clear to me (if I am right)

My first question is: (also ignored the hypervisor cpu demand for the simplicity)

What is the differencies if I have a host with 4cores and two guests with 1-1 vcpu OR I have the same host with same two guests with 2-2 vcpu? It seems that they required the same quantity of cpu time from the host. So can the guest os (which can be use more cores in normal case) benefit from the 2 vcpu or is it enough only 1 (of course if the cpu usage is not 100%)? It seems I reach the nirvana wile I'm ask questions like this, because if a guest have only 1 vcpu and its cpu usage is low then i think there is enough the 1 vcpu Smiley Happy

Uhh I have to ask again from a new perspective, because I'm confused a little.

So what I don't understand that which is the best: using a guest with 1vcpu and 80% cpu usage on the guest, or using the same guest with 2vcpu and 40-40% cpu usage (on the guest)? So is there any benefit to assign more vcpu to a guest if its load is not required?

Uhh sorry for my chaotic questions...

thank you

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
NealeC
Hot Shot
Hot Shot
Jump to solution

Hi Marypoppins,

There are lots of things to consider when right sizing your VMs and any shares or resources pools you may want to use.

If you have a dual core server (I have in my home lab 🙂 and you ignore the hypervisor overhead) then yes if 2 VMs have 1vcpu then each VM gets one core each to execute instructions and will have that core to itself for ever because it doesn't know the other core is there.

So there is no scheduling issue.

If you have 1 VM with 100% cpu then it may help to assign 2 vCPU to it (presuming the OS and applications are multithreaded).

However if VM1 now has 2vCPU and VM2 still only has 1vCPU then now the hypervisor has to decide when to give time to VM1 and time to VM2.

The hypervisor will only schedule time to VM1 when it can give it BOTH vCPUs.  It won't just run it on 1 vCPU and look for the 2nd when it need it.

It will time slice and swap between giving VM1 both CPUs then giving only both vCPU to VM2 (even though it will only use 1)

Up your host to 4 cores.  Your 2 vms are happy again.  You can also up VM2 to 2 vCPU too.

We are back to the same happy situation as earlier.  Each VM has 2 vCPU all to itself.

If you now add another 1 vCPU  VM then again the hypervisor has a job to do.  It has to schedule time for each VM.

A common mistake people new to VMware take is to presume upping vCPU will solve resource issues.  However because the hypervisor can only schedule time for a VM when it has enough cores to service ALL it's vCPU needs then if you had 4 VMs with 4 vCPU on a 4 core server you will see lots of contention as they will be hard to schedule.

Now there's a lot to absorb there.  But on top of that you can use shares to guide the hypervisor in weighting VMs to give them more scheduled time than another VM.

To understand that, get some strong coffee and read the following pdf 🙂

http://www.vmware.com/files/pdf/techpaper/VMware-vSphere-CPU-Sched-Perf.pdf#src=vmw_so_vex_cneal_850

Hope that helps

-------------- If you found this or any other answer useful please consider the use of the Helpful or Correct buttons to award points. Chris Neale VCIX6-NV;vExpert2014-17;VCP6-NV;VCP5-DCV;VCP4;VCA-NV;VCA-DCV;VTSP2015;VTSP5;VTSP4 http://www.chrisneale.org http://www.twitter.com/mrcneale

View solution in original post

2 Replies
NealeC
Hot Shot
Hot Shot
Jump to solution

Hi Marypoppins,

There are lots of things to consider when right sizing your VMs and any shares or resources pools you may want to use.

If you have a dual core server (I have in my home lab 🙂 and you ignore the hypervisor overhead) then yes if 2 VMs have 1vcpu then each VM gets one core each to execute instructions and will have that core to itself for ever because it doesn't know the other core is there.

So there is no scheduling issue.

If you have 1 VM with 100% cpu then it may help to assign 2 vCPU to it (presuming the OS and applications are multithreaded).

However if VM1 now has 2vCPU and VM2 still only has 1vCPU then now the hypervisor has to decide when to give time to VM1 and time to VM2.

The hypervisor will only schedule time to VM1 when it can give it BOTH vCPUs.  It won't just run it on 1 vCPU and look for the 2nd when it need it.

It will time slice and swap between giving VM1 both CPUs then giving only both vCPU to VM2 (even though it will only use 1)

Up your host to 4 cores.  Your 2 vms are happy again.  You can also up VM2 to 2 vCPU too.

We are back to the same happy situation as earlier.  Each VM has 2 vCPU all to itself.

If you now add another 1 vCPU  VM then again the hypervisor has a job to do.  It has to schedule time for each VM.

A common mistake people new to VMware take is to presume upping vCPU will solve resource issues.  However because the hypervisor can only schedule time for a VM when it has enough cores to service ALL it's vCPU needs then if you had 4 VMs with 4 vCPU on a 4 core server you will see lots of contention as they will be hard to schedule.

Now there's a lot to absorb there.  But on top of that you can use shares to guide the hypervisor in weighting VMs to give them more scheduled time than another VM.

To understand that, get some strong coffee and read the following pdf 🙂

http://www.vmware.com/files/pdf/techpaper/VMware-vSphere-CPU-Sched-Perf.pdf#src=vmw_so_vex_cneal_850

Hope that helps

-------------- If you found this or any other answer useful please consider the use of the Helpful or Correct buttons to award points. Chris Neale VCIX6-NV;vExpert2014-17;VCP6-NV;VCP5-DCV;VCP4;VCA-NV;VCA-DCV;VTSP2015;VTSP5;VTSP4 http://www.chrisneale.org http://www.twitter.com/mrcneale
marypoppins
Contributor
Contributor
Jump to solution

In the end everything is about the guest cpu (ram, disk) usage. Until a guest has enough time slice to compute its instructions with 1 vcpu, then absolutely unnecessary to assign more. In a very simple (and maybe stupid) example if a guest (on an host with unlimited resource) make its functions with 1 vcpu in 5sec, it will make the same functions in 2.5sec with 2 vcpu. However in a limited environment (mainly in thin provisioning) assign more vcpu makes the hypervisor work harder to give time slices to the guest (with more vcpu).


thank you for your answer, i will read the documents as well

have a nice day

0 Kudos