How to enable multi-instances of duralbe function app run in parallel
Hi,
I have an Azure durable function app in a container. When I create it using az CLI with argument "--plan", it works as I expect (multiple instances can run in parallel if I concurrently call my function mutliple times), but when I create it using az CLI with argument "--environment" and "--workload-profile-name", only ONE instance can run even if I call the function multiple times concurrently. I want to know how to enable multiple instances to run in paraellel when I create the durable function app with argument "--environment" and "--workload-profile-name".
(Due to the high workload, multiple instances are required to run concurrently. If i create my function app with argument "--plan", I need to pay for ONE instance even if I don't call my function. That is the reason I want to create my function app with argument "--environment" and "--workload-profile-name")
Thank you very much!
Azure Functions
-
Shireesha Eeraboina (Quadrant Resource LLC) 655 Reputation points • Microsoft Vendor
2025-01-02T05:51:23.3533333+00:00 Hi @Juntang Dai (Centific Technologies Inc) ,
Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.
To address your issue where only a single instance of your Azure Durable Function is running concurrently when using the --environment and --workload-profile-name arguments with the Azure CLI, you are encountering a difference in how the function app is being provisioned and scaled.
- First you need to make sure that the app is configured to allow scaling beyond one instance. You can set the scaling rules using the Azure CLI, ARM templates, or the Azure portal.
- Then ensure that your function app is on a Premium plan or Elastic Premium plan, which supports auto-scaling and running multiple instances. When using a Premium or Isolated environment, this configuration allows multiple instances to scale up once the function app plan is set to a Premium or Isolated plan, enable autoscaling based on demand and you can do this through the Azure portal by navigating to your function app, then to the Scale-out (App Service Plan) section. There you can set the scale to allow the app to scale based on request load.
- After confirming your scaling settings are correct, ensure that your Azure Durable Function is deployed correctly. The app should now be able to scale out to multiple instances based on load once your app is set up, you can monitor scaling and performance using Azure Application Insights or through the Azure portal to verify that multiple instances are indeed running in parallel and scaling as needed.
Also refer the below attached document regarding the concurrency
Concurrency in Azure Functions | Microsoft Learn
If you have any further queries, please feel free to reach out to us.
Thank you.
-
Juntang Dai (Centific Technologies Inc) 0 Reputation points • Microsoft Vendor
2025-01-02T07:19:58.3566667+00:00 Hi Shireesha,
Thank a lot for your detail answer. I did what you wrote before I ask this question here.Unfortuanately, your answer did not focus on my question.
Just as what I have said in my question, I don't want to pay for ONE instance when I do not call my function. If I use a plan (Premium plan or Elastic Premium plan) to run my durable function app, I need to pay ONE instance during the period I do not call my function. I want my function is scaled up to ZERO instance and can automatically be scaled up to "n" instance based on workload.
Thank you very much, have a great day!
-
Juntang Dai (Centific Technologies Inc) 0 Reputation points • Microsoft Vendor
2025-01-02T07:35:32.14+00:00 Hi Shireesha,
Thanks a lot for your detail answer. Unfortunately, it seems like you did not focus on my question. I did what you said your answering before I ask my question here.
If I use plan (Premium plan or Elastic Premium plan) to run my function, then I need to pay for ONE instance during the period I do not call my function.
Thank you very much!
-
Shireesha Eeraboina (Quadrant Resource LLC) 655 Reputation points • Microsoft Vendor
2025-01-02T09:43:32.6866667+00:00 Hi @Juntang Dai (Centific Technologies Inc) ,
Sorry for the inconvenience happened now we got it that you're aiming to avoid paying for an instance when your function app is idle (i.e., when it's not being called), and you'd prefer it to scale to zero instances when idle, while still scaling up automatically to multiple instances based on the workload when calls are made.
If you want to avoid paying for idle capacity, the Consumption Plan will be best option because it scales down to zero instances when idle. However, make sure that there are limitations with Durable Functions on the Consumption Plan (e.g., execution duration limits and other constraints) also if your use case for Durable Functions doesn't need the advanced features of the Premium or Isolated plans (e.g., long-running workflows, custom scale settings, etc.), the Consumption Plan will meet your needs for cost efficiency.
Thankyou.
-
Juntang Dai (Centific Technologies Inc) 0 Reputation points • Microsoft Vendor
2025-01-03T06:57:36.67+00:00 Hi Shireesha,
Thank you very much for your advice to use Consumption Plan.
In order to use Consumption Plan, I tried following az CLI to create my function app:
az functionapp create --name func-couponchecker --storage-account couponchecker --consumption-plan-location westus2 --resource-group CouponIntelligence --functions-version 4 --runtime python --os-type Linux --image couponchecker.azurecr.io/edgeimage:v1.0.0 --assign-identity
But the function app can not be visited. From Azure portal, I can not see the function list even if clicked the refresh button. I am not sure if the cmd above is correct.
I have used following az CLI to create my function app using Premium Plan:
az functionapp create --name func-couponchecker --storage-account couponchecker --resource-group CouponIntelligence --functions-version 4 --runtime python --image couponchecker.azurecr.io/edgeimage:v1.0.0 --assign-identity --plan couponchecker-premium-planThe function app created by above cmd works. Following is the what I have seen from portal:
Could you please see my command to create function app using Consumption Plan and tell me if there are any errors in the command?
Thank you very much!
-
Shireesha Eeraboina (Quadrant Resource LLC) 655 Reputation points • Microsoft Vendor
2025-01-03T09:47:00.9933333+00:00 Hi @Juntang Dai (Centific Technologies Inc) ,
It looks like the main issue here is that the Consumption Plan has some limitations and restrictions compared to the Premium Plan, and it might not fully support all the features you're trying to use in the Azure CLI command.
You are trying to use a custom Docker image (couponchecker.azurecr.io/edgeimage:v1.0.0) with the Consumption Plan, but this is not supported on Consumption Plan because it requires a Premium Plan or Dedicated Plan for running custom containers. Whereas the Premium Plan supports both custom images and more advanced features, which is why your second command works when you use the --plan couponchecker-premium-plan
Updated Command for Consumption Plan (without custom Docker image)
az functionapp create \ --name func-couponchecker \ --storage-account couponchecker \ --consumption-plan-location westus2 \ --resource-group CouponIntelligence \ --functions-version 4 \ --runtime python \ --os-type Linux \ --assign-identity
The above command removes the --image option and uses the default Python runtime on the Consumption Plan. The function app should now be created and be accessible.
I hope the above provided information might help you, if you have any further queries, please feel free to reach out to us.
Thank you.
-
Juntang Dai (Centific Technologies Inc) 0 Reputation points • Microsoft Vendor
2025-01-06T02:51:25.76+00:00 Hi Shireesha,
I can not remove --image when creating my Function App. My function needs to run Microsoft Edge and the driver of Microsoft Edge. And Windows operation system can not provide suitable Edge and driver, so we need to install them in docker image.
I am not sure if we can install the sutable version of Edge's driver exe file in windows.
Thanks a lot!
-
Juntang Dai (Centific Technologies Inc) 0 Reputation points • Microsoft Vendor
2025-01-06T09:09:14.55+00:00 Hi Shireesha,
If we can not install the sutable version of Edge's driver exe file in windows host of Azure Durable Function App, we need to build our Durable Function App in docker image.
From above document of Function App, we can see only Premimum plan, Dedicated plan(App service) and Container App are in the range of our options.
From above document, we can see both Premimum plan and App Service(Dedicated plan) have the feature "Minimum of 1 instance required", this is not cost efficient when our function app is idle, so we can only choice the plan "Container App".
In my orignal question I mentioned that we have created our function app with argument "--environment" and "--workload-profile-name" (this is the same as selecting "Container Apps Environment to create the function app"), but the problem is that only ONE instance can run even if I call the function multiple times concurrently.
Hope my explanation above has clarified my question to you.
Thank you very much!
-
Shireesha Eeraboina (Quadrant Resource LLC) 655 Reputation points • Microsoft Vendor
2025-01-06T10:23:02.1266667+00:00 Hi @Juntang Dai (Centific Technologies Inc) ,
From the details that you have shared Microsoft Edge and its driver to be installed in a Docker container, and you need to run the function with a custom Docker image, let's focus on the Premium Plan or Dedicated Plan as these are the only two plans that support custom Docker images, including running Microsoft Edge with the appropriate driver.
In Azure Container Apps, scaling is managed by CPU and memory settings. If you only have one container instance running, even though you're calling the function multiple times, Azure may not automatically scale out to multiple instances to handle concurrent requests to enable scaling and allow multiple instances of your container to run in parallel, you'll need to:
- Set up autoscaling for the Container App and adjust the scaling configuration to allow scaling based on requests or resource utilization.
Also let me provide you with some specific guidance, both for the Premium Plan and addressing your concerns about the Windows environment and the Edge driver.
As from the details I can understand that you are using a custom Docker image with the Microsoft Edge browser and Edge WebDriver, you'll need to use the Premium Plan as the Consumption Plan cannot support custom images. Here’s the correct approach for creating the Function App with the Premium Plan.
Since you're using Linux for your function app and need to install Microsoft Edge and its WebDriver, you'll need to ensure that your Docker image is correctly set up for this.
Also, you mentioned concerns about installing the Edge driver on Windows. However, since you're running this in a Linux-based container, the Windows OS issue doesn’t apply here. The Linux environment in your container can fully support Microsoft Edge (for Linux) and its corresponding driver for Linux.
However, if you must use Windows-based containers, you will need to move to a Windows-based App Service Plan. But for most use cases, running a Linux-based container with Microsoft Edge should be sufficient.
I hope the above provided information is helpful to understand better and resolve your issue.
Thankyou.
-
Juntang Dai (Centific Technologies Inc) 0 Reputation points • Microsoft Vendor
2025-01-07T07:46:48.8133333+00:00 Hi Shireesha,
Thank you very much for your detail reply, especailly for your following advice:
"Set up autoscaling for the Container App and adjust the scaling configuration to allow scaling based on requests or resource utilization."
Below is the Container Apps Environment I used in my durable function app, and the value of --workload-profile-name is "Dedicated-D4", its min number of instance is 0, max is 20.
My host.json is below:
{ "version": "2.0", "concurrency": { "dynamicConcurrencyEnabled": true, "snapshotPersistenceEnabled": true }, "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } } }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[4.*, 5.0.0)" }, "functionTimeout": "10:00:00", "extensions": { "durableTask": { "maxConcurrentOrchestratorFunctions": 1, "maxConcurrentActivityFunctions": 1 } } }
I used above host.json in my durable function app. I am not sure if there is any wrong in it.
I really appreciate you if you can give me some advice in this host.json or about the workload profile "Dedicated-D4".
Thanks a lot!
-
Shireesha Eeraboina (Quadrant Resource LLC) 655 Reputation points • Microsoft Vendor
2025-01-07T12:11:57.6933333+00:00 Hi @Juntang Dai (Centific Technologies Inc) ,
Thanks for bringing your concerns to us as from the details the host.json configuration for the Durable Function app appears mostly correct but may need some adjustments to optimize performance in the Azure Container Apps environment, especially with the "Dedicated-D4" workload profile.
Firstly, the minInstances value of 0 might cause your app to scale down to zero, which could lead to orchestration or activity functions being paused or delayed. It’s recommended to set minInstances to a higher value (e.g., 1) to ensure that there are always some instances available to handle the workload, particularly for long-running orchestrations.
Secondly, your concurrency settings are configured to run only one orchestrator and one activity function at a time (maxConcurrentOrchestratorFunctions and maxConcurrentActivityFunctions are both set to 1). If your workload can handle parallelism, consider increasing these values to allow for better scalability and throughput. However, if your orchestrations require strict ordering, these settings are fine.
At last, make sure to monitor the performance of your application through Azure Monitor and Application Insights to ensure that the scaling behavior aligns with your workload, and adjust your auto-scaling rules accordingly.
Thankyou.
-
Juntang Dai (Centific Technologies Inc) 0 Reputation points • Microsoft Vendor
2025-01-08T03:05:43.17+00:00 Hi Shireesha,
I can not understand why you said below in this thread:
"It’s recommended to set minInstances to a higher value (e.g., 1) to ensure that there are always some instances available to handle the workload, particularly for long-running orchestrations."
Please read my orignal question, you will know I don't want to pay for ONE instance during the period when I do NOT call my durable function, so I set the min number of instances to zero, but the problem is that only one instance runs when I call my durable function app multiple times in parellel.
I guess you have understand my problem as you said following in the your previous comment:
"Set up autoscaling for the Container App and adjust the scaling configuration to allow scaling based on requests or resource utilization."But you did not tell me "how to" in detail.
I used host.json and the configuration of "Dedicated-D4" workload profile I mentioned in my previous comment before I asked my question. Could you please tell me how to fix the problem?
Thank you very much!
-
Shireesha Eeraboina (Quadrant Resource LLC) 655 Reputation points • Microsoft Vendor
2025-01-08T09:47:08.5466667+00:00 Hi @Juntang Dai (Centific Technologies Inc) ,
Here setting minInstances to 0 means your app will scale down to zero when not in use, which saves your cost.However, only one instance running for parallel calls might happen if autoscaling or concurrency is misconfigured so for this you need to configure autoscaling for Azure Container Apps to scale based on request load, and adjust concurrency settings in host.json to allow parallel execution of multiple function instances.
Below are the steps to adjust your Azure Container Apps autoscaling settings to scale out based on load (requests).
Go to the Azure Portal and open the Container App that hosts your Durable Function and in the Container Apps environment, go to Scale under the Settings section and ensure that the scaling is set to trigger based on CPU or Request Count, depending on your needs. For example, if you want the app to scale based on the number of function invocations, use Request Count as the scaling metric.
In the Scaling settings, you need to adjust the Max Instances (already set to 20 in your case, which is fine) and set the Min Instances to 0, which you already have, to avoid paying for idle resources also configure the Scaling rules to trigger scaling up based on metrics. This way, when the demand increases Azure Container Apps will scale out automatically to handle more concurrent executions.
Also to Adjust host.json to Allow Parallel Execution you have to Increase the maxConcurrentOrchestratorFunctions and maxConcurrentActivityFunctions to a higher value to allow more parallel executions also if your orchestration and activities can run concurrently, you can safely increase these limits.
Thankyou.
-
Juntang Dai (Centific Technologies Inc) 0 Reputation points • Microsoft Vendor
2025-01-09T07:30:26.7266667+00:00 Hi Shireesha,
Thank you very much for your suggestion. But I can not find the "GUI" you mentioned. In the portal of my Container Apps environment, I can not find Scale under the Settings section. And In the portal of my Durable Function App, I find a similar GUI "Scale rule settings" in the "Configuration" part under "Settings" section.
Following is the process I create my Azure Durable Function App "func-couponchecker-1" and corresponding GUIs:
- create container app environment "DjtContainerappEnvironment": az containerapp env create --name DjtContainerappEnvironment --enable-workload-profiles --resource-group CouponIntelligence --location eastus
- go to Azure portal, select "Workload profiles" under "Settings" of "DjtContainerappEnvironment", and add workload profile "Dedicated-D4"
below is the portal of DjtContainerappEnvironment, there is no Scale under Settings:
- create Azure durable function app "func-couponchecker-1": az functionapp create --name func-couponchecker-1 --storage-account couponchecker1 --environment DjtContainerappEnvironment --workload-profile-name "Dedicated-D4" --resource-group CouponIntelligence --functions-version 4 --runtime python --image couponchecker.azurecr.io/edgeimage:v1.0.0 --assign-identity
- go to Azure portal, select "Workload profiles" under "Settings" of "DjtContainerappEnvironment", and add workload profile "Dedicated-D4"
Below is the Overview section of "func-couponchecker-1":
below is "Configuration" under "Settings" section:
In you comment, you said: "in the Container Apps environment, go to Scale under the Settings section and ensure that the scaling is set to trigger based on CPU or Request Count",
I am not sure if the relating GUI is just what show in your comment. If it is not in your comment, please share me with it.
If you can share me with the complete screenshot, not just the part of screen, that is good for me to understand better.
Thanks a lot!
- create container app environment "DjtContainerappEnvironment": az containerapp env create --name DjtContainerappEnvironment --enable-workload-profiles --resource-group CouponIntelligence --location eastus
-
Shireesha Eeraboina (Quadrant Resource LLC) 655 Reputation points • Microsoft Vendor
2025-01-10T06:27:12.9633333+00:00 Hi @Juntang Dai (Centific Technologies Inc) ,
Apologies for the delayed response.
Thank you for bringing your concerns to our attention. The UI belongs to the CONTAINER APP, not the CONTAINER APP ENVIRONMENT. Please navigate to the CONTAINER APP in the portal, click on scale, and specify your limits there. For your reference, I have attached a screenshot below.
Thank you.
-
Juntang Dai (Centific Technologies Inc) 0 Reputation points • Microsoft Vendor
2025-01-10T08:01:35.19+00:00 Hi Shireesha,
We did not create CONTAINER APP and we do not use container app in our Azure durable function app. What we created is CONTAINER APP ENVIRONMENT.In docuemnt about "Create your first containerized functions on Azure Container Apps" ( https://learn.microsoft.com/en-us/azure/azure-functions/functions-deploy-container-apps?tabs=acr%2Cbash&pivots=programming-language-python ), you can find section "Create Azure Container App environment with workload profiles enabled."
Thanks a lot!
Sign in to comment