Rawpixel - Fotolia
Virtualization should ideally insulate VMs from the underlying hardware. The abstraction of CPUs into vCPUs, and the allocation of vCPUs to VMs, shouldn't present any adverse effects on VM performance -- ideally, every vCPU is complete and independent, and it shouldn't make any difference which vCPUs are assigned to which VMs. But it can.
A hypervisor, such as VMware ESXi, allows administrators to employ an affinity feature to favor the use of certain vCPUs for specific VMs, or use anti-affinity features to discourage the use of certain vCPUs for specific VMs.
The importance of vCPU affinity is largely related to the addition of hyper-threading processor technology. Remember, while threading effectively creates a second logical CPU, many of the processor's subsystems are shared. So, threading doesn't double the number of physical CPUs -- it's just a means of keeping CPUs busy when they might otherwise be idle. This benefit comes with a potential performance penalty. When two threads from the same core are allocated to two different VMs, the compute demands of those VMs could cause performance degradation of either or both VMs.
For example, consider a hyper-threaded CPU core. This provides two logical CPUs that are virtualized as two vCPUs: CPU 0 and CPU 1. The second threaded core would be denoted CPU 2 and CPU 3. A third threaded core would be designated CPU 4 and CPU 5, and so on.
It's perfectly plausible to allocate CPU 0 to one VM and CPU 1 to another VM -- effectively putting two different workloads on the same physical CPU core. This can, and often does, work fine, assuming both VMs make modest demands of the CPU. However, if one or both of those VMs place heavy demands on the CPU, it can stifle the performance of the other VM or see its own performance impaired because the underlying physical CPU just can't handle the load.
The idea with affinity and anti-affinity is an administrator can manage vCPU distribution to alleviate such potential problems and optimize the performance of VMs across the physical system. For the previous example, an administrator can apply affinity rules to run the first VM on CPU 0 -- the first thread of the first core. And then, he can either use another affinity rule with the second VM to stipulate CPU 2, which is the first thread of the second core, or use anti-affinity rules to simply prevent the second VM from running on CPU 1 -- don't care where else that VM runs, just not here.
Affinity and anti-affinity rules aren't always required. Many average workloads can run well when sharing a CPU core through hyper-threading. Rules are most beneficial when optimizing critical or compute-intensive workloads.
Manage memory resources for VMs
Improve VM networking performance
Dig Deeper on Virtual machine performance management
Related Q&A from Stephen J. Bigelow
Eliciting performance requirements from business end users necessitates a clearly defined scope and the right set of questions. Expert Mary Gorman ... Continue Reading
Requirements fall into three categories: business, user and software. See examples of each one, as well as what constitutes functional and ... Continue Reading
Navigating data center malfunctions when hardware is off premises can be tricky. Organizations must have strong SLAs with their colo provider to ... Continue Reading