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

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

by info.odysseyx@gmail.com
0 comment 4 views


background

As we know, Logic App Standard with WS ASP follows target-based scaling like Azure Function EP plan, which is mainly determined by job queue length rather than CPU/memory usage.

However, in some situations, high CPU/memory usage can occur without a long work queue, resulting in the scaling controller not being able to vote to increase backend instances as expected.

So in this blog, I will show you how to “simulate” rule-based scaling capability for Logic App Standard using WS Plan, a Logic App Standard running on ASE using Logic App Consumption (also possible with Azure products, e.g. Azure Function).

machine

Since we need to scale based on CPU/memory usage (and possibly other metrics), the first problem to solve is getting the metrics data:

2024-08-13_13h13_31.png

For example, if you want to know the average CPU usage, you can go to the CPU Percentage page and capture a HAR trace, and you will see that the APIs used in the portal are:

https://management.azure.com/subscriptions/[SubscriptionID]/Resource Group/[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&validateddimensions=false&api-version=2019-07-01

Once you have CPU usage data, you can calculate whether the current value has reached a threshold. If it has, you can change the number of always-ready instances by calling the management API.Web App – Update Configuration – REST API (Azure App Service) | Microsoft Learn).

Implementation logic

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

2. Retrieve the current number of Logic App backend instances and set the target number of instances to current.

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

  • If it is greater than the expansion threshold and the maximum number of instances (20) is not reached, add 1 instance to the target number of instances.
  • If the minimum number of instances (1) is less than the threshold, remove one instance from the target number of instances.

4. Compare the current value with the target value and if they are different, always send a request to change the prepared instance.

Sample Template

A demo can be found here: Drac-Zhang/Rule-based scaling template (github.com) Implemented scaling feature based on CPU usage over the last 2 minutes.

Meanwhile, for Logic App Consumption, you need to enable managed identity and assign “Reader” and “Logic App Standard Contributor” roles at the resource group level for MI.

Known Issues

1. Since we are monitoring CPU/Memory usage at ASP level, we can have only one Logic App for ASP, but we can solve this by calling change metrics for CPU/Memory usage per Logic App.

2. Logic App Standard configuration API always prepares an instance. Current WS plan has a maximum of 20.

3. Due to collection delay, there is a delay of about 1 minute in retrieving metrics.





Source link

You may also like

Leave a Comment

Our Company

Welcome to OdysseyX, your one-stop destination for the latest news and opportunities across various domains.

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

Laest News

@2024 – All Right Reserved. Designed and Developed by OdysseyX