4lowTheRabbit.github.io

Test Application Initialization in Azure App Services

We can use Application Initialization to warmup an worker instance in Azure App Service. So that when an App Service Plan is scaled out, the new worker instance is warmed up, before it receives real end user requests.

Setup

I deployed a .Net framework MVC application with a WarmupController class below:

public class WarmupController : Controller
{
    // GET: Warmup
    public string Index()
    {
        Thread.Sleep(60000);
        return "Warmed up";
    }
}

And the web.config file:

<applicationInitialization>
    <add initializationPage="/warmup/" />
</applicationInitialization>
<tracing>
    <traceFailedRequests>
    <remove path="*" />
    <add path="/warmup/">
        <traceAreas>
        <add provider="ASP" verbosity="Verbose" />
        <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
        <add provider="ISAPI Extension" verbosity="Verbose" />
        <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,Rewrite,iisnode" verbosity="Verbose" />
        </traceAreas>
        <failureDefinitions statusCodes="200-500" />
    </add>
    </traceFailedRequests>
</tracing>

I turn on the Failed Request Trace and Web Server Log for the site.

Turn on the logs

The log files can be found in the D:\home\LogFiles\ folder of the site. I can access the log files via the Kudu site.

I use ab to trigger site requests load:

ab -n 1000000 -c 2 http://juzhuwarmup.azurewebsites.net/home/about

ab

When the load test is on, I scale out the plan to add a new worker instance.

Test result

The ab requests are not sent the new instance, until the warmup request is returned.

Things to note.