7

On auto scaling of Azure App Service, I only find the below.

Scale a web app in Azure App Service

This only allows for scaling to more or less instances. It does not allow for scaling to bigger and smaller instances.

I want to schedule an app service instance size between small, medium, and large on a schedule. Is there an API that will allow me to do this?

Thank you much.

Jacques Bosch
  • 2,165
  • 3
  • 25
  • 36

6 Answers6

5

Due to the lack of a simple solution, I created a one-click deploy to do what you're asking.

https://github.com/jraps20/jrap-AzureVerticalScaling

Overview

My approach uses Azure Automation Runbooks. Via the one-click deploy method you can get fully up and running in a few minutes. The two complementary runbooks (ScaleAppServicePlansUp and ScaleAppServicePlansDown) work together to store, read and modify whichever App Service Plans you choose. The primary target for these runbooks are non-prod environments.

The code is too long to include in this answer, unfortunately (so yes, this will mostly be a link-only answer).

Pseudo Code

Scale Down

Iterate across all Resource Groups (or pass in specific one)
Iterate across all App Service Plans (or pass in specific one)
Iterate across all App Services (identify Tier-specific settings)

During iteration, the current App Service Plan Service Tier is stored in Azure Automation Variables (3 distinct variables for each App Service Plan)

Within each App Service Plan, each App Service is iterated to identify tier-specific settings. Some of these settings include: AlwaysOn, Use32BitWorkerProcess, and ClientCertEnabled. All current settings are stored in Azure Automation Variables.

All App Service Plans are then scaled down to the FREE tier.

Scale Up

Iterate across all Resource Groups (or pass in specific one)
Iterate across all App Service Plans (or pass in specific one)
Iterate across all App Services (identify Tier-specific settings)

During iteration, the original App Service Plan Service Tier is retrieved from Azure Automation Variables (3 distinct variables for each App Service Plan)

Within each App Service Plan, each App Service is iterated and any previously stored tier-specific settings are retrieved.

All App Service Plans are then scaled up to their original tier.
All App Services with tier-specific settings are reapplied to their original values.

Additional Resources

Disclaimer

I became aware of Sam Spoerles technique after completing my work. The benefits of my approach over his are as follows:

  • One-click deployment to Azure
  • Generic or specific based on parameters
  • Uses updated Az modules instead of AzureRm modules
  • Relies on storage to retain the previous state, via Automation Variables
jrap
  • 335
  • 2
  • 11
  • I've just installed this and created up and down plans - when I run the down plan, the output all appears to be good - for my two app services, the log states "--- --- --- Finished converting 'myServerNameHere' App Service Plan to Free Tier"." But when I look in the "Scale up (App Service plan)" section of those 2 app services, the radio button is still marked next to the original paid-for service plan. Is that normal, that it doesn't update the App Service Plan section, or is something amiss? – Jess Feb 16 '23 at 19:05
  • 1
    Something is amiss. There must be a setting that is preventing the change. – jrap Feb 17 '23 at 20:15
  • In the logs, it shows that 'AlwaysOn' has been set to false - and I can see this has happened in the webapp configuration/general settings page. The log does not mention doing anything with 'Use32BitWorkerProcess' or 'ClientCertEnabled', so maybe these are the issue. I couldn't find any mention of 'Use32BitWorkerProcess' in the settings page - so perhaps I'm looking in the wrong screen? I found ClientCertEnabled and it is currently set to 'ignore' - the options are Require, Allow, Optional, Ignore - there is no 'off' or 'false' option, so maybe this has changed since you wrote the script? – Jess Feb 18 '23 at 09:27
  • I've just noticed that whilst it doesn't downgrade to the free tier with scale down, it has been successfully upgrading the tier version with scale up (i.e. it has scaled up from the existing tier I was on, basic, to the standard tier), actually increasing costs. – Jess Feb 20 '23 at 20:27
  • It has been a bit since I wrote the script and have not used it in a while. In the end though hit just recreates the manual changes you would make in order to reduce the tier. If you try to do it manually it may reveal what the issue is. – jrap Feb 21 '23 at 21:27
4

Unfortunately, there is no way to scale the Azure App Service instance size (i.e. the App Service Plan Pricing Tiers) on a schedule basis at this time.

As of now, Azure App Service can only support horizontal scaling (i.e. instance count scaling) on a schedule basis but not for the vertical scaling (i.e. instance size scaling).

Hope this helps!

juvchan
  • 6,113
  • 2
  • 22
  • 35
4

Actually you can scale up (vertically, i.e. change the service plan) as well as out (instance count) automatically.

The scale out option has been there forever and allows you to setup rules (e.g. CPU exceeds %, memory goes over threshold, etc.)

The scale up option requires using Azure Automation. It's fully documented here

Hope that helps!

Bil Simser
  • 1,713
  • 1
  • 19
  • 27
1

There is no easy way to do that.

However, if you're willing to write some code you could use the PowerShell api with Azure Automation to create this functionality for yourself.

You'd use the apis to check the metrics (like CPU) every X minutes, and if the CPU is higher than Y scale up to the next larger instance. If it's below your threshold, then scale down.

Zain Rizvi
  • 23,586
  • 22
  • 91
  • 133
  • Thank you. Do you know for a fact that those APIs would allow for scaling instance size up and down? – Jacques Bosch Dec 08 '15 at 06:01
  • @JacquesBosch: yes, they definitely support scaling instance size up and down. If I remember correctly, the size property is on the App Service Plan instead of the website, so that's where you want to look. – Zain Rizvi Dec 08 '15 at 18:50
  • Yes, I know the instance size is on the plan level. Thanks again. I'll take a look. – Jacques Bosch Dec 09 '15 at 05:17
1

Using powershell, you can switch the app service plan of a web app like this

PS C:\> $Resource = Get-AzureRmResource -ResourceType "microsoft.web/sites" -ResourceGroupName "ResourceGroup11" -ResourceName "ContosoSite" 
PS C:\> $Resource.Properties.ServerFarmId = "/subscriptions/{subscr_id}/resourceGroups/FriendsRGrp/provider
s/Microsoft.Web/serverfarms/FriendsPlan"
PS C:\> $Resource | Set-AzureRmResource -Force

Here the server farm id is nothing but the resource id of the service plan which you can get from the new portal, by looking at the properties of the plan.

You can have two service plans one with basic and another with standard. You can then upgrade to standard during weekdays and downgrade to basic on weekends using Azure Automation.

I understand that you're requirement is to change the existing plan itself and not to switch between plans. I'm thinking that it should be possible, although I haven't tried it myself. But if you go through the properties returned in the Resource.Properties of the returned Azure web app resource as above, you should be able to figure it out.

0

I think what you are looking for is to AutoScale an Azure WebApp on Schedule or CPU kind of metrices

1.Change your hosting plan to Standard, you can't setup auto-scaling below standard tier.

2.Use Azure Preview Portal at portal.azure.com.

3.Azure Preview Portal: The correct setting for this would be to use the “ CPU percentage”

4.Azure Portal you would set the Scale by Metrics from None to CPU

5.Set Instance count to between 1 and like 4 or 8, you can change it later, you can go upto 10.

For more details you can refer to this article http://blogs.msdn.com/b/devschool/archive/2015/05/24/azure-webjobs.aspx What this article doesn't discuss is scaling by schedule, which I think you can figure out once you get there. Make sure you use portal.azure.com

Brij Raj Singh - MSFT
  • 4,903
  • 7
  • 36
  • 55