Runbook

Azure Web App Performance Downtime or Slowness due to High Traffic

Back to Runbooks

Overview

This incident type refers to situations where an Azure web app experiences slow performance or downtime due to increased traffic. When the traffic to a web app increases, it can overload the server, causing it to respond slowly or even crash. This can lead to downtime, which can affect the user experience and impact the business. To resolve this issue, the web app can be scaled vertically (scale up/down) or horizontally (scale out/in) based on traffic patterns. Auto-scaling rules can also be configured to handle traffic fluctuations automatically.

Parameters

1export WEB_APP_NAME="PLACEHOLDER"
2
3export RESOURCE_GROUP_NAME="PLACEHOLDER"
4
5export APP_SERVICE_PLAN_ID="PLACEHOLDER"
6
7export APP_SERVICE_PLAN_NAME="PLACEHOLDER"
8
9export AUTOSCALE_SETTING_NAME="PLACEHOLDER"
10
11export NEW_INSTANCE_SKU="PLACEHOLDER"
12
13export MAX_INSTANCES="PLACEHOLDER"
14
15export MIN_INSTANCES="PLACEHOLDER"

Debug

Check the current status of the web app:

az webapp show --name ${WEB_APP_NAME} --resource-group ${RESOURCE_GROUP_NAME} --query "state"

Check the logs of the web app to identify any errors or performance issues:

az webapp log tail --name ${WEB_APP_NAME} --resource-group ${RESOURCE_GROUP_NAME}

Check the current resource usage of the web app:

az monitor metrics list --resource ${APP_SERVICE_PLAN_ID} --metric "CpuPercentage" "MemoryPercentage" --interval PT1H

Check the current number of instances of the web app:

az appservice plan show --name ${APP_SERVICE_PLAN_NAME} --resource-group ${RESOURCE_GROUP_NAME} --query "sku.capacity"

Check the current auto-scaling rules of the web app:

az monitor autoscale show --name ${AUTOSCALE_SETTING_NAME} --resource-group ${RESOURCE_GROUP_NAME}

Repair

Scale the web app vertically (scale up/down) to increase its capacity. This involves adding more resources such as RAM, CPU, and storage to the server.

1#!/bin/bash
2
3
4
5# Set the App Service Plan name
6
7APP_SERVICE_PLAN_NAME=${APP_SERVICE_PLAN_NAME}
8
9
10
11# Set the Azure resource group name
12
13RESOURCE_GROUP=${RESOURCE_GROUP_NAME}
14
15
16
17# Set the new instance size for the web app
18
19NEW_INSTANCE_SKU=${NEW_INSTANCE_SKU}
20
21
22
23# Scale the web app vertically
24
25az appservice plan update --name $APP_SERVICE_PLAN_NAME --resource-group $RESOURCE_GROUP --sku $NEW_INSTANCE_SKU

Scale the web app horizontally

1#!/bin/bash
2
3
4
5# Define variables
6
7RESOURCE_GROUP=${RESOURCE_GROUP_NAME}
8
9PLAN=${APP_SERVICE_PLAN_NAME}
10
11COUNT=${MAX_INSTANCES}
12
13
14
15# Scale the web app horizontally
16
17az appservice plan update --number-of-workers $COUNT --name $APP_SERVICE_PLAN_NAME --resource-group $RESOURCE_GROUP

Configure auto-scaling rules to handle traffic fluctuations automatically. This ensures that the web app can handle increased traffic without manually scaling up or down.

1# Define variables
2
3RESOURCE_GROUP=${RESOURCE_GROUP}
4
5APP_SERVICE_PLAN_ID=${APP_SERVICE_PLAN_ID}
6
7AUTOSCALE_SETTING_NAME=${AUTOSCALE_SETTING_NAME}
8
9MIN_INSTANCES=${MIN_INSTANCES}
10
11MAX_INSTANCES=${MAX_INSTANCES}
12
13
14
15# Configure auto-scaling settings
16
17az monitor autoscale create \
18
19 --resource-group $RESOURCE_GROUP \
20
21 --resource-id $APP_SERVICE_PLAN_ID \
22
23 --name $AUTOSCALE_SETTING_NAME \
24
25 --min-count $MIN_INSTANCES \
26
27 --max-count $MAX_INSTANCES \
28
29 --count 1
30
31
32
33# Create auto-scaling scale out rule
34
35az monitor autoscale rule create \
36
37 --resource-group $RESOURCE_GROUP \
38
39 --autoscale-name $AUTOSCALE_SETTING_NAME \
40
41 --scale out 1 \
42
43 --condition "Percentage CPU > 75 avg 5m"
44
45
46
47# Create auto-scaling scale in rule
48
49az monitor autoscale rule create \
50
51 --resource-group $RESOURCE_GROUP \
52
53 --autoscale-name $AUTOSCALE_SETTING_NAME \
54
55 --scale in 1 \
56
57 --condition "Percentage CPU < 25 avg 5m"

Learn more

Related Runbooks

Check out these related runbooks to help you debug and resolve similar issues.