Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
You can implement autoscaling in container apps that use the Durable Task Scheduler. Autoscaling maintains the reliability and scalability of long-running workflows by adapting to changing demands without manual intervention.
Control autoscaling by setting the range of application replicas deployed in response to an orchestration, activity, or entity being triggered. The scaler dynamically adjusts the number of container app replicas within that range, allowing your solution to handle spikes in the workload and prevent resource exhaustion.
Note
Autoscaling is supported for apps built using the Durable Task SDKs and hosted in Azure Container Apps.
Configure the autoscaler
You can set the autoscaler configuration via the Azure portal, a Bicep template, and the Azure CLI.
Field | Description | Example |
---|---|---|
Min replicas | Minimum number of replicas allowed for the container revision at any given time. | 1 |
Max replicas | Maximum number of replicas allowed for the container revision at any given time. | 10 |
endpoint | The Durable Task Scheduler endpoint that the scaler connects to. | https://dts-ID.centralus.durabletask.io |
maxConcurrentWorkItemsCount | The maximum concurrent work items dispatched as an event to your compute, such as telling your compute to run an orchestration. | 1 |
taskhubName | The name of the task hub connected to the scheduler. | taskhub-ID |
workItemType | The work item type that is being dispatched. Options include Orchestration, Activity, or Entity. | Orchestration |
Managed identity | The user assigned or system assigned managed identity linked to the scheduler and task hub resource. Ensure the Authenticate with a Managed Identity checkbox is selected. | [email protected] |
Experiment with the sample
In the Autoscaling in Azure Container Apps sample, you use the Azure Developer CLI to implement autoscaling for a container app built with the .NET Durable Task SDK and hosted in Azure Container Apps. The sample showcases an orchestration using the function chaining pattern.
Note
Although this sample uses the Durable Task .NET SDK, autoscaling is language-agnostic.
Prerequisites
- .NET 8 SDK or later
- Docker (for building the image)
- Azure Developer CLI
Set up your environment
Clone the
Azure-Samples/Durable-Task-Scheduler
directory.git clone https://github.com/Azure-Samples/Durable-Task-Scheduler.git
Authenticate with Azure using the Azure Developer CLI.
azd auth login
Deploy the solution using Azure Developer CLI
Navigate into the
AutoscalingInACA
sample directory.cd /path/to/Durable-Task-Scheduler/samples/scenarios/AutoscalingInACA
Provision resources and deploy the application:
azd up
When prompted in the terminal, provide the following parameters.
Parameter Description Environment Name Prefix for the resource group created to hold all Azure resources. Azure Location The Azure location for your resources. Azure Subscription The Azure subscription for your resources. 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 howazd up
:- Creates and configures all necessary Azure resources via the provided Bicep files in the
./infra
directory usingazd provision
. Once provisioned by Azure Developer CLI, you can access these resources via the Azure portal. The files that provision the Azure resources include:main.parameters.json
main.bicep
- An
app
resources directory organized by functionality - A
core
reference library that contains the Bicep modules used by theazd
template
- Deploys the code using
azd deploy
Expected output
Packaging services (azd package) (✓) Done: Packaging service client - Image Hash: {IMAGE_HASH} - Target Image: {TARGET_IMAGE} (✓) Done: Packaging service worker - Image Hash: {IMAGE_HASH} - Target Image: {TARGET_IMAGE} Provisioning Azure resources (azd provision) Provisioning Azure resources can take some time. Subscription: SUBSCRIPTION_NAME (SUBSCRIPTION_ID) Location: West US 2 You can view detailed progress in the Azure Portal: https://portal.azure.com/#view/HubsExtension/DeploymentDetailsBlade/~/overview/id/%2Fsubscriptions%SUBSCRIPTION_ID%2Fproviders%2FMicrosoft.Resources%2Fdeployments%2FCONTAINER_APP_ENVIRONMENT (✓) Done: Resource group: GENERATED_RESOURCE_GROUP (1.385s) (✓) Done: Virtual Network: VNET_ID (862ms) (✓) Done: Container Apps Environment: GENERATED_CONTAINER_APP_ENVIRONMENT (54.125s) (✓) Done: Container Registry: GENERATED_REGISTRY (1m27.747s) (✓) Done: Container App: SAMPLE_CLIENT_APP (21.39s) (✓) Done: Container App: SAMPLE_WORKER_APP (24.136s) Deploying services (azd deploy) (✓) Done: Deploying service client - Endpoint: https://SAMPLE_CLIENT_APP.westus2.azurecontainerapps.io/ (✓) Done: Deploying service worker - Endpoint: https://SAMPLE_WORKER_APP.westus2.azurecontainerapps.io/ SUCCESS: Your up workflow to provision and deploy to Azure completed in 10 minutes 34 seconds.
- Creates and configures all necessary Azure resources via the provided Bicep files in the
Confirm successful deployment
In the Azure portal, verify the orchestrations are running successfully.
Copy the resource group name from the terminal output.
Sign in to the Azure portal and search for that resource group name.
From the resource group overview page, click on the client container app resource.
Select Monitoring > Log stream.
Confirm the client container is logging the function chaining tasks.
Navigate back to the resource group page to select the
worker
container.Select Monitoring > Log stream.
Confirm the worker container is logging the function chaining tasks.
Understanding the custom scaler
This sample includes an azure.yaml
configuration file. When you ran azd up
, you deployed the entire sample solution to Azure, including a custom scaler for your container apps that automatically scales based on the Durable Task Scheduler's workload.
The custom scaler:
- Monitors the number of pending orchestrations in the task hub.
- Scales the number of worker replicas up with increased workload.
- Scales back down when the load decreases.
- Provides efficient resource utilization by matching capacity to demand.
Confirm the scaler is configured
Verify the autoscaling is functioning correctly in the deployed solution.
In the Azure portal, navigate to your worker app.
From the left side menu, click Application > Revisions and replicas.
Click the Replicas tab to verify your application is scaling out.
From the left side menu, click Application > Scale.
Click the scale name to view the scaler settings.
Next steps
Currently, autoscaling container apps using Durable Functions for Durable Task Scheduler isn't available. In the meantime, try autoscaling container apps using the Microsoft SQL (MSSQL) backend.