Review and Step by step deployment of the New Auto Scale (Preview) feature of Azure Virtual Desktop
MS has given the Diwali Gift to the Azure Virtual Desktop admins by the introduction of GUI based auto scale scheduler for AVD. There are definetely smiles on the faces of the thousands of AVD admins, who have struggled a lot to manage the present Auto Scale Script.
There was a session on #MSignite 2021 for this, if you haven’t watched that yet, this will be a good article for you.
For almost last one and half year, the only way to setup the auto scaling with your Azure Virtual desktop is to use the Azure Automation based scaling tool. Some of the top notch SI’s like HCL, has developed their own devops automation in and around the native Azure Autoscaling tool for the easy deployment and use but that doesn’t completely rule out the complexities of the Azure Scaling Tool which uses of the combination of an Azure Automation account, a PowerShell runbook, a webhook, and the Azure Logic App to function. When the tool runs, Azure Logic App calls a webhook to start the Azure Automation runbook. The runbook then creates a job.
During peak usage time, the job checks the current number of sessions and the VM capacity of the current running session host for each host pool. It uses this information to calculate if the running session host VMs can support existing sessions based on the SessionThresholdPerCPU parameter defined for the CreateOrUpdateAzLogicApp.ps1 file. If the session host VMs can’t support existing sessions, the job starts additional session host VMs in the host pool.
The above scaling tool is a low-cost automation option for customers who want to optimize their session host VM costs.
- Schedule VMs to start and stop based on Peak and Off-Peak business hours.
- Scale out VMs based on number of sessions per CPU core.
- Scale in VMs during Off-Peak hours, leaving the minimum number of session host VMs running.
But the above tool deployment is complex, and we have seen admins to struggle to fix the tool when any jobs has failed to run in the Azure automation account.
There are other 3rd party options available in the market, one of the best tool comes with Nerdio Manager, which provide the auto scale capabilities for multi user desktops and remote apps host pool. They also have auto scale for single user personal desktops, although now the similar auto scale feature for single user personal desktop can also be implemented with the help of Azure Automation and VM Start on Connect feature of AVD.
Citrix CVAD solution which is again provide a great control plane for the AVD, also provide the auto scale feature built in the Citrix Studio which generally heavily used by the large and medium enterprises who are on Citrix Cloud with AVD.
Recently Azure Virtual Desktop came out with the new GUI based Auto Scale Feature (Preview), this lets you to scale your Azure Virtual Desktop deployment’s virtual machines (VMs) up or down to optimize deployment costs. Based on your needs, you can make a scaling plan based on:
- Time of day
- Specific days of the week
- Session limits per session host
In today’s blog, I would like to explain you how quickly you can deploy the GUI based autoscaling in Azure.
Create a RBAC role with the help of a PowerShell script
In the first step to deploy the new auto scale tool, you need to create a new RBAC role in Azure. Here is a PowerShell Script which will helps in creating the new RBAC role. This role will allow Windows Virtual Desktop to power manage all VMs in your subscription. It will also let the service apply actions on both host pools and VMs when there are no active user sessions.
$role = Get-AzRoleDefinition “Virtual Machine Contributor”
$role.Id = $null
$role.Name = “Desktop Virtualization Autoscale”
$role.Description = “Can setup the Auto Scale of Azure Virtual Desktop”
$role.Actions.Clear()
$role.Actions.Add(“Microsoft.Compute/virtualMachines/deallocate/action”)
$role.Actions.Add(“Microsoft.Compute/virtualMachines/restart/action”)
$role.Actions.Add(“Microsoft.Compute/virtualMachines/powerOff/action”)
$role.Actions.Add(“Microsoft.Compute/virtualMachines/start/action”)
$role.Actions.Add(“Microsoft.Compute/virtualMachines/read”)
$role.Actions.Add(“Microsoft.DesktopVirtualization/hostpools/read”)
$role.Actions.Add(“Microsoft.DesktopVirtualization/hostpools/write”)
$role.Actions.Add(“Microsoft.DesktopVirtualization/hostpools/sessionhosts/read”)
$role.Actions.Add(“Microsoft.DesktopVirtualization/hostpools/sessionhosts/write”)
$role.Actions.Add(“Microsoft.DesktopVirtualization/hostpools/sessionhosts/usersessions/delete”)
$role.Actions.Add(“Microsoft.DesktopVirtualization/hostpools/sessionhosts/usersessions/read”)
$role.Actions.Add(“Microsoft.DesktopVirtualization/hostpools/sessionhosts/usersessions/sendMessage/action”)
$role.AssignableScopes.Clear()
$role.AssignableScopes.Add(“/subscriptions/11111-11111-11111-11111-11111”)
New-AzRoleDefinition -Role $role
In the above script replace the subscription ID with your own Azure Subscription ID.
Assign the RBAC role in the Azure Portal
Once the custom RBAC role is created you need to assign the role to grant access to Azure Virtual Desktop. As shown below in the GUI.
Select the Azure Virtual Desktop
Once you have assigned the role it will show in the member list like below.
Create the scaling plan for the Azure Virtual Desktop
The next step is to create the scaling plan for the Azure Virtual Desktop.
In the scaling plan basics tab, you need to supply the Name of the scaling plan, Azure Location, Friendly Name of the scaling plan and the description.
In the schedules tab you need to enter the schedule details, here I am first creating a weekdays schedule so I have given the name of the scaling plan as weekdays_schedule, Repeat on allows me to choose the days of the week when I need this schedule to run. I have chosen all the weekdays except the Saturday and Sunday.
When I click next it shows the Ramp-up screen, it’s an important screen to be filled.
Ramp-up:
Here you should know the following before you fill the details.
Start Time: Enter a start time for the scaling plan to prepare virtual machines for peak business hours. This also the end time for off-peak hours.
Load balancing algorithm: Breath-first load balancing distributes new user sessions across all available session hosts in the host pool. Depth-first load balancing distributes new user sessions to an available session hosts with with the highest number of conenctions but has not reached its maximum session limit threshold. For Load balancing algorithm, we recommend selecting breadth-first algorithm. Breadth-first load balancing will distribute users across existing VMs to keep access times fast.
Minimum percentage of hosts (%): Here you can specify the minimum percentage of session host virtual machines to start for ramp-up and peak hours. For example, if Minimum percentage of hosts is specified as 10% and total number of session hosts in your host pool is 10m Autoscale will ensure a minimum of 1 session host is available to take user connections.
Capacity threshold (%): This is the value of percentage of used host pool capacity that will be considered to evaluate whether to turn on/off virtual machines during the ramp-up and peak hours. For example, if capacity threshold is specifies as 60% and your total host pool capacity is 100 sessions, autoscale will turn on additional session hosts once the host pool exceeds a load of 60 sessions.
In the next step you need to fill the peak hours details.
Peak hours:
Start Time: Here you need to enter a start time for beginning of peak hours in the time zone you specified for your scaling plan. This is also the end time for ramp-up-hours.
Load balancing algorithm: Breath-first load balancing distributes new user sessions across all available session hosts in the host pool, depth-first load balancing distributes new user sessions to an available session host with the hisghest number of connections but has not reached it’s maximum session limit threshold.
We have kept the same as breath-first.
Capacity threshold%: This is the value of percentage of used host pool capacity that will be considered to evaluate whether to turn on/off virtual machines during the ramp-up and peak hours. For example, if capacity threshold is specifies as 60% and your total host pool capacity is 100 sessions, Autoscale will turn on additional session hosts once the host pool exceeds a load of 60 sessions.
In next step we will see what’s there is in the Ramp-down tab.
Ramp-down:
Start time: Here you can specify minimum percentage of session host virtual machines that you would like to get to for ramp-down and off-peak hours. For example, if Minimum percentage of hosts is specified as 10% and the total number of session hosts in your host pool is 10, Autoscale will ensure a minimum of 1 session host is available to take user connections.
Capacity threshold%: This is the value of percentage of used host pool capacity that will be considered to evaluate whether to turn on/off virtual machines during the ramp-up and peak hours. For example, if capacity threshold is specifying as 60% and your total host pool capacity is 100 sessions, Autoscale will turn on additional session hosts once the host pool exceeds a load of 60 sessions.
Force Log Off Users: Logging off a user from a session without warning can result in loss of data on the user’s session. You should send a message to the user to warn the user before taking this action.
Delay time before logging out users and shutting down VMs (min): This will set the session host VMs to drain mode, notify any currently signed in users to save their work and wait the configured amount of time before forcing the users to logoff. Once all users’ sessions on the session host VM have been logged off, Autoscale will shut down the VM.
The last step is setting the Off-peak hours.
Start Time: This is the start time for off-peak or non-business hours. This is also the end time for ramp-down.
Assign a scaling plan to an existing host pool
You can assign the newly created scaling plan to a host pool in 3 simple easy steps
- Go to Windows Virtual Desktop.
- Select Host pools, then go to Scaling plan and select New.
- Select Scaling plan, then select + Assign to assign a scaling plan to an unassigned host pool.
How you can test and validate?
After a few minutes of creating the scaling plan, you can go to the running AVD virtual machine and check the activity log, you should get an activity stating that the VM was started, and this event initiated by Windows Virtual Desktop App.
That’s all for today, the new GUI based scaling plan doesn’t cost anything extra for the AVD customers and as I suggested earlier since scaling plane currently don’t support personal dedicated host pools so for that you can use the feature start VM on connect of AVD and Auto Shut down feature of the Virtual Machine, although there are multiple tools available in the market for the Autoscaling of AVD but the main purpose of the Autoscale tool is to save the cost, with the introduction of a GUI based tool it’s became an easy job for the admins who are managing thousands of AVD’s every day. I am sure this is not the end and there will new enhancement in the autoscaling of AVD and new algorithms will be introduced in the future.