The easiest way to scale the brand new Azure SignalR service
A couple of months ago we migrated our push notification for the website to the brand new Azure SignalR service. In this post I am going to quickly give the steps to create a simple task that scales up and down the service in order to save money in your Azure account.
This service is quite new so the pricing tiers and scale settings are still not very well designed for all customers cases.
In our case we have peaks of traffic during Europe business hours and during the night and weekends the traffic goes down. So the users connected to the push service vary through the day. Right now there is no an automatic scale system built for SignalR service as we have in App Services.
Prices and tiers
Right now the SignalR service has 2 tiers: Basic and Standard.
With the Standard Tier you can scale 1,2,5,20, 50, 100 thanks to this page (Scale Option):
To give an overview 100 units cost almost $5000 per month
The code we use to scale:
#!/bin/bashResourceGroupName=$2SignalRName=$1CurrentDayOfWeek=$(date +%u)echo $CurrentDayOfWeekCurrentHour=$(date +%H)echo $CurrentHourif (( $CurrentDayOfWeek <= 5 ))thenif (($CurrentHour >= 6 && $CurrentHour < 22))thenecho is week morning.az signalr update -n $SignalRName — resource-group $ResourceGroupName — sku Standard_S1 — unit-count 2elseecho is week night.az signalr update -n $SignalRName — resource-group $ResourceGroupName — sku Standard_S1 — unit-count 1fielseecho is weekend.az signalr update -n $SignalRName — resource-group $ResourceGroupName — sku Standard_S1 — unit-count 1fi
At FXStreet we manage all the Azure maintenance task from Azure devops, probably is not the best way but is very versatile because you can execute scripts in the steps.
An example of the things we manage:
So how to scale SignalR service? We use Azure cli step in Azure dev ops
That’s it! less than 24 lines of code. In case you don’t use Azure devops you just need to add az login in order to login into your azure account and you can use the very same code.