Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make sure a new autoscaled Azure App Service instance is warm before it handles traffic?

With autoscaling turned on on an app service, Azure will add instances as needed based on set rules. I always start from a minimum of 2 instances. I'd like to make sure that traffic is not directed to the new app service instance until the application code has fully initialized. How can I do this? IS it possible to add a timeout? Or is it done automatically somehow?

like image 990
Ennis Avatar asked Jun 14 '17 18:06

Ennis


People also ask

Which Azure service can use autoscale?

Use Azure Monitor autoscale. Azure Monitor autoscale provide a common set of autoscaling functionality for virtual machine scale sets, Azure App Service, and Azure Cloud Service. Scaling can be performed on a schedule, or based on a runtime metric, such as CPU or memory usage.

How the app services can be scaled in Azure?

In your browser, open the Azure portal. In your App Service app page, from the left menu, select Scale Up (App Service plan). Choose your tier, and then select Apply. Select the different categories (for example, Production) and also See additional options to show more tiers.

What are two types of scaling in Azure?

Two main ways an application can scale include vertical scaling and horizontal scaling. Vertical scaling (scaling up) increases the capacity of a resource, for example, by using a larger virtual machine (VM) size. Horizontal scaling (scaling out) adds new instances of a resource, such as VMs or database replicas.


2 Answers

You want to use Application Initialization in the web.config file for your app.

you'll need to add something like this:

<system.webServer>  
  <applicationInitialization >  
    <add initializationPage="/page-you-want-to-warm-up.php" hostName="your-app.azurewebsites.net"/> 
  </applicationInitialization>  
<system.webServer> 

Every time your application starts, this can be because of a new worker coming online (horizontal scaling) or even just a cold start caused by a new deployment, config change etc... the ApplicationInitialization will be executed to warm up the site before accepting requests on that worker.

You can read more about this here: http://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/

Even though that post is talking about using this for warming up a site when doing a swap operation it also applies to cold starts, and scale outs.

like image 195
Byron Tardif Avatar answered Sep 29 '22 16:09

Byron Tardif


How can I do this? IS it possible to add a timeout? Or is it done automatically somehow?

If you use horizontal scaling, also called scaling out and in, azure will keep your application continues running without interruption as new resources are provisioned.

Azure will automatically warm up the new instance's application and add a Load Balance to distribute the requests between them automatically. You don't need to configure the load balance separately by yourself.

More details about how azure auto scale work, you could refer to this article and this article.


"Azure will automatically warm up the new instance's application" - the links you provided do not say this - can you provide other references? I essentially don't want the instance added to a load balancer until a specific URL is accessible with 200 OK or after a hard timeout of 2 minutes.

After the web app scale out to the 2 instance, if the new request are send to the default instance web site , azure will warm up the new instance's web app.

You could write a test as below:

Add below config codes in web.config's webserver tag to trace all the request:

<tracing>  
  <traceFailedRequests>  
    <clear/>  
    <add path="*">  
      <traceAreas>  
      <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,Rewrite,iisnode" verbosity="Verbose" />  
      </traceAreas>  
      <failureDefinitions statusCodes="200-600" />  
    </add>  
  </traceFailedRequests>  
</tracing> 

Then if your site scale out to 2 instance, after you access the web app. Load balance will not redirect the request to the second instance since the instance's process doesn't start. Azure will auto warm up the second instance's web app.

You could find the log as below image shows:

enter image description here

The log result:

enter image description here

fr00030.xml(you could find the process is 5860 old instance):

enter image description here

fr00031.xml(you could find the process is 8164 new instance and takes 4015 msec)

enter image description here

Besides, as Byron Tardif says, if you want to enable custom warm up(warm up all the pages), you could use Application Initialization Module.

It will also be called before the new request access your second web app instance.

like image 34
Brando Zhang Avatar answered Sep 29 '22 16:09

Brando Zhang