Windows Azure slow on first few requests

I have looked at this: Controlling Application Pool Idle Timeouts in Windows Azure, but not sure if this will still cause an issue when Azure recycles the application pool every 29 hours approx.

It won't cause an issue when Azure recycles the app pool, but you can also add to that startup task to prevent/increase the application pool recycling time.

Try this:

Define the task in your ServiceDefinition:

<Startup>
    <Task commandLine="startup\disableTimeout.cmd" executionContext="elevated" />
</Startup>

Then have your cmd file with the following code (just put it into notepad, then save as a .cmd file):

%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeout:00:00:00

%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.recycling.periodicRestart.time:00:00:00

Two things to make sure of:

1) Make sure you save the file with ANSI encoding.
2) When you've added that script into Visual Studio, make sure you select "Copy Always" as the "Copy to Output Directory" option in the properties.


Are you precompiling the application? By default, the application after being deployed still needs to be compiled for the first time. Depending on the size of the application, compile can take multiple seconds http://msdn.microsoft.com/en-us/library/399f057w(v=vs.85).aspx


When the first HTTP request arrives a lot of extra work is actually done - application pool is started, all needed assemblies are found, all assemblies shipped as MSIL are compiled into machine code, then the necessary ASP.NET views are precompiled (unless you deploy them precompiled, but it's quite hard with Azure tools so I guess you don't do that). This all takes some time and so the unlucky first users have to wait.

The workaround is to warm up the site from inside role entry point OnStart() - make it precompile the site and then send an HTTP request to localhost.

Tags:

Azure