How to script warm up of CloudService instances in Azure?

443 views Asked by At

I have a CloudService Classic Application with 2 instances which I will call bob_app_001 and bob_app_002, each BobApp has 5 instances in it.

The app is a c# Api which has an endpoint that we use for monitoring on ~/ping.

I currently deploy by taking one of the services out of Traffic Manager, letting traffic drain off, then VIP swapping the staging to Production slots, then re-adding to Traffic Manager. The issue here is that the first few request are always slow as the service spins itself up. I am trying to avoid this by spinning up all the web related stuff by hitting the ping endpoint before dropping the pool back into rotation.

How do I script getting all the app's urls from bob_app_001, which I can then loop through calling Invoke-WebRequest for each of them, on the ping endpoint to warm the service before I drop it back into the TrafficManager after VIP swap.

1

There are 1 answers

1
Alex On BEST ANSWER

getting all the app's urls from bob_app_001 This will be the tricky part, especially without reaching inside the app and exposing the URLs somehow (depending on how your routing is set up)

I'd suggest using Application Initialization Module instead.

To enable the module you need to create an applicationInitialization section in web.config where you define the url to be hit for the initialization task to begin.

<system.webServer>  
  <applicationInitialization>  
    <add initializationPage="/app/init" />  
  </applicationInitialization>  
<system.webServer>

Then a lightweight controller to do you initialisation in:

public class InitController : ApiController
{
    [Route("/app/init")]
    public IHttpActionResult Index()
    {
        //do your initialisation / warmup here

        return Ok();
    }
}

I've left any notion of security out of this example, but it'd be best to restrict access to /app/init from within the application (and only run once)

Once setup, the swap operation between deployment slots will be completed after the code under "app/init" url is finished.