When managing multiple apps on Azure App Service, scalability is crucial, especially for high-density hosting scenarios. Typically, when apps are hosted in an Azure App Service plan, the entire plan is scaled out. This means that if you scale an App Service plan to 10 instances, each instance will run all the apps in the plan. This setup can lead to inefficient resource utilization, particularly if not all apps have high demand.
For example, if you have a 10-instance scaled-out plan with 10 apps, each app service will run across all instances:
- Server 1 runs all 10 apps
- Server 2 runs all 10 apps
- And so on…
In this configuration, the demand for each app might be different. Let's assume the following usage pattern across your 10 apps:
- Apps 1-5 handle 20,000 requests per day.
- Apps 5-6 handle 5,000 requests per day.
- Apps 7-10 handle less than 500 requests per day.
If all apps are running on all 10 nodes, this leads to an inefficient distribution of resources, particularly for low-usage apps. Per-app scaling offers a solution to optimize this setup.
Optimizing Resource Allocation with Per-App Scaling
Per-app scaling allows you to scale apps independently within the same App Service plan. This means instead of having all apps run on all 10 instances, you can distribute them according to their demand:
- High-demand apps (Apps 1-5) can run across all 10 nodes.
- Medium-demand apps (Apps 5-6) can run across 5 nodes.
- Low-demand apps (Apps 7-10) can run across 2 nodes.
This way, the apps utilize only the resources they need, improving performance and cost-efficiency.
Enabling Per-App Scaling
Per-app scaling is available in the Standard, Premium, Premium V2, Premium V3, and Isolated pricing tiers of Azure App Service. It must be enabled at the App Service plan level to allow scaling an app independently from the overall service plan.
To implement per-app scaling:
- Enable per-app scaling by configuring the App Service plan.
- Allocate instances to each app based on its demand.
You can update the configuration using Azure's REST API for App Service Plans:
{
"kind": "app",
"sku": {
"name": "P1v3",
"tier": "PremiumV3",
"size": "P1v3",
"family": "Pv3",
"capacity": 1
},
"location": "West US 2",
"properties": {
"perSiteScaling": true
}
}
This enables per-site scaling for the specified App Service plan.
Managing App Instances Using REST API
To manage and verify the number of worker nodes allocated to each app, use the Azure App Service REST APIs:
- Get current App Service plan settings:
- App Service Plans - Get - REST API.
- Create or update service plan settings (including per-app scaling):
- App Service Plans - Create Or Update - REST API.
To update the number of worker nodes for each app:
Web Apps - Get - REST API (Azure App Service) | Microsoft Learn -GET
Web Apps - Update - REST API (Azure App Service) | Microsoft Learn - Update
{
"properties": {
"siteConfig": {
"numberOfWorkers": 1
}
}
}
Verify the number of nodes in use by the app using this REST endpoint:
Web Apps - List Instance Identifiers - REST API.
Summary
Per-app scaling in Azure App Service enables you to optimize resource allocation and efficiency for high-density hosting scenarios. Instead of running all apps on every node, you can scale each app based on its actual demand, saving costs and improving performance. This feature is particularly beneficial for hosting multiple applications with varying levels of traffic on the same service plan.
By using Azure's REST APIs, you can easily manage and monitor the scaling of individual apps within the plan, ensuring they run on the optimal number of instances.
Source: https://learn.microsoft.com/en-us/azure/app-service/manage-scale-per-app
Comments