Nomenator
Nomenator

Reputation: 1137

How to round in Azure batch autoscale formula

When I commit my formula, Azure complains about calculation errors. I narrowed it down to having a number with decimal places. Here’s my formula:

pivot = (0.15*($CurrentDedicated/20)+0.84);
target = $CurrentDedicated*(($CPUPercent.GetSample(TimeInterval_Minute*5)/100)/pivot);

Naturally, it complains about not having a sample, so I put in $CPUPercent.GetSamplePercent(TimeInterval_Minute*0,TimeInterval_Minute*5) in a ternary expression, but it complains about “evaluation error”. I figure this is happening because I’m trying to provision a fractional number of dedicated machines.

So… How can I round up and down in such an expression?

UPD:

So I found my problem, $CPUPercent.GetSample should not be used as a number. Instead, max(), min(), or avg() should be used on it to produce a number. The corrected formula is as follows:

samplepercent = $CPUPercent.GetSamplePercent(TimeInterval_Minute*0,TimeInterval_Minute*5);
pivot = (0.15*($CurrentDedicated/20)+0.84);
$TargetDedicated = samplepercent < 0.7 ? 1 : $CurrentDedicated*((avg($CPUPercent.GetSample(TimeInterval_Minute*5))/100)/pivot);

Sadly, there is no way to round up or down. The autoscale expressions to not have functions for it and do not have the % operator defined (x = x - x%1 and x = x - x%1 + 1 to round down and up respectively). This is sad indeed and may require me to review the above equation to make sure it works as intended.

Upvotes: 0

Views: 929

Answers (1)

Related Questions