chef / knife-vsphere

Chef knife plug-in for VMware vSphere
Apache License 2.0
202 stars 125 forks source link

Unable to modify a VM's CPU core count #353

Closed Here-Be-Dragons closed 7 years ago

Here-Be-Dragons commented 7 years ago

What are you trying to do and what's not working?

When cloning or customizing a VM's CPU configuration, only the vCPU count is addressed. Core count cannot be modified. This prevents configurations following VMware's best practices, and could have licensing implications for Operating Systems or software licensed per physical socket.

Please paste the command and output (run with -VV). Don't forget to X out any passwords or sensitive information

Use case: Cloning a template with the end CPU configuration being 1 vCPU, 4 Cores.

Functionality Today

$ knife vsphere vm clone NewNode --template UbuntuTemplate --cspec StaticSpec \
    --cips 192.168.0.99/24 \
    --chostname NODENAME --cdomain NODEDOMAIN \
    --ccpu 4

Result: VM with 4 vCPUs and 1 core per vCPU.

Expected Functionality

$ knife vsphere vm clone NewNode --template UbuntuTemplate --cspec StaticSpec \
    --cips 192.168.0.99/24 \
    --chostname NODENAME --cdomain NODEDOMAIN \
    --ccpu 1 --ccore 4

Result: VM with 1 vCPU and 4 cores per vCPU.

Other details, such as gem version and if you're working with a Linux or Windows VM

No "CPU Core" configuration option as of Gem 1.2.25

swalberg commented 7 years ago

Hi, thanks for report. If I'm understanding this correctly, we need to set the numCoresPerSocket value in the config part of the spec:

numCoresPerSocket*  xsd:int 
Number of cores among which to distribute CPUs in this virtual machine.
Since vSphere API 5.0

numCPUs*    xsd:int 
Number of virtual processors in a virtual machine.
Reconfigure privilege: VirtualMachine.Config.CpuCount 

Can you also point me to the docs you're referring to so I can make sure this gets done in line with VMWare's recommendations?

Thanks,

Sean

Here-Be-Dragons commented 7 years ago

Yes, numCoresPerSocket is the value that references the cores to be applied to a virtual machine. The best practices are covered in this document: https://www.vmware.com/content/dam/digitalmarketing/vmware/en/pdf/techpaper/vmware-perfbest-practices-vsphere6-0-white-paper.pdf. Here are excerpts that relate to the allocation of sockets vs. cores:

Page 20:

Configuring a virtual machine with more virtual CPUs (vCPUs) than its workload can use might cause slightly increased resource usage, potentially impacting performance on very heavily loaded systems. Common examples of this include a single-threaded workload running in a multiple-vCPU virtual machine or a multi-threaded workload in a virtual machine with more vCPUs than the workload can effectively use.

Page 22:

Because of this difference, there can be a slight performance advantage in some environments to virtual machines configured with no more vCPUs than the number of cores in each physical NUMA node.

Conversely, some memory bandwidth bottlenecked workloads can benefit from the increased aggregate memory bandwidth available when a virtual machine that would fit within one NUMA node is nevertheless split across multiple NUMA nodes. This split can be accomplished by limiting the number of vCPUs that can be placed per NUMA node by using the maxPerMachineNode option (do also consider the impact on vNUMA, however, by referring to “Virtual NUMA (vNUMA)” on page 48).

Page 48:

In some cases, though, you might have non-technical reasons to set cores per virtual socket to a value other than 1. For example, software is sometimes licensed on a per-socket basis, making it desirable to have multiple cores per virtual socket.

Here-Be-Dragons commented 7 years ago

Hot off the presses just for us! This article is much more concise than the previously linked white paper. https://blogs.vmware.com/performance/2017/03/virtual-machine-vcpu-and-vnuma-rightsizing-rules-of-thumb.html

swalberg commented 7 years ago

Thanks! I'm traveling until Monday so won't be able to do anything about it right away. I'd also like to learn more about this so we set up the options that make the most sense.

I might not be reading your --ccpu 1 --ccore 4 example correctly though. The last article you posted seems to point to --ccpu being a multiple of --ccore, such that in your example I'd expect --ccpu to be a multiple of 4. I think the way you're describing it, you're saying "I want 4 cpus per socket, and give me one of those".

Right now I think there's an expectation that --ccpu=X will give you X CPUs (e.g. ask the OS how many CPUs it has, this is X), rather than a multiplication of cores per socket times sockets. What do you think?

Here-Be-Dragons commented 7 years ago

Interesting... it looks like they present the CPU/Core screen differently in the web interface. This is how it is presented in the legacy fat client (and thus my confusion):

vSphere Cpu and Core Count

I will need to do some testing, but I do believe you are correct-- it is a division of the two numbers, not the product. So --ccpu 8 --ccore 4 would leave you with 2 physical sockets, 4 cores per socket. I'd want to know what the end result would be of something like --ccpu 2 --ccore 4 would do...

The good news: if you do implement numCoresPerSocket, it will not impact existing commands, since the default for numCoresPerSocket is 1 unless specified otherwise.

For clarity, would you like me to edit my original issue?

swalberg commented 7 years ago

Hey, no need to update, I think having the history of how we got here is good.

So I'm thinking that rather than --ccore we're now looking at --ccorespersocket or something like that? Or would it help people more to say --csockets and the code does the math?

Let me know how your testing goes.

Here-Be-Dragons commented 7 years ago

Just chatted with a few folks on my automation team and while they agreed that the way VMware does the API seems backwards, it would probably be best to do a 1-for-1 map to the API. I guess that is something for you to decide, though! As long as it is clear what the command does in the knife vsphere documentation we can use either to accomplish our goals.

jjasghar commented 7 years ago

Just from a UX standpoint --ccorespersocket seems more verbose and what people will gravitate to. Unfortunately, I never have to use these options so I'm just thinking academically.

petericebear commented 7 years ago

Having the same issue. Any updates an this?

swalberg commented 7 years ago

Thanks for the reminder -- after I got back home this one slipped my mind. I'll get to work on this one.

petericebear commented 7 years ago

Thanks man! That would be awesome!

petericebear commented 7 years ago

For the time being after cloning a VM I set the cores to the same amount of numCPUs of --ccpu 5 Then before power on: knife vsphere vm numCoresPerSocket 5

It then uses 1 socket for the CPUs. The --ccorespersocket would be great, but this can help some people till then.

petericebear commented 7 years ago

This is now merged, can be closed?