Thanks, Natalia.
And hi, everyone. My name is Jason Freeberg.
I'm a Product Manager on Azure App Service.
So in the previous two videos, Natalia showed you
how to deploy a Node.js application to Azure App Service
and then how to connect it to a database and storage.
Now that you've done
that, let's get this application ready for production use.
And specifically, let's set up auto scaling so that your application
will scale out horizontally when it receives more requests.
Before we get started,
make sure you go back to Natalia's first two videos and follow along.
Once you've done that,
let's open the Azure Portal to your Azure Web App.
Once you have that open,
scroll down to 'Scale up' and you need to make sure
that you're on an App Service plan tier that has auto scaling.
So you can see here, I've selected P1V2 and if I scroll down
under included features, there's auto scale for up to 20 instances.
Now, once you've made sure that you're on an App Service plan
that has auto scaling, click down to 'Scale out' and you'll see that
there's two options for scaling your App Service plan.
The first is manual scale, and by default
this should be at one instance and you can use this slider
to select a number of instances that you want, say ten instances,
and then Azure will keep your App Service plan
at a static ten instances.
Now on the other hand, you can come over to custom
autoscale and then you can scale based on a metric.
So here we'll click 'add a rule'
and then we're going to scale based on our App Service.
And we're going to select our Web App here.
So this is the same--
application that we have right over here.
'nvcontosohrapp'
Next thing we're going to do is select
the metric that we want to scale based off.
You can see in this list,
there's a lot of different metrics that you can use.
But for this example, we're going to use request count.
Now, if we come down here, you can see that
this graph is showing, in blue, the number of requests
that we've gotten over time.
And you can see there haven't been a whole lot
and then this dash line is showing the threshold of requests
that we need to get past for the App Service plan to scale out.
So if we keep scrolling, you can see that this is set at 70,
the dash line,
and then
under duration, I'm going to set this to 5 minutes.
So far, our scale rule is saying that when my request count
is greater than 70 requests for a five minute period,
then I want to increase my instance count by one instance.
So now we'll hit 'add'.
And then last thing you need to do
is make sure that you set a maximum above one instance.
Otherwise the rule will never execute.
So for example, I'll set my maximum to four instances.
Last thing to do is hit save
and now we've set up auto scaling!
So now to test this,
let's go back to VS Code
and then you can see here I have a shell command ready to go.
This is using the Apache Benchmark tool
and if you're not familiar with it, it's pretty simple.
It's just going to send 15,000 requests
with a concurrent request count of 100.
So at any one time
there shouldn't be more than 100 concurrent requests to the Web App.
That's going to take a lot of time.
But you remember that we set the scale rule
to only execute when there's been a consistent or--
excuse me, an average of 70 requests
over a five minute period.
So we'll run this command
and then we'll come back in a few minutes
when all these requests have hit our Web App.
Alright.
So we're back after a short break.
All of the requests have completed.
You can see the Apache Benchmark tool is done here.
So if we come back to the portal,
you can see here, already, our instance count is at two.
And if we come in to 'run history'
this is showing the run history for auto scale over the past hour.
And you can see here, it was at one instance
and then the Apache Benchmark tool kicked in.
And now we're up to our two instances.
One last thing I want to call out in our auto scale rule
is you want to make sure to set a rule to scale back in.
So you can say under here, 'decrease instance count by' one.
Say, when your request count
is less than a certain threshold.
Say, under 20 requests,
then you want to decrease your instance count by one.
Just as an example.
So I hope you enjoyed the video.
Join me for the next video where we'll set up App Service
deployment slots and a new staging environment for our Web App.
Thanks for watching!