Share via


How to increase application pool idle timeout in windows azure cloud applications ?

App-pool Idle Time-out is the amount of time (in minutes) a worker process will remain idle before it shuts down. A worker process is idle if it is not processing requests and no new requests are received.   

Idle Time-out property can be changed in IIS after you RDP into the VM's of Azure, but this is not recommended and remote desktop must be used only for basic troubleshooting. Any changes done on the Virtual Machine manually after RDP will not be persisted.This is because, in the event of any hardware failure or automatic OS upgrade in Azure cloud, Fabric controller will bring down the VM instance and automatically deploy your package on another VM/on the same VM (Virtual machine). If this happens all the changes done manually on the VM will be lost. Therefore the recommended approach is to perform all the operation by code and deploy the package.

You can implement this by using ServerManager class defined in Microsoft.Web.Administration DLL.

===============================================================================================================

  1.  Add Microsoft.Web.Administration DLL to the project reference. (Path of Microsoft.Web.Administration DLL: C:\Windows\System32\inetsrv).

            

       2. Set Copy local property of the above DLL to true. (Right click on the DLL -> properties -> copy local = true)

             

      3. Copy and paste the below code snippet.

      4. Run the WebRole in elevated execution context. (Add the below tag in servicedefinition.csdef file to run the code in elevated privileges)

             <Runtime executionContext="elevated"/>

            

 

// The below code snippet must be added in WebRole.cs file.

using System;

using System.Collections.Generic;

using System.Linq;

using Microsoft.WindowsAzure;

using Microsoft.WindowsAzure.Diagnostics;

using Microsoft.WindowsAzure.ServiceRuntime;

using Microsoft.Web.Administration;

using Microsoft.WindowsAzure.Diagnostics.Management;

namespace WebRole1

{

   public class WebRole : RoleEntryPoint

  {

        public override bool OnStart()

        {

               ServerManager iisManager = new ServerManager();

               Application app = iisManager.Sites[RoleEnvironment.CurrentRoleInstance.Id + "_Web"].Applications[0];

               //================ idletimeout ====================================================//               

         string dt = iisManager.ApplicationPoolDefaults.ProcessModel.IdleTimeout.ToString();

               TimeSpan ts = new TimeSpan(0, 60, 00);

               iisManager.ApplicationPoolDefaults.ProcessModel.IdleTimeout = ts;

 

         //================ Enable or disable static/Dynamic compression ===================//

         Configuration config = iisManager.Sites[RoleEnvironment.CurrentRoleInstance.Id + "_Web"].GetWebConfiguration();

               ConfigurationSection urlCompressionSection = config.GetSection("system.webServer/urlCompression");

               urlCompressionSection["doStaticCompression"] = true;

               urlCompressionSection["doDynamicCompression"] = true;

        //================ To change Application pool name ================================//

              app.ApplicationPoolName = "ASP.NET v4.0 Classic";

        // Commit the changes done to server manager.

               iisManager.CommitChanges();

               return base.OnStart();

        }

    }

}

    

===============================================================================================================

This can also be done using a startup task in windows azure, please refer the below blog:

https://blog.smarx.com/posts/controlling-application-pool-idle-timeouts-in-windows-azure

Comments

  • Anonymous
    December 13, 2012
    Thank you so much for posting this, I was looking for some guidance on just this topic and it was quite helpful!

  • Anonymous
    January 08, 2013
    Thanks! I like this option better than the startup tasks - this allows me to more easily reuse this across my ~8 different Azure apps and manage them all more-or-less the same with a shared DLL.

  • Anonymous
    December 11, 2013
    The downside is the web role has to run as Administrator. Bye bye least privilege.

  • Anonymous
    May 26, 2014
    Great hint. Appreciate you for this