2

I have implemented an azure cloud service (recipesavants.cloudapp.net) with 2 instances (both small) and anytime I go to the URI it takes forever (usally 30+ seconds) for the 1st page to render.

I am thinking that this is because the instance is spinning up from a sleep or inactive state, is this correct?

To alleviate this - I have created a worker role that pings the URI every minute using the following code:

using (var client = new HttpClient())
{
    // New code:
    client.BaseAddress = new Uri("http://brewsavants.cloudapp.net");
    HttpResponseMessage response = await client.GetAsync("");
    client.BaseAddress = new Uri("http://recipesavants.cloudapp.net");
    response = await client.GetAsync("");
    client.BaseAddress = new Uri("http://recipesavantsapi.azurewebsites.net/api/ping");
    response = await client.GetAsync("");
}

But, it still seems like after 20 minutes or so - the instances go to sleep. Is there another work around? I really need these instances to be highly available, and fast.

Dave New
  • 38,496
  • 59
  • 215
  • 394
MVCWizards
  • 21
  • 1
  • This is more an IIS-related question as Azure Web Roles just run vanilla IIS. You are seeing default behaviours for ASP.Net applications - after period of non-use their application pools are unloaded and then take a period to start of next request. There are a few solutions (on Stack Overflow and elsewhere) to this for Web Roles. Look for 'always on azure webrole' on your search engine of choice. – Simon W Jan 12 '15 at 00:43
  • Not sure if this is directly related, but I [answered another Azure question](http://stackoverflow.com/a/10352397/272109) a while back about adjusting the AppPool timeout to deal with the 20-minute window. – David Makogon Jan 12 '15 at 04:04

1 Answers1

2

You can include a script with your package, which is configured to run as a startup script, every time the role is restarted.

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. In the service definition.csdef for your Azure Cloud Service project you have to add the line

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

Redeploy your solution

realnero
  • 994
  • 6
  • 12