Gritty Technical Info on Windows Azure Worker Roles

In the last blog entry, “Gritty Technical Info on Windows Azure Web Roles“, I covered the creation and startup of a web role within the Windows Azure Development Fabric and observing the web role with the Windows Azure Compute Emulator.  In this blog entry I’ll cover the worker role.

Open the Windows Azure Web Role Sample Solution.  Right click on the Windows Azure and select New Worker Role Project.

New Worker Role Project...
New Worker Role Project...

Once the worker role project SampleWorkerRole is added the solution explorer will display the project just like the web role, albeit fewer files.

Solution Explorer
Solution Explorer

Next right click on the SampleWorkerRole instance in the Windows Azure Web Role Sample and select properties.  Now set the instance count to 2 and the VM size to extra large.

SampleWorkerRole Properties
SampleWorkerRole Properties

Click on F5 to run the application.  Now when the application executes the 6 web role instances will start and the 2 worker role instances will start.

Windows Azure Compute Emulator
Windows Azure Compute Emulator

Examine the first worker role instance.

SampleWorkerRole Instance Status
SampleWorkerRole Instance Status

The worker role instance displays a number of new diagnostic messages in a similar way to the web role.  The first half of the trace diagnostics are configuration and instance messages.  The second half of the trace diagnostics are status messages that are printed from the worker role running.

Open up the code in the WorkerRole.cs file in the SampleWorkerRole Project.  As a comparison open the WebRole.cs file in the SampleWebRole Project.

[sourcecode language=”csharp”]
using System.Diagnostics;
using System.Net;
using System.Threading;
using Microsoft.WindowsAzure.ServiceRuntime;

namespace SampleWorkerRole
{
public class WorkerRole : RoleEntryPoint
{
public override void Run()
{
Trace.WriteLine("SampleWorkerRole entry point called", "Information");

while (true)
{
Thread.Sleep(10000);
Trace.WriteLine("Working", "Information");
}
}

public override bool OnStart()
{
ServicePointManager.DefaultConnectionLimit = 12;
return base.OnStart();
}
}
}
[/sourcecode]

In the WorkerRole.cs file the code inherites from the RoleEntryPoint for the WorkerRole. In the WorkerRole Class the Run and OnStart Methods are overridden to provide some basic trace information and set the default connection limit.

The Run method has a basic while loop that updates every 10000 milliseconds, which displays on the Windows Azure Compute Emulator as “Information: Working”.

[sourcecode language=”csharp”]
using Microsoft.WindowsAzure.ServiceRuntime;

namespace SampleWebRole
{
public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
return base.OnStart();
}
}
}
[/sourcecode]

In the code for the WebRole.cs file there is very little actually going on.  Take a closer look at the OnStart method override.  Technically this code doesn’t even need to be in the generated file and can be deleted, but provides a good starting point to add any other code needed in the start of the web role.

Next I’ll add some code in the worker role to provide a telnet prompt that responds with worker role information.  To work through this exercise completely download a telnet client like Putty (http://www.chiark.greenend.org.uk/~sgtatham/putty/).

If Visual Studio 2010 is no longer open, launch it and open the Windows Azure Web Role Sample Solution.  Right click on the SampleWorkRole Role in the Windows Azure Web Role Sample Project.  Click on the Endpoints tab of the properties window and click on Add Endpoint and call it TelnetServiceEndpoint.

Endpoint
Endpoint

Add a private member and create a run method with the following code.

[sourcecode language=”csharp”]
private readonly AutoResetEvent _connectionWait = new AutoResetEvent(false);

public override void Run()
{
Trace.WriteLine("Starting Telnet Service…", "Information");

TcpListener listener;
try
{
listener = new TcpListener(
RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["TelnetServiceEndpoint"].IPEndpoint) { ExclusiveAddressUse = false };
listener.Start();

Trace.WriteLine("Started Telnet Service.", "Information");
}
catch (SocketException se)
{
Trace.Write("Telnet Service could not start.", "Error");
return;
}

while (true)
{
listener.BeginAcceptTcpClient(HandleAsyncConnection, listener);
_connectionWait.WaitOne();
}
}
[/sourcecode]

After adding this code, add the following code for the role information to write to a stream.

[sourcecode language=”csharp”]
private static void WriteRoleInformation(Guid clientId, StreamWriter writer)
{
writer.WriteLine("— Current Client ID, Date & Time —-");
writer.WriteLine("Current date: " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString());
writer.WriteLine("Connection ID: " + clientId);
writer.WriteLine();

writer.WriteLine("— Current Role Instance Information —-");
writer.WriteLine("Role ID: " + RoleEnvironment.CurrentRoleInstance.Id);
writer.WriteLine("Role Count: " + RoleEnvironment.Roles.Count);
writer.WriteLine("Deployment ID: " + RoleEnvironment.DeploymentId);
writer.WriteLine();

writer.WriteLine("— Instance Endpoints —-");

foreach (KeyValuePair<string, RoleInstanceEndpoint> instanceEndpoint in RoleEnvironment.CurrentRoleInstance.InstanceEndpoints)
{
writer.WriteLine("Instance Endpoint Key: " + instanceEndpoint.Key);

RoleInstanceEndpoint roleInstanceEndpoint = instanceEndpoint.Value;

writer.WriteLine("Instance Endpoint IP: " + roleInstanceEndpoint.IPEndpoint);
writer.WriteLine("Instance Endpoint Protocol: " + roleInstanceEndpoint.Protocol);
writer.WriteLine("Instance Endpoint Type: " + roleInstanceEndpoint);
writer.WriteLine();
}
}
[/sourcecode]

Now add a handle method for the asynchronous call.

[sourcecode language=”csharp”]
private void HandleAsyncConnection(IAsyncResult result)
{
var listener = (TcpListener)result.AsyncState;
var client = listener.EndAcceptTcpClient(result);
_connectionWait.Set();

var clientId = Guid.NewGuid();
Trace.WriteLine("Connection ID: " + clientId, "Information");

var netStream = client.GetStream();
var reader = new StreamReader(netStream);
var writer = new StreamWriter(netStream);
writer.AutoFlush = true;

var input = string.Empty;
while (input != "3")
{
writer.WriteLine(" 1) Display Worker Role Information");
writer.WriteLine(" 2) Recycle");
writer.WriteLine(" 3) Quit");
writer.Write("Enter your choice: ");

input = reader.ReadLine();
writer.WriteLine();

switch (input)
{
case "1":
WriteRoleInformation(clientId, writer);
break;
case "2":
RoleEnvironment.RequestRecycle();
break;
}

writer.WriteLine();
}

client.Close();
}
[/sourcecode]

Finally override the OnStart() method and setup the RoleEnvironmentChanging Event.

[sourcecode language=”csharp”]
public override bool OnStart()
{
ServicePointManager.DefaultConnectionLimit = 12;

DiagnosticMonitor.Start("DiagnosticsConnectionString");

RoleEnvironment.Changing += RoleEnvironmentChanging;

return base.OnStart();
}

private static void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
{
if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
{
e.Cancel = true;
}
}
[/sourcecode]

Now run the role by hitting F5. When the application runs open up the Windows Azure Compute Emulator to check for the end point and verify the instances of the role are running.

Endpoint displayed in the Windows Azure Compute Emulator
Endpoint displayed in the Windows Azure Compute Emulator

The Service Name should be Windows_Azure_Web_Role, with an Interface Type of SampleWorkerRole running on the tcp://*:1234 URL and the IP is 127.0.0.1P:1234.

SampleWorkerRole
SampleWorkerRole

Click on one of the instances, which should be green, and assure that each has started up appropriately.

PuTTY
PuTTY

Startup a telnet application, such as Putty and enter the information in as shown in screenshot above.

Telnet
Telnet

Start the telnet prompt connecting to the Windows Azure Worker Role. The prompt with the three choices will display. Click to recycle and then display worker role information a few times, just to make sure all the information is available and the worker role telnet application service is working. Select 3 to exit out and the prompt should close while the role continues to run on the development fabric.

Gritty Technical Info on Windows Azure Web Roles

This is a follow up to the previous blog entry I wrote pertaining to Windows Azure Roles.  I wanted to cover the bases on the various technical aspects of creating a Windows Azure Web Role & Worker Role in Visual Studio 2010.  Without interruption let’s just dive right in.  Start Visual Studio 2010 and initiate a new project. File, new, and then project will open the new project dialog.

Windows Azure Project
Windows Azure Project

Select a cloud template type and name your project.  Click OK and the New Windows Azure Project Dialog will appear to select the role types you can choose from.

Windows Azure Project Templates
Windows Azure Project Templates

Select an ASP.NET MVC Web Application, name it appropriately, and then click OK.  When prompted for a test project select yes and click OK.  When the solution is finished generating from the chosen templates there will be a SampleWebRole ASP.NET MVC Web Application, the test project titled SampleWebRole.Tests, and a Windows Azure Project titled Windows Azure Web Role Sample.

Solution
Solution

After that run the application to assure that the Development Fabric & other parts of the web application startup appropriately.

With the web application still running, click on the Development Fabric Icon in the status bar of Windows 7 and select the Show Computer Emulator UI.

Show Compute Emulator UI
Show Compute Emulator UI

The Windows Azure Compute Emulator will display. Click on the Service Deployments tree until you can see each individual instance (the little green lights should be showing). Figure 4.6 shows this tree opened with one of the instances selected to view the status trace.

Windows Azure Compute Emulator
Windows Azure Compute Emulator

Select Shift + F5 to stop the web application from running.  In the Solution Explorer right click on the SampleWebRole under the Windows Azure Web Role Sample Project and select Properties.

Properties for SampleWebRole
Properties for SampleWebRole

Under the configuration tab of the SampleWebRole Properties set the Instance Count to 6 and the VM Size to Extra Large.

Windows Azure Instance Properties
Windows Azure Instance Properties

Now select F5 to run the web application again in the Windows Azure Development Fabric.  The Windows Azure Compute Emulator (if it is closed right click back on the status icon to launch it again) will now display each of the 6 instances launching under the SampleWebRole.

Windows Azure Compute Emulator
Windows Azure Compute Emulator

Click on one of the green lights to show that specific instance status in the primary window area.

Windows Azure Compute Instance 2
Windows Azure Compute Instance 2

When you select the specific instance the status of that instance is displayed. The instance that is displayed in figure 4.10 has a number of events being recorded with the diagnostics, MonAgentHost, and the runtime. This particular instance had gone through a rough start. During the lifecycle of a Windows Azure Web, Worker, or CGI Role there are a number of events similar to these that can occur.

Read through the first few lines. These lines show that another agent was running, which could be a number of things that conflicted with this web role starting up cleanly. Eventually the web role was able to startup appropriately as shown in the runtime lines stating that the OnStart() is called and then complete, with the Run() executing next.

Reading further through the diagnostics the web role eventually requests a shutdown and then prepares for that shutdown pending the exit of the parent process 6924.

These types of events are common place when reviewing the actions a web role will go through; generally, don’t get too alarmed by any particular set of messages. As long as the role has green lights on the instances, things are going swimmingly. When the lights change to purple or red then it is important to really start paying attention to the diagnostics.

Windows Azure Worker Roles

In the next blog entry (Part II) I want to show is how to add a worker role and how to analyze the activities within the role. The worker role is somewhat different than a web role. The primary difference between a web role and a worker role is that one is built around providing compute work, while one is built around providing web compute. Think of the worker role as something similar to a Windows Service, which runs ongoing to execute jobs & other processes, often backend type processes. A web role is what is built to host Silverlight and web applications such as ASP.NET or ASP.NET MVC.

Part II published on Monday the 17th.

Shout it

Windows Azure and the PaaS Context

PaaS stands for Platform as a Service.  The new concept around Devops* (Developer + Operations) has allowed cloud computing to reach an apex of agility for business.  For developers PaaS provides an ultimately clean and agile experience around staging and deployment.  PaaS is also the highest level of cost savings for most prospective enterprise and mid-size business users of the cloud computing services.  Windows Azure has positioned itself with the vast majority of its services as a platform.

Working with a platform, instead of an infrastructure based cloud computing service allows Devops to focus almost solely on the business problems.  In addition this prevents an unnecessary staffing level for IT in most organizations.  With staff re-focused on business problems and eliminating the majority of hardware issues in an organization costs go down while return on investment dramatically increases.

The Ideal PaaS Scenario, Athenaeum Corporation

Imagine a company, I’ll call it Athenaeum Corporation that has around 250 people and provides a web based on demand service.  Right now they have 4 geographically dispersed data centers that incur real estate, staffing, energy, and other costs.  In each of those geographically dispersed data centers there are network switches and dedicated web servers connected to clustered with failover databases.  Each set of clustered databases is setup to replicate among all the geographically disperse locations everyday on a near real-time basis.  The website that these locations host is then balanced by load balancers, which also require maintenance and administration.

The headquarters of this company is located away from the data centers, but has a smaller duplicate data center of its own that also receives replicated data and hosts the website.  This is for internal and development purposes.  The development team consists of approximately 45 people out of the 250 staff.  The network operations staff is about 25 people, with internal IT making up another 15 people.  Altogether the direct support of development and operations is 85 people out of a 250 person staff.

At the headquarters are approximately 280 machines ranging from desktop PCs to Laptops.  These machines are used to support operations, sales, accounting, support, and every other part of the company.  These 280 machines are connected to approximately 60 internal servers that provide things like Exchange Services, file sharing directories, communications on instant messengers, Sharepoint services, and other IT related tools.  In addition there are other switches, cabling, and other items related to the routing, load balancing, and usage of these internal services.

The Athenaeum Corporation that I’ve described is a perfect scenario that could literally save hundreds of thousands of dollars with cloud computing services.  While saving that money they could possibly increase their physical service, better their uptime & system processing performance, and more just by migrating to the Windows Azure Platform.

Before jumping into how a company like the Athenaeum Corporation might jump into PaaS with the Windows Azure Platform, let’s take a quick review of the services that the Windows Azure Platform provides.

The Platform of Windows Azure

The core Windows Azure Platform is made up of compute and storage.  The compute is broken up into Web, Worker, and CGI Roles.  The storage is broken up into Table, Blob, and Queue services.  All of these features have a platform SDK that can be used or RESTful Web Service APIs.  From the basis of an operating system, it is abstracted away and only the platform is of concern to development.

Beyond the core compute and storage elements the Windows Azure Platform cloud has the Windows Azure AppFabric and the SQL Azure Relational Database for service bus, security access control, and storage of highly structured data.  The AppFabric is made up of two core features; the access control and the service bus.  The SQL Azure is really just a clustered, high end instance of SQL Server running with a hot swappable backup that is managed by Microsoft in their data centers.

The Windows Azure AppFabric is one of the features of Windows Azure Platform that makes working with on-premises, internal, disparate, and Windows Azure Platform or other cloud services easy.  With the AppFabric access control security, claims based identification, and other authentication mechanisms may be used for seemless single sign-on experiences.  With the systems secured with the access control, the AppFabric service bus can then be used as a way to manage and keep communication between those disparate systems flowing and active.  The AppFabric Access Control & Services Bus provides a way to incorporate any request to incorporate systems that a business enterprise, government, or other entity may have.

With SQL Azure, a hosted, high end solution to relational data storage needs is provided.  One big concern is that the data sizes are to 50GB in storage.  Although the there is this 50GB limit, once this size has been attained the data most likely should not be contained solely in a relational data store.  This is when the other Windows Azure Storage mediums come into play.  But for data under 50 GB, a relational data store setup to work seamlessly in Windows Azure like this provides additional platform capabilities for developers to port traditionally hosted applications into the cloud with minimal changes.

Now that the platform is covered, how would the Athenaeum Corporation move their system & website operations into the Windows Azure Platform for increased capabilities and decreased costs?  The first thing needed is a breakdown of the individual systems and interoperations.

  1. Relational databases in each of the geographically dispersed data centers with failover databases.
  2. Headquarters has 280 PCs and Laptops.
  3. Headquarters has 60 internal IT maintained servers with custom applications, file-sharing, and other tools running on Windows Server.
  4. Load balancing is done for the web based on demand services in house.
  5. 4 Data Centers geographically dispersed with respective real estate, staffing, energy, and other costs.
  6. Network operations requires approximately 25 staff for 24-hour a day operational uptime.
  7. Web Based On Demand Services.

I’ll start breaking down these 7 key functionalities and state how the move to Windows Azure would change costing by using the platform.  Relational databases in each of these data centers can be moved in a couple different ways.

  1. One is to move the databases into one single primary SQL Azure instance.  Since the databases are most likely located at each of the datacenters for location CDN reasons, it made sense before, but with the move to the cloud the Windows Azure CDN could be used and the database would likely have better access to the geographically dispersed web presence points.
  2. The second is to move the databases to affinity points within the cloud that already match the current locations, porting the replication functionality for the specific data that each site needs.
  3. The 280 PCs and Laptops would still need connectivity and access to all of the existing applications they have now.  The cloud changes little in regard to this situation.  However redundant machines could be removed and with the implementation of SaaS based solutions, which I’ll discuss further in the next section, would dramatically decrease the cost of machines that each employee would need along with a decrease in support, administration, and maintenance of the software they currently use.
  4. The 60 internal servers at headquarters that IT maintains could be migrated completely, especially if they’re all running a Windows Operating System.  For anything that isn’t, one may want to look to AWS, Rackspace, or other virtualization solution at these cloud providers.  In Windows Azure internal servers hosting IIS applications could likely have them moved to Web or Worker Roles.  Anything such as Ruby on Rails, PHP, or Java that is hosted via IIS can be moved to a CGI Role in Windows Azure.  For anything that has other complexities and such can be installed on a Windows Azure VM Role.
  5. Current in house load balancing can be eliminated entirely.  There is no need for in house management of this with a PaaS like the Windows Azure Platform.  So mark this off the cost list, it is included in the cost of the service and requires no configuration, management, or other interaction.
  6. Each data center that previously provided geographic locations for the web presence can be brought into the Windows Azure Cloud.  There are two primary locations in North America at this time, and several more in other countries throughout the world.  With this ability the need to have 4 different data centers is removed.  In most cases, the centers that Windows Azure is located in also have significant security and penetration tests done at a physical level.  This effectively increases the security of each of the geographic access points.  Removing one more cost, while providing more for the money.
  7. Network operations, effectively simplified by the removal of routing, load balancing, and other concerns that needed to be done in house.  The cloud offers 24x7x365 operational uptime.  This eliminates the need for the in house staffing, with only a 4-6 staff needed for this particular scenario.  The roles and requirements for the 4-6 staffing positions would primarily be there to maintain data, assure that systems that are custom are maintained and operational within the Windows Azure Cloud.
  8. The last item is easily moved into the Windows Azure Platform using a Windows Azure Web Role.  This provides everything needed to operate a SaaS Web Application with the Windows Azure Portal PaaS.

On that last point of moving the Athenaeum Software into the Windows Azure Cloud, is SaaS on the Windows Azure Platform.

Windows Azure and the IaaS Context (or lack thereof)

Windows Azure has several primary competitors in the IaaS Realm, even though they aren’t technically an IaaS Cloud Provider at all.  Some of these competitors in this space are Amazon Web Services (AWS), Rackspace, GoGrid and VMWare.  Each of these providers offer virtual machines with either Windows or Linux Operating Systems, multiple data centers for geographically dispersed access, dynamic scaling, and other features associated with hosting infrastructure in cloud computing.

Some of the more dedicated infrastructure services provide content delivery, routing, load balancing, virtualized instances, virtualized & dedicated private clouds, DNS routing, autoscaling at an infrastructure level and more.  Some of the providers and their respective services are listed below:

Amazon Web Services Infrastructure Services

  • Amazon Cloudwatch enables Autoscaling.
  • Amazon Cloudfront is a content delivery network (CDN).
  • Amazon Route 53 for highly available and scalable DNS.
  • Amazon Virtual Private Cloud (VPC) for secure bridges into on-premises computing.
  • Elastic Load Balancing for distributing incoming application traffic.
  • SQS, or Simple Queue Service for messaging.
  • SNS, or Simple Notification Service for alerting.

Rackspace Infrastructure Services

  • Content Delivery Network (CDN)
  • Simple Load Balancing using virtualized server to provide load balancing.

GoGrid Infrastructure Services

  • Content Delivery Network (CDN) with a boasted 18 points of presence on 4 continents.
  • F5 Hardware Load Balancing
  • Data Center specific provisioning.
  • Autoscaling with Vertical RAM Scaling and more features.

Pricing IaaS

These companies offer a lower price point, which plays into the assumption that the user of the cloud services is skilled in setting up the needed networking, access, services, servers, and other things needed for each virtual machine launched within the respective cloud environment.  Some of the price points, especially in regards to Linux, are 1/3rd to 2/3rd the price of Windows Azure.

The Windows Azure advantage is at a higher price point, but lower total cost of ownership.  This advantage unfolds when operating in the dedicated development environment, but removing the networking and information technology arm of a company.  Basically, a company buys the cloud services from the grid just like they would the building power for their headquarters.  This leaves the generation of power, or simply the compute power, to a dedicated utility instead of having in house management of these resources.

Infrastructure Services

There are a number of companies in the technology industry today that offer infrastructure services.  Infrastructure services generally revolve around a few specific characteristics;

  • Content Delivery
  • Routing & Load Balancing
  • Virtual or Dedicated Private Cloud
  • Operating System Virtualized Instances

Windows Azure provides two primary infrastructure services.  Both of the services are somewhat minimal, since Windows Azure is focused on being a platform and not an infrastructure.  The service is the Windows Azure Content Delivery Network and the Windows Azure VM Role.

The content delivery network is provided as an add-on to the Windows Azure Storage to provide faster geographically dispersed access to data.  This increases the speed of access to the data and sties within the Windows Azure Cloud Platform.

Windows Azure VM Role

Windows Azure as marketed by Microsoft is not an infrastructure service.  However Microsoft has broken from being a pure platform only service with the Windows Azure VM Role.  The Windows Azure Platform is still primarily a platform service, but the VM Role has been provided with the intent of migrating customers that may need a full machine instance of Windows Server to run existing applications.  This enables an enterprise or other business to start migrating existing applications without a complete rewrite of those applications.

This enables the migration of applications that have long, non-scriptable, fragile installation steps to be moved into the Windows Azure Cloud Platform.  The VM Role does pose a possible distraction to developers, who should focus on developing applications against the Windows Azure Web or Service Roles.  This provides the greatest benefit and chance for savings over time.  In addition the roles are patched, and kept up to date by Windows Azure instead of needing hands on maintenance from the account holder or developers.

On a Windows Azure VM Role the operating system, updates, and other maintenance of the role are left up to the account holder.  Microsoft offers no automated patching or other support.  The VM Role must also be monitored by the account holder.  Windows Azure knows when the system becomes unresponsive but otherwise doesn’t act unless the system completely crashes, shuts down, or otherwise stops.

The VM Role is also advantageous when an account holder or developer needs elevated privileges for a particular application.  This however does not mean it is an encouraged practice to use elevated privileges for application development within Windows Azure.  But the VM Role offers the ability for those situations that are inflexible and require abrogation of good design principles.  This feature offers the ability to install MSIs, custom configure IIS, or otherwise manipulate the server environment for hosting needs.

One of the largest concerns with the VM Role is that the savings and decrease in maintenance associated with Windows Azure Platform managing the networking, load balancing, and other related infrastructure services.  The VM Role does not retain this automated level of management and at this time does not have load balancing or other features enabled.  Load balancing can be done externally to the Windows Azure Platform, but requires CNAME and custom DNS management in order to do so.

My Current Windows Development Machine Software Stack

I recently did a clean install of Windows 7 64-bit.  It had been a really long time since I listed the current tools, SDKs, and frameworks that I’ve been using.  Thus here’s my entourage of software that I use on a regular basis that is installed on my primary development machines.

Basic Software & System OS

Administration Utilities

Themes & Such

In addition to these packages of software another as important, if not more important to my day-to-day software development includes these software services and cloud hosting services.

SaaS, PaaS, and IaaS

Software I will be adding to the stack within the next few days, weeks, and months.