Skip to content

Commit 369d4f3

Browse files
committed
add to toc and add content for the autoscaling how-to
Signed-off-by: Hannah Hunter <[email protected]>
1 parent aa9f154 commit 369d4f3

File tree

7 files changed

+203
-20
lines changed

7 files changed

+203
-20
lines changed

articles/azure-functions/durable/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
href: ./durable-task-scheduler/durable-task-scheduler.md #placeholder
135135
- name: How-to guides
136136
items:
137+
- name: Autoscaling with the Durable Task SDKs in Azure Container Apps
138+
href: ./durable-task-scheduler/durable-task-scheduler-auto-scaling-aca.md
137139
- name: Run app on Azure Container Apps
138140
href: ./durable-task-scheduler/durable-task-scheduler.md #placeholder
139141
- name: Billing
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
---
2+
title: "Autoscaling in Azure Container Apps pattern for the Durable Task SDKs"
3+
description: Learn how to implement autoscaling with the Durable Task Scheduler using the Durable Task .NET SDK in Azure Container Apps.
4+
ms.subservice: durable-task-scheduler
5+
ms.topic: how-to
6+
ms.date: 05/01/2025
7+
---
8+
9+
# Autoscaling in Azure Container Apps pattern for the Durable Task SDKs
10+
11+
You can implement Kubernetes Event-Driven Autoscaling (KEDA) in container apps that use the Durable Task SDKs. Autoscaling maintains the reliability and scalability of long-running workflows by adapting to changing demands without manual intervention.
12+
13+
Control autoscaling by setting the range of application replicas deployed in response to an orchestration being triggered. The scaler dynamically adjusts the number of replicas within that range, allowing your solution to handle spikes in the workload and prevent resource exhaustion.
14+
15+
In this article, the [Autoscaling in Azure Container Apps sample]() demonstrates how to implement autoscaling with the Azure Durable Task Scheduler using the .NET SDK in Azure Container Apps. The function chaining application pattern showcases an orchestration workflow that benefits from dynamically scaling worker instances based on load.
16+
17+
> [!NOTE]
18+
> Although this sample uses the Durable Task .NET SDK, autoscaling is language-agnostic.
19+
20+
## Prerequisites
21+
22+
- [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) or later
23+
- [Docker](https://www.docker.com/products/docker-desktop/) (for building the image)
24+
- [Azure Developer CLI](/developer/azure-developer-cli/install-azd)
25+
26+
## Set up your environment
27+
28+
1. Clone the `Azure-Samples/Durable-Task-Scheduler` directory.
29+
30+
```bash
31+
git clone https://github.com/Azure-Samples/Durable-Task-Scheduler.git
32+
```
33+
34+
1. Authenticate with Azure using the Azure Developer CLI.
35+
36+
```azdeveloper
37+
azd auth login
38+
```
39+
40+
## Deploy the solution using Azure Developer CLI
41+
42+
1. Navigate into the `AutoscalingInACA` sample directory.
43+
44+
```azdeveloper
45+
cd /path/to/Durable-Task-Scheduler/samples/portable-sdks/dotnet/AutoscalingInACA
46+
```
47+
48+
1. Provision resources and deploy the application:
49+
50+
```azdeveloper
51+
azd up
52+
```
53+
54+
1. When prompted in the terminal, provide the following parameters.
55+
56+
| Parameter | Description |
57+
| --------- | ----------- |
58+
| Environment Name | Prefix for the resource group created to hold all Azure resources. |
59+
| Azure Location | The Azure location for your resources. |
60+
| Azure Subscription | The Azure subscription for your resources. |
61+
62+
This process may take some time to complete. As the `azd up` command completes, the CLI output displays two Azure portal links to monitor the deployment progress. The output also demonstrates how `azd up`:
63+
64+
- Creates and configures all necessary Azure resources via the provided Bicep files in the `./infra` directory using `azd provision`. Once provisioned by Azure Developer CLI, you can access these resources via the Azure portal. The files that provision the Azure resources include:
65+
- `main.parameters.json`
66+
- `main.bicep`
67+
- An `app` resources directory organized by functionality
68+
- A `core` reference library that contains the Bicep modules used by the `azd` template
69+
- Deploys the code using `azd deploy`
70+
71+
### Expected output
72+
73+
```azdeveloper
74+
Packaging services (azd package)
75+
76+
(✓) Done: Packaging service client
77+
- Image Hash: {IMAGE_HASH}
78+
- Target Image: {TARGET_IMAGE}
79+
80+
81+
(✓) Done: Packaging service worker
82+
- Image Hash: {IMAGE_HASH}
83+
- Target Image: {TARGET_IMAGE}
84+
85+
86+
Provisioning Azure resources (azd provision)
87+
Provisioning Azure resources can take some time.
88+
89+
Subscription: SUBSCRIPTION_NAME (SUBSCRIPTION_ID)
90+
Location: West US 2
91+
92+
You can view detailed progress in the Azure Portal:
93+
https://portal.azure.com/#view/HubsExtension/DeploymentDetailsBlade/~/overview/id/%2Fsubscriptions%SUBSCRIPTION_ID%2Fproviders%2FMicrosoft.Resources%2Fdeployments%2FCONTAINER_APP_ENVIRONMENT
94+
95+
(✓) Done: Resource group: GENERATED_RESOURCE_GROUP (1.385s)
96+
(✓) Done: Virtual Network: VNET_ID (862ms)
97+
(✓) Done: Container Apps Environment: GENERATED_CONTAINER_APP_ENVIRONMENT (54.125s)
98+
(✓) Done: Container Registry: GENERATED_REGISTRY (1m27.747s)
99+
(✓) Done: Container App: SAMPLE_CLIENT_APP (21.39s)
100+
(✓) Done: Container App: SAMPLE_WORKER_APP (24.136s)
101+
102+
Deploying services (azd deploy)
103+
104+
(✓) Done: Deploying service client
105+
- Endpoint: https://SAMPLE_CLIENT_APP.westus2.azurecontainerapps.io/
106+
107+
(✓) Done: Deploying service worker
108+
- Endpoint: https://SAMPLE_WORKER_APP.westus2.azurecontainerapps.io/
109+
110+
111+
SUCCESS: Your up workflow to provision and deploy to Azure completed in 10 minutes 34 seconds.
112+
```
113+
114+
## Confirm successful deployment
115+
116+
In the Azure portal, verify the orchestrations are running successfully.
117+
118+
1. Copy the resource group name from the terminal output.
119+
120+
1. Sign in to the [Azure portal](https://portal.azure.com) and search for that resource group name.
121+
122+
1. From the resource group overview page, click on the client container app resource.
123+
124+
1. Select **Monitoring** > **Log stream**.
125+
126+
1. Confirm the client container is logging the function chaining tasks.
127+
128+
:::image type="content" source="media/durable-task-scheduler-auto-scaling-aca/client-app-log-stream.png" alt-text="Screenshot of the client container's log stream in the Azure portal.":::
129+
130+
1. Navigate back to the resource group page to select the `worker` container.
131+
132+
1. Select **Monitoring** > **Log stream**.
133+
134+
1. Confirm the worker container is logging the function chaining tasks.
135+
136+
:::image type="content" source="media/durable-task-scheduler-auto-scaling-aca/worker-app-log-stream.png" alt-text="Screenshot of the worker container's log stream in the Azure portal.":::
137+
138+
## Understanding the custom scaler
139+
140+
This sample includes an `azure.yaml` configuration file. When you ran `azd up`, you deployed the entire sample solution to Azure, including a custom KEDA scaler for your container apps that automatically scales based on the Durable Task Scheduler's workload.
141+
142+
The custom scaler:
143+
144+
- Monitors the number of pending orchestrations in the task hub.
145+
- Scales the number of worker replicas up with increased workload.
146+
- Scales back down when the load decreases.
147+
- Provides efficient resource utilization by matching capacity to demand.
148+
149+
## Confirm the scaler is working
150+
151+
Verify the autoscaling is functioning correctly in the deployed solution.
152+
153+
1. In the Azure portal, navigate to your worker app.
154+
155+
1. From the left side menu, click **Application** > **Revisions and replicas**.
156+
157+
1. Click the **Replicas** tab to verify your application is scaling out.
158+
159+
1. From the left side menu, click **Application** > **Scale**.
160+
161+
1. Click the scale name to view the scaler settings.
162+
163+
### Test the scaler
164+
165+
You can test the scaler by running the client app with a large number of orchestration requests.
166+
167+
1. Open the client `Program.cs` and edit it to scheduler more orchestrations in your preferred code editor.
168+
169+
1. In the terminal, run the client using Azure Developer CLI.
170+
171+
```azdeveloper
172+
azd deploy --service client
173+
```
174+
175+
1. While the orchestrations are running, navigate to the client app in the Azure portal to monitor its replica count.
176+
177+
1. Once orchestrations complete, make sure the replicas scale back down after a cooldown period.
178+
179+
## Next steps
180+
Loading
Loading
Loading
Loading

articles/azure-functions/durable/durable-task-scheduler/quickstart-aca-azd-durable-task-sdk.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Quickstart: Configure Durable Task SDKs in your container app with Azure Functions Durable Task Scheduler (preview)"
33
description: Learn how to configure an existing container app for the Azure Functions Durable Task Scheduler using the Durable Task SDKs and deploy using Azure Developer CLI.
44
ms.subservice: durable-task-scheduler
5-
ms.topic: how-to
5+
ms.topic: quickstart
66
ms.date: 04/29/2025
77
zone_pivot_groups: df-languages
88
---
@@ -164,11 +164,12 @@ cd /samples/portable-sdks/java/FunctionChaining
164164
- Endpoint: https://SAMPLE_WORKER_APP.westus2.azurecontainerapps.io/
165165
166166
167-
SUCCESS: Your up workflow to provision and deploy to Azure completed in 10 minutes 34 seconds. ```
167+
SUCCESS: Your up workflow to provision and deploy to Azure completed in 10 minutes 34 seconds.
168+
```
168169

169170
## Confirm successful deployment
170171

171-
In the Azure portal, verify the client container app is publishing messages to the Azure Service Bus topic.
172+
In the Azure portal, verify the orchestrations are running successfully.
172173

173174
1. Copy the resource group name from the terminal output.
174175

@@ -186,7 +187,7 @@ In the Azure portal, verify the client container app is publishing messages to t
186187

187188
1. Select **Monitoring** > **Log stream**.
188189

189-
1. Confirm the client container is logging the function chaining tasks.
190+
1. Confirm the worker container is logging the function chaining tasks.
190191

191192
:::image type="content" source="media/quickstart-aca-azd-durable-task-sdk/worker-app-log-stream.png" alt-text="Screenshot of the worker container's log stream in the Azure portal.":::
192193

@@ -200,6 +201,22 @@ In the Azure portal, verify the client container app is publishing messages to t
200201

201202
::: zone pivot="csharp"
202203

204+
### Client Project
205+
206+
The Client project:
207+
208+
- Uses the same connection string logic as the worker
209+
- Schedules an orchestration instance with a name input
210+
- Waits for the orchestration to complete and displays the result
211+
- Uses WaitForInstanceCompletionAsync for efficient polling
212+
213+
```csharp
214+
var instance = await client.WaitForInstanceCompletionAsync(
215+
instanceId,
216+
getInputsAndOutputs: true,
217+
cts.Token);
218+
```
219+
203220
### Worker Project
204221

205222
The Worker project contains:
@@ -249,22 +266,6 @@ var host = builder.Build();
249266
await host.StartAsync();
250267
```
251268

252-
### Client Project
253-
254-
The Client project:
255-
256-
- Uses the same connection string logic as the worker
257-
- Schedules an orchestration instance with a name input
258-
- Waits for the orchestration to complete and displays the result
259-
- Uses WaitForInstanceCompletionAsync for efficient polling
260-
261-
```csharp
262-
var instance = await client.WaitForInstanceCompletionAsync(
263-
instanceId,
264-
getInputsAndOutputs: true,
265-
cts.Token);
266-
```
267-
268269
::: zone-end
269270

270271
::: zone pivot="python"

0 commit comments

Comments
 (0)