Azure Batch – Pool Auto scale forumulas

2016, Sep 19    

Just playing around with some Azure Batch Auto-scaling formulas.
See the Azure documentation here : https://azure.microsoft.com/en-gb/documentation/articles/batch-automatic-scaling/

Time based – Static

Between 8am and 6pm, Monday – Wednesday (0=Sunday) 5 nodes will be allocated to the pool.

$CurTime=time();
$WorkHours=$CurTime.hour>=8 && $CurTime.hour<18;
$IsWeekday=$CurTime.weekday>=1 && $CurTime.weekday<=3;
$IsWorkingWeekdayHour=$WorkHours && $IsWeekday;
$TargetDedicated=$IsWorkingWeekdayHour?5:0;

Task based - Dev/Economical

Restrict capacity to ** unless there is a waiting task - then allocates a single vm node to take the job.
This will built up to 5 minutes of latency before the pool autoscales, not including node boot time, and any pre-tasks the pool has associated. In my case this took up to 12 minutes before the scale occurred, originally going over my coded task schedulers timeout of 10 minutes.

$LastSampledActiveTasks= $ActiveTasks.GetSample(1);
$needcompute=min($LastSampledActiveTasks,1);
$TargetDedicated=$needcompute?1:0;

Combination of task and time

On Monday (8am-6pm) ensure a minimum capacity of 1. When there is a waiting task in the queue, increase the pool capacity by 1 node.

$CurTime=time();
$WorkHours=$CurTime.hour>=8 && $CurTime.hour<18;
$IsWeekday=$CurTime.weekday>=1 && $CurTime.weekday<=1;
$IsWorkingWeekdayHour=$WorkHours && $IsWeekday;
$minCapacity=$IsWorkingWeekdayHour?1:0;

$LastSampledActiveTasks=$ActiveTasks.GetSample(1);
$LastSampledRunningTasks=$RunningTasks.GetSample(1);
$RunningAndWaiting=max($LastSampledActiveTasks,1) + max($LastSampledRunningTasks,1);
$needcompute=$RunningAndWaiting>=1;
$TargetDedicated=$needcompute?($minCapacity+1):$minCapacity;

Hard limit

As above, but ensuring that the maximum pool size never exceeds 10.

$maxComputeNodeLimit=10;

$CurTime=time();
$WorkHours=$CurTime.hour>=8 && $CurTime.hour<18;
$IsWeekday=$CurTime.weekday>=1 && $CurTime.weekday<=1;
$IsWorkingWeekdayHour=$WorkHours && $IsWeekday;
$minCapacity=$IsWorkingWeekdayHour?1:0;

$LastSampledActiveTasks=$ActiveTasks.GetSample(1);
$LastSampledRunningTasks=$RunningTasks.GetSample(1);
$RunningAndWaiting=max($LastSampledActiveTasks,1) + max($LastSampledRunningTasks,1);
$needcompute=$RunningAndWaiting>=1;

$nodesToAllocate=$RunningAndWaiting>$maxComputeNodeLimit?$maxComputeNodeLimit:$RunningAndWaiting;
$TargetDedicated=$needcompute?$nodesToAllocate:$minCapacity;