Autoscaling Azure with WASABi – Part 2

I gave an Autoscaling Azure talk at the Brisbane Azure User Group (BAUG) on the 18th April 2012. This series of posts will walk through the demo I put together for the talk using the Autoscaling Application Block (WASABi).

What are we building?

We will be building the application that performs the autoscaling using the Autoscaling Application Block (WASABi) from the Enterprise Library 5.0 Integration Pack for Windows Azure. I decided to build a simple console application to host the autoscaler locally for the purposes of the demo. For simplicity I also used a local service information store and local rules store. More on these stores in the next parts of the series.

In a real world situation you would probably want to host the autoscaler in an Azure cloud service worker role and the stores in an Azure storage account.

Create Storage Account

Didn’t we just create a storage account in part 1? Yes we did, but that was for the web application that we will be scaling. We now need to create a storage account that will hold the data points that the autoscaler will use to evaluate its scaling rules.

The data points store must be hosted in an Azure storage account as the Autoscaling Application Block uses the upsert feature of the Azure table storage that is not supported by the local emulator.

Log in to the Windows Azure preview portal and click on the NEW button. Select Storage > Quick Create and fill in the details for your storage account. I have selected baugautoscalingdata as my url and Southeast Asia as my region since I live in Australia. The subscription I am using is the subscription linked to my MSDN. I have also disabled geo-replication for the demo storage account. Click on Create Storage Account.

baugautoscalingdata - create storage account

Wait for the storage creation to complete successfully. You should be rewarded with an Online status.

baugautoscalingdata - Storage online !

Create Console Application

Now on to the actual console application that will host the autoscaler. Click on New Project in Visual Studio and select Visual C# > Windows > Console Application. I have a folder C:\Projects\WasabiDemo where I am creating the solution with the name, ConsoleAutoscaler. Click OK to create the project.Console Application Project

Right click on the ConsoleAutoscaler project and select Properties. Ensure that the Target Framework is set to .NET Framework 4 and not the default .NET Framework 4 Client Profile. Save.

Right click on the ConsoleAutoscaler project and select Manage NuGet Packages … Select the Online tab on the left of the dialog and then in the search box type the word wasabi. Hit Enter.

Select the Enterprise Library 5.0 – Autoscaling Application Block package and click Install.NuGet: Enterprise Library 5.0 – Autoscaling Application Block

A number of dependencies are installed into the project in addition to schemas to manage the service information and local rules stores.

Solution Explorer

Open the Program.cs file and update with the following code:

 
using System;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.Autoscaling;

namespace ConsoleAutoscaler
{
  class Program
  {
    static void Main(string[] args)
    {
      try
      {
        var scaler = EnterpriseLibraryContainer.Current.GetInstance<Autoscaler>();
        scaler.Start();

        while (true)
        {
          System.Threading.Thread.Sleep(10000);
          Console.WriteLine("{0} - running", DateTime.Now);
        }
      }
      catch (Exception exp)
      {
        Console.WriteLine(exp.Message);
        Console.Write(exp.StackTrace);
      }
      Console.ReadKey();

    }
  }
}

That is all there is to setting up the autoscaler using the Autoscaling Application Block. The next steps will be to configure the autoscaler and the service information and local rules stores.

Autoscaling Azure with WASABi – Part 1

I gave an Autoscaling Azure talk at the Brisbane Azure User Group (BAUG) on the 18th April 2012. This series of posts will walk through the demo I put together for the talk using the Autoscaling Application Block (WASABi).

What do we need to get started?

You’ll need Visual Studio 2010 and the Windows Azure SDK for .NET. You’ll also need a Windows Azure account – you can sign up for a 90-day free trial or use your MSDN Subscription.

What are we building and deploying?

We will be building and deploying an Azure application that will be the target of the autoscaling. I decided to build a simple ASP.NET MVC 3 web application that also allowed me to manipulate some simple metric that WASABi could monitor for its autoscaling rules. WASABi can monitor a number of metrics but for the demo I decided on the queue length of a queue on the Windows Azure Queue Storage Service as this was the simplest to get up and running.

Create Storage Account

Once you have a Windows Azure account log in to the Windows Azure preview portal and click on the NEW button. We need a storage account to hold the queue we’ll be using in the demo. Select Storage > Quick Create and fill in the details for your storage account. I have selected baugautoscalingapp as my url and Southeast Asia as my region since I live in Australia. The subscription I am using is the subscription linked to my MSDN. I have also disabled geo-replication for the demo storage account. Click on Create Storage Account.

baugautoscalingapp - create storage account

Wait for the storage creation to complete successfully. You should be rewarded with an Online status.

baugautoscalingapp - Storage online !

The easiest way to interact with your storage account is to use Azure Storage Explorer 5. You will need your access key to interact with your storage account so click on Manage Keys in the portal and copy the Primary Access Key to the clipboard.

Storage account - manage access keys

Click on Add Account in the Azure Storage Explorer and populate the details. I have pasted my access key copied from the portal into the storage account key field. Click Add Storage Account.

Azure Storage Explorer - configure

Confirm that you can connect to your storage account. You can see that we have not created any queues in our storage account yet.

Azure Storage Explorer - connected

Create Web Application

Now on to the actual web application. Click on New Project in Visual Studio and select Visual C# > Cloud > Windows Azure Cloud Service. I have a folder C:\Projects\WasabiDemo where I am creating the solution with the name, WebApplication. Click OK to create the project.Windows Azure Cloud Server Project

Select Windows Azure Tools – June 2012 on the next dialog. Select the ASP.NET MVC3 Web Role and click on the pencil to rename the role to WasabiDemoWebRole. Click OK.ASP.NET MVC 3 Web Role

Select the empty ASP.NET MVC 3 project template as we want this project as lean as possible. Click OK.Empty template

Open the WasabiDemoWebRole in the WebApplication Azure project from the Solution Explorer. Change the VM size to Extra small and Save. This is useful in maximising the hours allocated to your subscription. You can get 6 Extra small instances for the cost of a Small instance.

VM size - Extra small

Right click on the Models folder in the WasabiDemoWebRole project and select Add > Class. Create a class named QueueManager.

 
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;

namespace WasabiDemoWebRole.Models
{
  public class QueueManager
  {
    private string StorageConnectionString
    {
      get { return "DefaultEndpointsProtocol=https;AccountName=[REPLACE WITH YOUR STORAGE ACCOUNT NAME];AccountKey=[REPLACE WITH YOUR STORAGE ACCOUNT KEY]"; }
    }

    private string QueueName
    {
      get { return "workerqueue"; }
    }

    public int MessageCount
    {
      get { return RetrieveMessageCount(); }
    }

    private CloudQueue GetQueue()
    {
      var storageAccount = CloudStorageAccount.Parse(StorageConnectionString);
      var queueClient = storageAccount.CreateCloudQueueClient();
      var queue = queueClient.GetQueueReference(QueueName);
      queue.CreateIfNotExist();

      return queue;
    }

    public void AddMessage()
    {
      var queue = GetQueue();
      var message = new CloudQueueMessage("Brisbane Azure User Group - Wasabi Demo Test Message");
      queue.AddMessage(message);
    }

    public void RemoveMessage()
    {
      var queue = GetQueue();
      var retrievedMessage = queue.GetMessage();
      queue.DeleteMessage(retrievedMessage);
    }

    public int RetrieveMessageCount()
    {
      var queue = GetQueue();
      return queue.RetrieveApproximateMessageCount();
    }
  }
}

You will need to replace the [REPLACE WITH YOUR STORAGE ACCOUNT NAME] and [REPLACE WITH YOUR STORAGE ACCOUNT KEY] tokens in the StorageConnectionString property with your storage account name and the primary access key value from your storage account.

Right click on the Controllers folder in the WasabiDemoWebRole project and select Add > Controller. Create a controller named HomeController and use the Empty controller template.

 
using System.Web.Mvc;
using WasabiDemoWebRole.Models;

namespace WasabiDemoWebRole.Controllers
{
  public class HomeController : Controller
  {
    public ActionResult Index()
    {
      ViewBag.Message = "Queue Manager";

      var queueManager = new QueueManager();
      ViewBag.MessageCount = queueManager.MessageCount;

      return View();
    }

    [HttpPost]
    public ActionResult Manage()
    {
      ViewBag.Message = "Queue Manager";
      var queueAction = Request["QueueAction"];

      var queueManager = new QueueManager();

      if (queueAction.Equals("Add"))
      {
        queueManager.AddMessage();
      }
      else if (queueAction.Equals("Remove"))
      {
        if (queueManager.MessageCount > 0) { queueManager.RemoveMessage(); }
      }

      ViewBag.MessageCount = queueManager.MessageCount;

      return View("Index");
    }
  }
}

Right click on View() in the Index() method in HomeController and select Add View … Click the Add button in the dialog.

 
@{
    ViewBag.Title = "Brisbane Azure User Group - Wasabi Demo";
}

<h2>@ViewBag.Message</h2>
<p>Current Count of Messages in Queue Waiting to be Processed: @ViewBag.MessageCount</p>
<p>
  <form action="/Home/Manage" method="POST">
    <button type="submit" name="QueueAction" value="Add">Add</button>
    <button type="submit" name="QueueAction" value="Remove">Remove</button>
  </form>
</p>

Publish to Azure

Right click on the WebApplication Azure project in the Solution Explorer and click on Publish. Click on the Sign in to download credentials link in the Publish Windows Azure Application dialog. A publishsettings file containing publish credentials for your Azure account will be downloaded. Download publishsettings file

Click on the Import button in the Publish Windows Azure Application dialog and import the publishsettings file you have just downloaded. Select your subscription from the drop down once it has been populated.Import publishsettings file and select subscription

If you have not already provisioned a cloud service through the portal you will be prompted to create one. This is required to host your web role. I have selected baugautoscalingapp as the name of my cloud service and have selected Southeast Asia as my location.Create cloud service

The cloud service will be created.Cloud service created

This can be confirmed in the portal. The baugautoscalingapp cloud service has a service status of Created.

Confirmed in portal

Change the deployment label in the Advanced Settings tab to something meaningful. Click Next.Deployment label

Confirm the settings in the Summary and then click Publish.Summary

You will see the details of the deployment in the Windows Azure Activity Log in Visual Studio.

Windows Azure Activity Log in Visual Studio

The Deploying status will be visible on the cloud service via the portal.

Cloud service status in portal

The deployment is shown as complete in the Windows Azure Activity Log in Visual Studio

Visual Studio says deployment complete

The cloud service has a service status of Created and a Production status of Running.

Cloud service status in portal

The web application is running in Azure. If we open the cloud service url in a browser and go to the Home/Manage route we can view our simple application. Clicking on the Add button will add messages to the queue and the Remove button will remove them. Below I have added 5 messages to the queue.Application running in Azure !

If we open up Azure Storage Explorer and click on the queues link we can see that the workerqueue is now available and contains 5 messages. The message contains the text from our QueueManager class.

Confirm queue size and contents

We now have a running web application in Azure that can be scaled and control over the queue that will be used for metrics by the autoscaler.

Certificates

This is a section with some additional details around what that Publish Windows Azure Application dialog did behind the scenes. All interactions with Azure are managed via Management Certificates. This ensures that only authorised requests can be made to deploy, configure or scale resources within Azure.

If you look at your Certificate Store via the Certificates snap-in in MMC you will notice a certificate under Personal > Certificates that matches the name of the publishsettings file. The dialog automagically created a management certificate for you and added it to your store.

Certificate Store

The Management Certificates cannot be viewed in the new preview portal so you have to take a trip down memory lane and open up the old portal – https://windows.azure.com/. Click on the Management Certificates section and you’ll see the related Management Certificates associated with your subscription. Each time a publishsettings file is generated a management certificate is added under your subscription. No additional certificates however are added to your local certificate store.

Old portal - Management Certificates

Autoscaling Azure with WASABi – Introduction

I gave an Autoscaling Azure talk at the Brisbane Azure User Group (BAUG) on the 18th April 2012. This series of posts will walk through the demo I put together for the talk using the Autoscaling Application Block (WASABi).

In Part 1 we’ll build and deploy the Azure application that will be the target of the autoscaling. In Parts 2 – 5 we’ll build and configure the application that performs the autoscaling using the Autoscaling Application Block (WASABi) from the Enterprise Library 5.0 Integration Pack for Windows Azure. Finally in Part 6 we’ll run the autoscaling application and monitor the target application during the autoscaling requests.

Integration Masterclass with Richard Seroter

I had the privilege of attending an Integration Masterclass with Richard Seroter in Brisbane yesterday. Thanks to Dean Robertson of Mexia for organising this event in Australia.

Integration Masterclass with Richard Seroter hosted by Mexia

Richard led us through various strategies for building hybrid cloud integration solutions with the Microsoft Application Platform. One of the technologies that excited me was StreamInsight which provides complex event processing capabilities. In particular I’m looking forward to getting my hands on StreamInsight Austin which provides StreamInsight-based event processing in Windows Azure.

Dell XPS 15 (L502X) Wireless Issues – Fixed

I recently bought a new Dell XPS 15 laptop. Dell was having an Easter special (30% discount) so I maxed it out with features (quad-core i7, 8GB RAM, 256GB SSD and full HD screen). Its a nice laptop and I was hoping that the numerous reviews I’d read regarding issues with its Intel ® Centrino ® Advanced-N 6230 wireless adapter would have been solved. I was wrong.

Slow as Molasses

My Macbook was achieving 30Mb/s downloads via my cable modem but the new Dell was only managing between 1 and 4Mb/s and even then it was patchy. I tried out the main suggested solution which was to configure the wireless adapter settings in the power options in Windows 7. This did not help.

Intel Drivers

I came across a forum suggesting that the Intel drivers rather than those from Dell would solve the problem. I downloaded and installed the Wireless_15.1.1_Ds64.exe file from the Intel Download Centre. It solved the issue and now I am getting 30Mb/s downloads via my Dell.

Update – 8th Oct 2012

You could also re-install your machine with Windows 8! I upgraded to Windows 8 this weekend and have not had to install drivers from either Dell or Intel. My wireless is working perfectly and even some of the minor annoyances I’ve still had to put up with have disappeared.

iOS 5.0.1 and over the air software updates

The latest software update (5.0.1) of iOS brings with it the first experience of the iOS 5 over the air software updates. And I can say that I am a big fan !

My previously blogged about methods for updating multiple iPhones in a household are no longer necessary. The 5.0.1 over the air software update was a manageable 44MB and very kind on my bandwidth (even when downloading it more than once to upgrade each phone over our household wireless).

iOS 5.0.1 Release Notes

  • Fixes bugs affecting battery life
  • Adds Multitasking Gestures for original iPad
  • Resolves bugs with Documents in the Cloud
  • Improves voice recognition for Australian users using dictation

Download iOS 5.0 for updating multiple iPhone 4 devices

When there are multiple iPhones in a household and you want to upgrade them all from a single iOS download via multiple Macs, it can be a bit of a challenge. I have previously blogged about how to do this. This post contains the link to the new major version (5.0) of iOS for the iPhone 4 which contains over 200 new features.

Download URL

The iOS 5.0 firmware update file (.ipsw) is available at:

Update

Updating each iPhone as per my previous post resulted in a strange 3002 error.

I finally managed to solve this by placing the downloaded .ipsw file in the following location on each Mac:

  • /Library/iTunes/iPhone Software Updates

Create the folder if it does not exist. Clicking on the update button in the iPhone Summary page in iTunes will update your iPhone. Repeat with each Mac and iPhone combination.

Download iOS 4.3.5 for updating multiple iPhone 4 devices

When there are multiple iPhones in a household and you want to upgrade them all from a single iOS download via multiple Macs, it can be a bit of a challenge. I have previously blogged about how to do this. This post contains the link to the latest version (4.3.5) of iOS for the iPhone 4 which deals with a certificate validation security vulnerability.

iOS 4.3.5 Release Notes

Fixes a security vulnerability with certificate validation.

Download URL

The iOS 4.3.5 firmware update file (.ipsw) is available at:

Update

Update each iPhone as per my previous post.