Azure batch auto scale formula

139 Views Asked by At

I'm trying to create a pool that always starts with 1 node. After 3 minutes of having more than 70% CPU usage the pool should generate another machine, and repeat. I'm using the current formula:

initialPoolSize = 1;
$TargetDedicatedNodes = initialPoolSize;
$totalDedicatedNodes =
    (avg($CPUPercent.GetSample(TimeInterval_Minute * 3)) >= 0.7) ?
    ($TargetDedicatedNodes + 1) : $TargetDedicatedNodes;

I also tried using this formula that is posted in the Microsoft documentation:

initialPoolSize = 1;
$TargetDedicatedNodes = initialPoolSize;
$totalDedicatedNodes =
    (min($CPUPercent.GetSample(TimeInterval_Minute * 3)) > 0.7) ?
    ($CurrentDedicatedNodes * 1.1) : $CurrentDedicatedNodes;

Both formulas don't work, I'm stuck with only 1 node for the entire build time, and the CPU usage is at 100%.

If anyone has any experience with this or can help that'll be greatly appreciated

2

There are 2 best solutions below

0
Gal Hadar On BEST ANSWER

This is the answer for anyone wondering

maxNumberOfVMs = 20; // maximum number of VMs you want

samplePercentThreshold = 0.7;

sampleDuration = TimeInterval_Minute * 3; 

// Get the last sample

$sample = (avg($CPUPercent.GetSample(sampleDuration)));

// If the average CPU usage was more than 70%, increase nodes by one, if 
not true keeps as is

$TargetDedicated = ($sample >= samplePercentThreshold ? $TargetDedicated +1 
: $TargetDedicated);

// If the average CPU usage is below 20% decrease nodes by one, if not true 
keep as is

$TargetDedicated = ($sample <= 0.2 ? $TargetDedicated - 1 : 
$TargetDedicated);

// Always keep the number of nodes under the maximum

$TargetDedicated = min($TargetDedicated, maxNumberOfVMs);
2
Venkatesan On

Create a pool that always starts with 1 node. After 3 minutes of having more than 70% CPU usage the pool should generate another machine, and repeat.

You can use the below autoscale formula to achieve your scenario.

initialnumberVm = 1;
maximumNumberVm =  10; 
DemoPercentThreshold = 0.7;
DemoDuration = TimeInterval_Minute * 3; 
$demo = $CPUPercent.GetSamplePercent(DemoDuration);
$TargetDedicated = ($CPUPercent.GetSamplePercent(DemoDuration) > DemoPercentThreshold ? initialnumberVm + 1 : initialnumberVm);
$TargetDedicated = max(initialnumberVm, min($TargetDedicated, maximumNumberVm));
  1. The maximum number of nodes allowed by this formula is 10, and it starts with one node.
  2. The pool's nodes have 3 minutes of average CPU utilization. It adds a new node to the pool if the average CPU utilization is more than or equal to 70%.
  3. It maintains the same number of nodes if the average CPU utilization is less than 70%. The number of nodes is constantly maintained between the initial value and the permitted maximum number.

Evaluation output:

$TargetDedicatedNodes=2
$TargetLowPriorityNodes=0
$NodeDeallocationOption=requeue
$demo=83.3333
DemoDuration=3m
DemoPercentThreshold=0.7
initialnumberVm=1
maximumNumberVm=10

enter image description here

Reference: Autoscale compute nodes in an Azure Batch pool - Azure Batch | Microsoft Learn