Choosing a CPU in ESXi?

paintb4707paintb4707 Member Posts: 420
Hey guys,

I have a dual Quad Core Xenon box and just loaded ESXi on it. I'm having a bit of an issue though. I can't seem to figure out how to allocate a specific physical CPU to a virtual machine. I can choose the number of CPUs and the affinity but how do you know which physical processor the virtual machine is running off of?

Thanks in advance

Comments

  • JDMurrayJDMurray Admin Posts: 13,101 Admin
    I don't think you can pin a VM to a specific core in ESXi. The point of a multi-core CPU is to allow the OS can run multiple threads from the same process in parallel on different cores. Pinning a VM to only a single core would hurt the OS' ability to optimize performance for all running VMs. And I'm assuming that ESXi has been written to take advantage of multi-core CPUs in this way. It may very well be that ESXi is only capable of assigning one VM to a single core core, but the specific core can't be choosen or determined from the ESXi console or API.
  • RTmarcRTmarc Member Posts: 1,082 ■■■□□□□□□□
    On ESXi you can set the processor affinity in the Advanced CPU section of the Resources tab (Edit Settings of VM > Resources > Advanced CPU). Look in the Scheduling Affinity section and you can indicate which processor(s) you want the VM to run.

    I don't recommend doing this unless you have a very specific reason to do so. This can cause contention problems with resource scheduling if done incorrectly. In fact, don't ever assign more than one processor to a VM unless it has an application that can take advantage of multiple processors.
  • paintb4707paintb4707 Member Posts: 420
    JDMurray wrote: »
    I don't think you can pin a VM to a specific core in ESXi. The point of a multi-core CPU is to allow the OS can run multiple threads from the same process in parallel on different cores. Pinning a VM to only a single core would hurt the OS' ability to optimize performance for all running VMs. And I'm assuming that ESXi has been written to take advantage of multi-core CPUs in this way. It may very well be that ESXi is only capable of assigning one VM to a single core core, but the specific core can't be choosen or determined from the ESXi console or API.

    The thing is I'm not trying to choose a specific core. I would like to pick a specific physical processor from my dual CPU host so that it will use all 4 cores from CPU A and another VM will use all 4 cores from CPU B.

    Or does ESX not work that way and just sees both processors as 1? Because I do notice it says I have 8 cores.
  • RTmarcRTmarc Member Posts: 1,082 ■■■□□□□□□□
    It treats the cores as physical processors.

    1-4 = cpu 0
    5-8 = cpu 1
  • paintb4707paintb4707 Member Posts: 420
    RTmarc wrote: »
    It treats the cores as physical processors.

    1-4 = cpu 0
    5-8 = cpu 1

    I thought that was the way it works. However when you create the VM and choose 2 vCPUs for example then go into the Affinity selection you could still choose 4 cores or as many as you like so it confused me.
  • RTmarcRTmarc Member Posts: 1,082 ■■■□□□□□□□
    What is your hyperthreading status displaying?
  • paintb4707paintb4707 Member Posts: 420
    RTmarc wrote: »
    What is your hyperthreading status displaying?
    Inactive
  • HeroPsychoHeroPsycho Inactive Imported Users Posts: 1,940
    RTmarc wrote: »
    I don't recommend doing this unless you have a very specific reason to do so. This can cause contention problems with resource scheduling if done incorrectly. In fact, don't ever assign more than one processor to a VM unless it has an application that can take advantage of multiple processors.

    And when assigning affinity like this, which is 95% of the time a bad idea, never assign it the first proc/core. That is the proc VMware will use for itself, so that proc is less available than any other.
    Good luck to all!
  • paintb4707paintb4707 Member Posts: 420
    Okay, I suppose I'll leave the affinity alone then. icon_redface.gif

    Thanks for the help guys
  • blargoeblargoe Member Posts: 4,174 ■■■■■■■■■□
    I believe that it will always attempt to assign the vcpu's to cores on the same physical processor first. It's probably already doing what you want... you could run a CPU load tester on one of the VM's and see which CPU's spike up I guess.

    Generally, it's not a good idea to even use that many vcpu's in production unless you're really, really, really sure the VM needs that many.
    IT guy since 12/00

    Recent: 11/2019 - RHCSA (RHEL 7); 2/2019 - Updated VCP to 6.5 (just a few days before VMware discontinued the re-cert policy...)
    Working on: RHCE/Ansible
    Future: Probably continued Red Hat Immersion, Possibly VCAP Design, or maybe a completely different path. Depends on job demands...
  • astorrsastorrs Member Posts: 3,139 ■■■■■■□□□□
    paintb4707 wrote: »
    I thought that was the way it works. However when you create the VM and choose 2 vCPUs for example then go into the Affinity selection you could still choose 4 cores or as many as you like so it confused me.
    You are telling it that it is allowed to schedule the vCPUs on any of those pCPUs (and only those) you set the affinity too.

    Like others said though, just leave affinity alone unless you have a specific requirement and also start with 1 vCPU and only add more if necessary (don't believe taskmanager either, instead rely on the VI Client performance counters for diagnosing CPU issues).
Sign In or Register to comment.