On Monday I posted a script for configuring virtual machine CPU scheduler settings. This script got me to thinking about another use for the virtual machine CPU reserve.
You see, it can also be used to ensure that you do not unintentionally start too many virtual machines at once.
If you were to set the CPU reserve on each virtual machine at 20% (or at 20,000 using the underlying API) then it is not possible to start extra virtual machines once you hit a ratio of 5 virtual processors for each physical processor. This is actually what System Center Virtual Machine Manager does to enforce limits on the system.
Here is a script that will do just that:
If you run this script and specify “20000” then you will be able to run at a ratio of 5 virtual processors for each physical processor. If you run this script and specify “25000” then you will be able to run at a ratio of 4 virtual processors for each physical processor.
Note that this will not apply to any virtual machine snapshots, or to any newly created virtual machines, so it is a little fragile as a solution.