Autoscaling in a modern world…. Part 4

Posted by Steve Loethen on Geeks with Blogs See other posts from Geeks with Blogs or by Steve Loethen
Published on Fri, 15 Jun 2012 08:45:20 GMT Indexed on 2012/06/15 21:17 UTC
Read the original article Hit count: 518

Filed under:

Now that I have the rules and services XML files in the cloud, it is time to sever the bounds of earth and live totally in the cloud.  I have to host the Autoscaling object in Azure as well, point it to the rules, tell it the management certs and get out of the way.

A couple of questions.  Where to host?  The most obvious place to me was a worker role.  A simple, single purpose worker role, doing nothing but watching my app.  Here are the steps I used.

1) Created a project.  Separate project from my web site.  I wanted to be able to run the web in the cloud and the autoscaler local for debugging purposes.  Seemed like the easiest way. 

2) Add the Wasabi block to the project.

3) Configure the settings.  I used the same settings used for the console app.  It points to the same web role, uses the same rules file. 

4) Make sure the certification needed to manage the role is added to the cert store in the sky (“LocalMachine” and “My” are default locations).

I ran the worker role in the local fabric.  It worked.  I then published to the cloud, and verified it worked again.  Here is what my code looked like.

public override bool OnStart()
  {
      Trace.WriteLine("Set Default Connection Limit", "Information");
      // Set the maximum number of concurrent connections 
      ServicePointManager.DefaultConnectionLimit = 12;

      Trace.WriteLine("Set up configuration change code", "Information");
      // set up config 
      CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) => configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)));

      Trace.WriteLine("Get current diagnostic configuration", "Information");
      // Get current diagnostic configuration
      DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();

      Trace.WriteLine("Set Diagnostic Buffer Size", "Information");
      // Set Diagnostic Buffer size
      dmc.Logs.BufferQuotaInMB = 4;

      Trace.WriteLine("Set log transfer period", "Information");
      // Set log transfer period
      dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);

      Trace.WriteLine("Set log verbosity", "Information");
      // Set log filter to verbose
      dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

      Trace.WriteLine("Start the diagnostic monitor", "Information");
      // Start the diagnostic monitor
      DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", dmc);

      Trace.WriteLine("Get the current Autoscaler from the EntLib Container", "Information");
      // Get the current Autoscaler from the EntLib Container
      scaler = EnterpriseLibraryContainer.Current.GetInstance<Autoscaler>();

      Trace.WriteLine("Start the autoscaler", "Information");
      // Start the autoscaler
      scaler.Start();

      Trace.WriteLine("call the base class OnStart", "Information");
      // call the base class OnStart
      return base.OnStart();
  }

  public override void OnStop()
  {
      Trace.WriteLine("Stop the Autoscaler", "Information");
      // Stop the Autoscaler
      scaler.Stop();
  }

I did have to turn on some basic logging for wasabi, which will cover in the next post.  This let me figure out that I hadn’t done the certificate step.  Smile

© Geeks with Blogs or respective owner