Given a deployment to an Azure Cloud Services WebRoles (2) using Azure SDK 3.0 on .net 4.5.2 and OS Family "4" (Windows 2012).
When the web application starts, we want to load a cache (from blob storage) that takes around 10 minutes (We have looked into moving this but currently can't)
Then when the IIS application pools recycles, we want the site to stay up.
Currently the default IIS settings with Cloud Services are:
- Not to start on load (autoStart / startMode)
- To idle every 20 minutes (idleTimeout)
- To recycle every 29 hours (periodicRestart)
- to have failures as HTTP 503s (loadBalancerCapabilities)
Because we default to 2 WebHost, we want to recycle the app pool at different times. We ideally want existing connection from the site to be redirected if one of the webhosts is loading the cache.
So far, we have a Start up task script to reconfigure the IIS AppPools
appcmd set config -section:system.applicationHost/applicationPools
with
/applicationPoolDefaults.autoStart:"True"
/applicationPoolDefaults.startMode:"AlwaysRunning"
/applicationPoolDefaults.processModel.idleTimeout:"00:00:00"
/applicationPoolDefaults.recycling.logEventOnRecycle:"Time,Requests,Schedule,Memory,IsapiUnhealthy,OnDemand,ConfigChange,PrivateMemory"
/applicationPoolDefaults.recycling.periodicRestart.time:"00:00:00"
/~"applicationPoolDefaults.recycling.periodicRestart.schedule"
/+"applicationPoolDefaults.recycling.periodicRestart.schedule.[value='06:00:00']"
/applicationPoolDefaults.failure.loadBalancerCapabilities:"TcpLevel"
e.g
%windir%\system32\inetsrv\appcmd set config -section:applicationPools /applicationPoolDefaults.autoStart:"True" /commit:apphost
As for code, we have looked at using a Busy
flag until the cache has loaded. This doesn't appear to re-route the traffic
RoleEnvironment.StatusCheck += WebRoleEnvironment_StatusCheck;
with
if (Busy)
{
e.SetBusy();
}
The draw back is this is done in the Application_Start
due to the containers that are required. I think it would be too hard to move the LoadCache()
into the OnStart()
of the RoleEntryPoint
.
Note; We also have "Keep-alive" on by default.
Questions;
- How do we take a WebHost offline while it loads the cache?
- Should we change the IIS settings? https://azure.microsoft.com/en-gb/blog/iis-reset-on-windows-azure-web-role/
- Should we use IIS 8.0 Application Initialization? http://fabriccontroller.net/iis-8-0-application-initialization-module-in-a-windows-azure-web-role/
- What should loadBalancerCapabilities be set to? https://docs.microsoft.com/en-us/iis/configuration/system.applicationhost/applicationpools/add/failure
- Should we try to stagger recycles? What about when we scale (add more instances) Does azure prevent that role instances are recycled at the same time?