This sample demonstrates how to implement autoscaling with the Azure Durable Task Scheduler using the .NET SDK in Azure Container Apps. The pattern showcases an orchestration workflow that can benefit from dynamically scaling worker instances based on load.
In this sample:
- The orchestrator calls the
SayHelloActivitywhich greets the user with their name - The result is passed to the
ProcessGreetingActivitywhich adds to the greeting - The result is then passed to the
FinalizeResponseActivitywhich completes the greeting - The final greeting message is returned to the client
This pattern is useful for:
- Creating scalable workflows that can handle varying loads
- Efficiently utilizing resources by scaling container instances up or down
- Building resilient systems that can respond to increased demand
- Implementing cost-effective processing for variable workloads
- .NET 8 SDK or later
- Docker (for building the image)
- Azure CLI (if using a deployed Durable Task Scheduler)
This sample includes an azure.yaml configuration file that allows you to deploy the entire solution to Azure using Azure Developer CLI (AZD). This deployment includes a custom KEDA scaler for your Container Apps that automatically scales based on the Durable Task Scheduler's workload.
- Install Azure Developer CLI
- Authenticate with Azure:
azd auth login
-
Navigate to the AutoscalingInACA sample directory:
cd /path/to/Durable-Task-Scheduler/samples/scenarios/AutoscalingInACA -
Initialize the Azure Developer CLI project (only needed the first time):
azd init
This step prepares the environment for deployment and creates necessary configuration files.
-
Provision resources and deploy the application:
azd up
This command will:
- Provision Azure resources (including Azure Container Apps and Durable Task Scheduler)
- Build and deploy both the Client and Worker components
- Set up the custom KEDA scaler for the Worker container app
- Configure the necessary connections between components
-
Monitor your orchestrations using the Azure Portal by navigating to your Durable Task Scheduler resource dashboard, or view the container app logs using the Azure Portal:
- Navigate to the Azure Portal and find your resource group
- Go to each Container App (Worker and Client) that was deployed
- In the left sidebar, select "Log stream" under the "Monitoring" section
- Observe the logs in real-time to confirm that:
- Client app is submitting orchestration requests
- Worker app is processing the orchestrations through each activity
- You should see logs showing the completion of
SayHelloActivity,ProcessGreetingActivity, andFinalizeResponseActivity
- This confirms that your orchestrations are being processed correctly
This sample implements autoscaling using KEDA (Kubernetes Event-Driven Autoscaling) with a custom scaler for Azure Container Apps. The scaler monitors the Durable Task Scheduler workload and automatically adjusts the number of worker instances based on the current orchestration load.
The custom scaler:
- Monitors the number of pending orchestrations in the task hub
- Scales the number of worker replicas up when there is increased workload
- Scales back down when the load decreases
- Provides efficient resource utilization by matching capacity to demand
To verify that the autoscaling is functioning correctly:
- Navigate to the Azure Portal and find your resource group
- Go to the Worker Container App that was deployed
- Select the "Revision management" section in the sidebar
- Observe the "Replica count" as it changes based on load
- You can also check the "Scale" tab to see the KEDA scaler configuration
To test the autoscaling:
- Run the client with a large number of orchestration requests
# You can modify the Client/Program.cs to schedule more orchestrations # Then run from your AZD environment: azd deploy --service client
- Monitor the replica count in the Azure Portal
- You should see the number of replicas increase as the workload grows
- Once the orchestrations complete, the replicas should scale back down after a cooldown period
You can also view the Application Insights logs to see the scaling events and performance metrics for your Container Apps.