Jump to content

Implement Rule-Based scaling in Logic App Standard via Logic App Consumption


Recommended Posts

Guest Drac_Zhang
Posted

Background

 

As we all know, in Logic App Standard with WS ASP, we follow the target-based scaling as Azure Function EP plan which mostly depends on job queue length not CPU/memory usage.

 

But in some situations, we could experience high CPU/memory usage without a long job queue which results to the scale controller cannot vote to increase backend instances as expected.

 

 

 

So this blog is introduce how to "simulate" rule based scaling feature for Logic App Standard with WS plan as Logic App Standard running in ASE via using Logic App Consumption (it can be out Azure products as well, eg: Azure Function).

 

 

 

Mechanism

 

Since we need to scale based on CPU/memory usage (can be different metrics as well) , so the first issue we need to resolved is to get metrics data as following:

 

[ATTACH type=full" alt="2024-08-13_13h13_31.png]62641[/ATTACH]

 

For example, if we would like to get average CPU usage, we can go into CPU Percentage page and capture a HAR trace which can tell us that the API used in portal is like:

 

https://management.azure.com/subscriptions/[subscriptionID]/resourceGroups/[ResourceGroup]/providers/Microsoft.Web/serverFarms/[ASP Name]/providers/microsoft.Insights/metrics?timespan=[startTime]/[EndTime]&interval=PT1M&metricnames=CpuPercentage&aggregation=average&metricNamespace=microsoft.web%2Fserverfarms&autoadjusttimegrain=true&validatedimensions=false&api-version=2019-07-01

 

 

 

Once we have the CPU usage data, we can calculate to see whether the current value hit the threshold, if so, we can call management API to change always ready instance count (Web Apps - Update Configuration - REST API (Azure App Service) | Microsoft Learn).

 

 

 

Implementation Logic

 

1. Retrieve CPU usage via API for past 2 minutes and calculate average

 

2. Retrieve current Logic App backend instance count and set target instance count as current

 

3. Validate when average CPU usage hit scale in/out threshold (>50% or <10%)

 

  • If larger than scale out threshold, add 1 instance in target instance count if not hit maximum (20) instance count
  • If less than scale in threshold, remove 1 instance in target instance count if not hit minimum (1) instance count

 

4. Compare current and target value, if it is different, then send request to change always ready instance(s).

 

 

 

Sample Template

 

Demo can be found in Drac-Zhang/Rule_Based_Scaling_Template (github.com) which implemented the scaling feature based on CPU usage of past 2 minutes.

 

Meanwhile, for the Logic App Consumption, we need to enable Managed Identity, assign "Reader" and "Logic App Standard Contributor" role on resource group level for MI.

 

 

 

Known Issues

 

1. Since it is monitoring the CPU/memory usage on ASP level, so for the ASP, it only can have one Logic App, but this can be workaround via change metrics call to Logic App specific CPU/memory usage.

 

2. The Logic App Standard configuration API changes always ready instance, the maximum value is 20 as per current WS plan.

 

3. We have around 1 minute latency for retrieving metrics due to ingestion delay.

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...