VMware Cloud Community
Vivchaturvedi
Contributor
Contributor

Needed Powercli script to limit vCPU

Hi,

I need help on powercli script to identify allocated vCPU on VMs and limit to same allocated.

 

Thanks in advance.

Reply
0 Kudos
18 Replies
LucD
Leadership
Leadership

What do you already have in that script you need help on?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Vivchaturvedi
Contributor
Contributor

Hello LucD,

 

I have this but not sure if this will work and hence want confirmation. Little scared to run in PRD infra.

$allocatedcpu = Get-VM | Get-VMResourceConfiguration | select NumCpuShares

Get-VM | Get-VMResourceConfiguration | Set-VMResourceConfiguration -CpuLimitMhz $allocatedcpu

 

Thanks,

Vivek

 

 

 

Reply
0 Kudos
LucD
Leadership
Leadership

I'm not sure what you are trying to do there.
You retrieve a relative number (CPU shares) and then use that to set a CPU limit in MHz.

The logic escapes me I'm afraid.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Vivchaturvedi
Contributor
Contributor

Yeah, I am trying to get allocated vCPUs from VMs and limit the same. I do not want VMs to use more than allocated.

 

Note :- I am not planning for Reserving CPU. 

Reply
0 Kudos
LucD
Leadership
Leadership

I have no idea what you mean.
Perhaps you could show with a screenshot of the Web Client what you are trying to do?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Vivchaturvedi
Contributor
Contributor

Currently, the Limit is set to unlimited. I want to limit it to allocated vCPUs.

Reply
0 Kudos
LucD
Leadership
Leadership

Ok, so that VM has 8 vCPU, but what do you intend to set the limit to?
That can't be 8 MHz?!?
Which value, and how do you intend to calculate it?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
scott28tt
VMware Employee
VMware Employee

I can't think of a reason to set a limit that's the equivalent of the number of virtual cores (multiplied by physical clock speed), that's the "natural" limit of a VM anyhow, and would also reflect if you ever changed the total number of virtual cores of the VM.

 


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
0 Kudos
Vivchaturvedi
Contributor
Contributor

If I calculate it, I have 40 Logical Processors and shows 44 GHz in summary page of Host. In this case, 1 vCPU would be 1.1 GHz.

Reply
0 Kudos
scott28tt
VMware Employee
VMware Employee

If your VM has 8 CPUs, what do you want the number of MHz limit to be?

Same question for a VM that had 4 CPUs.

 


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
0 Kudos
Vivchaturvedi
Contributor
Contributor

For 8vCPUs allocated, I will give 8x1.1GHz = 8800 MHz

Similarly, for 4vCPUs allocated, I will give 4x1.1 GHz = 4400 Mhz.

 

I am calculating according to host's CPU availability.

Reply
0 Kudos
depping
Leadership
Leadership

Please keep in mind that a limit is a hardstop. This means that even if the host is not doing anything, it will be limited to what was specified. Why not just rely on the shares, as that is what they do, they provide fair access to the resources.

If you don't have problems right now with performance, I would highly recommend avoiding limits!

Reply
0 Kudos
scott28tt
VMware Employee
VMware Employee

If 1.1GHz is your host clock speed, giving the VM 8 virtual CPUs will "limit" it to 8.8GHz anyway with the setting left as "Unlimited", same for a VM with 4 virtual CPUs having a natural "limit" of 4.4GHz with the setting left as "Unlimited".

 


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
0 Kudos
Vivchaturvedi
Contributor
Contributor

There is a reason for setting up a limit for VMs. 

 

We have some good number of Kub worker nodes. Not sure why but, service pods would run only on 1 or max 2 VM worker nodes and spike up the CPU to maximum of whatever available in Host. I have tested this by limiting the CPU to allocated size and can see improvement, where, service pods will now get distributed to other Kub worker nodes Vms. I know that we need to do some tuning from Kubernetes but for now, we need to save our hosts to die everytime.

 

Reply
0 Kudos
Vivchaturvedi
Contributor
Contributor

Nops, it will not natural allocated or limited. If I have unlimited set, then it can use the max available in host.

Reply
0 Kudos
scott28tt
VMware Employee
VMware Employee

8 x clock speed is the natural limit if using 8 CPUs in the VM, not the "max available in the host".

You still haven't actually said what your clock speed is, which makes "limiting to allocated size" difficult for anyone else to understand.

 


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
0 Kudos
Vivchaturvedi
Contributor
Contributor

It will go to the maximum whatever present on host for sure.

Clock speed is 2.20 GHz

 

Reply
0 Kudos
scott28tt
VMware Employee
VMware Employee

OK, now we have all the information to understand what you're trying to do.

So the natural limit for your 8 CPU VM is 17.6GHz and you'd like to set that to 8.8GHz, why not just give that VM 4 CPUs and leave it as "Unlimited"?

Same for a 4 CPU VM, the natural limit would be 8.8GHz but you want it to be 4.4GHz, why not just give it 2 CPUs and leave it as "Unlimited"?

 


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
0 Kudos