Keep the Azure Web role Always On

Microsoft Azure Web roles generally suffers with the Service Slow problem for the First request after a certain time of in activity. It is because of the default configuration of an IIS Application pool that is set to have an idle-timeout of 20 minutes. So, if there is any inactivity for 20 minutes, then it will automatically shutdowns your Web Role, resulting the first user will experience long loading time, which is unacceptable in the present day standards.

So the simple work around for this is to have a small script in your package which runs at startup, every time the role starts up.

For the above to work, include the following script in a startup.cmd file that you place in a folder called Startup in your web role project.

REM *** Prevent the IIS app pools from shutting down due to being idle.
%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeout:00:00:00


REM *** Prevent IIS app pool recycles from recycling on the default schedule of 1740 minutes (29 hours).
%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.recycling.periodicRestart.time:00:00:00

Set the "Copy to output directory" to "Copy always" so it becomes part of the package.

To ensure that startup.cmd script is called on web role starting add the following section in the "ServiceDefinition.csdef" of your Azure Cloud Service project under your Web Role part.

  

So your Web role section under "ServiceDefinition.csdef" will be look like below.

  
    
 
   
 
    
  
  
  ....
  
  
    
  
  
    
  

It's done. Just build your solution and deploy. The web role  will now no long automatically shutdown or recycle.

Gopikrishna

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment