7

A have an azure webrole with a test page and a service in that role. After publishing the role it doesn't start automatically, only at first use. So if the role is shut down for some reason the first usage after that is quite slow.

Is there a way to make webroles start automatically right after they are deployed (either first time, or after a migration)?

bkaid
  • 51,465
  • 22
  • 112
  • 128
Attila Klenik
  • 753
  • 6
  • 13
  • 1
    The following Stackoverflow answer shows how to to this in IIS 8 (Windows Server 2012) using the application initialization feature: http://stackoverflow.com/questions/13237393/automatically-install-application-initialization-in-azure-web-role-sdk-v1-8-wi – Juha Palomäki Oct 23 '13 at 05:24

2 Answers2

5

Check out the auto start feature of IIS 7.5. Make sure you set osFamily="2" for the webrole so that it uses the Windows 2008 R2 OS.

Edit: We're still stuck on osFamily="1" for technical reasons, so we haven't been able to implement auto start functionality yet. However, here are the steps that would be required to setup auto start:

  1. Create your own auto start provider that implements the IProcessHostPreloadClient interface. There used to be a default provider called the Application Warm-Up Module, but it's not available for download anymore. You can use .Net Reflector to view the contents of the Microsoft.ApplicationServer.Hosting.AutoStart.ApplicationServerAutoStartProvider.dll as an example implementation. This dll is included in Windows Server (not Azure) AppFabric.

  2. The next step is to specify the correct settings in your applicationHost.config. Some variation of the code listed here can be entered in your RoleEntryPoint class so that it's called when your Azure Role fires up.

Please let the community know if you successfully create your own auto start provider. At this point, there isn't a lot of information about implementing IProcessHostPreloadClient on the internet.

Jonathan McIntire
  • 2,665
  • 23
  • 26
  • @Atesz - A combination of my answer and David Makogon's should give you what you need. – Jonathan McIntire Mar 06 '12 at 17:39
  • Good point on osFamily, as the default is "1" (Windows 2008 SP2). – David Makogon Mar 06 '12 at 19:38
  • As I see, you have to do this magic on the host machine, or am I missing something? What if my app is migrated to a new machine? I have to do it again? Can't you do it through Azure (the ServiceDefinition has a Startup tag, where I start the sricpt mentioned by David)? I'm a little confused here. [My source of IIS autostart](http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx) – Attila Klenik Mar 17 '12 at 21:37
  • Currently this is a low priority problem, since the software is in the prototyping phase. As soon as I need to implement it, I'll let you know about the results. – Attila Klenik Mar 18 '12 at 19:04
2

A role is typically restarted about once a month, for OS maintenance of either the Guest or the underlying Host OS. What you're more likely to see is AppPool timeout due to inactivity, which will exhibit the same type of initial-hit delay. The default timeout is 20 minutes. You can change the timeout via elevated startup script, with something like:

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

I discussed this in another SO question as well.

Community
  • 1
  • 1
David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • +1 Forgot to mention setting the AppPool timeout even though we disable the timeout in our apps. :P – Jonathan McIntire Mar 06 '12 at 17:29
  • I know about the AppPool timeout, and it is disabled (with the same script you mention). But it still shuts down sometimes. Every exception is handled, so it can't be a problem. Probably maintance, that's why I want to start the service again as soon as it is deployed again. – Attila Klenik Mar 17 '12 at 21:24