Earlier this week I did a presentation to the Brisbane Infrastructure Group (BIG) (twitter: #bigau) about the Windows Azure Platform. I want to say a ‘big’ thankyou to all those who attended and also to Avenade for supporting the event.

I’ve uploaded the slide deck as a zip file for you to peruse. I’ve also added annotations in the ‘notes’ section on most pages where necessary including extra links to articles of relevance.

Please note that this slide deck is a combination of slides from the Azure Training Kit, the PDC08 talk delivered by Erick Smith and Chuck Lenzmeier, and my own content. Please feel free to reuse anything you find within, except my humour. I only request a link back to this site in return.

Tags Tags: , ,
Categories: Azure
Posted By: Steven Nagy
Last Edit: 13 Nov 2009 @ 09 01 PM

E-mailPermalinkComments (0)

 05 Nov 2009 @ 7:04 PM 

I’ve done a couple behind closed doors for my Readify work mates and for various clients, but this will be my first presentation to the open public. I’ll be presenting on the Windows Azure Platform at the Brisbane Infrastructure Group in Brisbane Queensland (Australia for my international readers).

Those who know me know that, amongst other things, I am a developer. My work with Readify in a consulting manner is all development related to some degree. I love to code! For me to present to an Infrastructure group about Azure has many potential hazards. I might be lynched, have fruit thrown at me, or just simply no one will show up to the presentation. But still, I must spread the message!

Besides, I am confident that the prospect of hearing about an operating system for the cloud will be too much for these infra nerds to resist! So log off those domain admin accounts, tuck your shirts into your undies, and come along to hear all about the next generation of computing in the cloud!

Venue:

Microsoft Level 9, 1 Eagle Street, Waterfront Place

Time:

5:00pm for a 5:30pm start.

Date:

Tuesday 10th November 2009

Lifts close at 6pm! 

Close:

Session generally closes by 8:00 pm.

 

Please RSVP as soon as possible via this link or by emailing the BIG group at: bigau@live.com.au

Also, I will be awarding a prize based on the best developer or sys admin joke on the night!

Disclaimer: Prize may have no real value

Tags Tags:
Categories: Azure
Posted By: Steven Nagy
Last Edit: 16 Nov 2009 @ 09 37 PM

E-mailPermalinkComments (0)

 31 Oct 2009 @ 10:59 PM 

This posting may very well be banter. You have been forewarned.

Services

Everywhere I look I see services. I can get pizza delivered, my clothes dry-cleaned, and my shopping delivered to my home without ever leaving my computer. These are all services provided by someone, somewhere. A little closer to home I have my TV which delivers a digital service, radio which delivers an analog service, phone line which delivers a communication service, an XBOX which delivers an entertainment service, and even my kitchen counter, which props up the toaster and bowl of fruit, is performing a useful service.

Definition

Here’s a site I often use that provides a service that explains the meaning of words. The word I am interested in, surprisingly, is “service”:

an act of helpful activity; help; aid

Ok I ignored the other definitions but they all pretty much relate back to the concept of something, someone or some corporation doing something useful for others. Sometimes we pay for services, sometimes they are free. But really, services are there to help and form the cornerstone of our very society.

Now that you love services as much as I do, you’ll completely appreciate what this means in software engineering: A service is any code component that helps your application achieve completeness. It is not necessarily something that communicates over the wire, via named pipe or some message queuing application. It isn’t always found in the form of XML, JSON, or binary formats. Its just like your kitchen counter, a piece of code that provides a useful function to your application.

Too abstract?

I think we often get too wrapped up in someone’s interpretation of various buzz words and lose site of the meaning of the words themselves. I have no problems using the term ‘service’ in a way that relates in no way to objects going over the wire, WCF, ASMX, etc. Instead, our repositories, factories, presenters, controllers, managers, builders, all those code classes that have a single responsibility, they are all services. For example, in an app I am working on now for a client (ASP.Net, WCF, MS SQL) I am using the MVP pattern and am using IOC (Ninject). I wanted my presenters to be responsible for navigation, but didn’t want them to know anything about page urls. So I created a ‘NavigationService’ (with matching interface) with a simple ‘Navigate’ method on it. It takes a view ‘name’ and looks up the sitemap to work out where to navigate to. This works great because now my presenters are controlling page flow without knowing anything about how navigation works. Its highly testable since my NavigationService can be mocked out easily (thus the interface). You obviously don’t have to put the word ‘service’ in the name, its just sometimes helpful if your class can’t easily be classified as a repository, factory, etc. If you had ‘Helper’ somewhere, generally you could probably replace that with ‘Service’ since it means the same thing.

Service Oriented Architecture

Soa island in Tiree, Scotland

Yes SOA means Service Oriented Architecture, not Service Oriented Application, and certainly not Service Only Architecture, which is what some people seem to think it means even when they say the word ‘oriented’. The term ‘oriented’ means ‘aligned’ or ‘related’ and in my mind, the literal translation of the phrase means “an architecture where the majority of modularisation is achieved through services”.

OASIS is a standards group and has a reference model for SOA which states:

“Service Oriented Architecture (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains.”

When we hear the word ‘distributed’ in computing we automatically assume disparity and remoteness. But again if we look to our word salad service (dictionary) we get:

“to divide into classes”

Oh this is almost too easy! Of course it doesn’t mean software classes (example, plant species as classes of plant distribution) but it fits too well to ignore. And those capabilities are of course our helpers, repositories, etc. The last part of that statement says “that may be under the control of different ownership domains”. I guess the point here is that it doesn’t have to.

What’s your point?

Lets say I have a smart client application, WPF since that’s my drug of choice. I’ve broken it down into a main EXE and a separate DLL where I store all my repositories, builders, factories, presenters, etc. I go to great lengths to ensure everything acts like a service (as per my explanations above). All my capabilities are distributed into separate classes.

In this scenario, am I implementing a Service Oriented Architecture?

Well I’m overly focused on services, some services call others, each is defined by a contract (since I use IOC to locate and resolve them), the implementation is hidden behind the interface, and the only implementation not in a service is the UI. So as far as I’m concerned, the answer is yes!

The great thing about IOC and services in general in .Net is that you can easily turn one of those interfaces into a WCF service contract with very little effort. You want to ‘distribute’ over the wire? You can! The important thing is that you have control over how the services are surfaced.

So the final takeaway is this: consider SOA for every application you ever design. This doesn’t mean WCF, ASMX, named pipes, etc. It just means designing your application with individual services that take care of all your application needs. If you can do that, you will realise clean abstractions, encourage testability, improve maintainability, and create reusability. And I can assure you, once you adopt this style (and a good IOC container to help), you’ll never go back.

The Azure Part

Some of that service stuff above is not overly relevant to what I’m going to talk about next. But SOA in general certainly is. Windows Azure supports division of labour very well: If your services are all located within one application assembly, then just provision one web project. If you feel you need to scale out certain services due to work load, slap some service contracts on them and push them into a new instance of their own. Want to keep some of those services on premise? No problems, use the Service Bus to route requests to your on-premise services, easily skipping through those firewalls. Want your data in the cloud too? No problem, stick it in SQL Azure or just plain old Windows Azure Storage if necessary. Hell you could even put it in Amazon S3 if you wanted, Azure doesn’t care: it supports these service abstractions easily and doesn’t know if the service you are calling is hosted in Azure, on-premise, through the service bus, or some external service (eg. S3, Flickr, etc).

Summary

The point I am trying to make is that if you follow the SOA principles above, your application design will “just work” when you want to move to Azure. The applications that are hardest to move to Azure are those with tightly coupled components and leaky abstractions. Its certainly difficult to adopt this style of development at first and is certainly something that your architect should be involved in continuously (code reviews, etc). But even if you don’t plan on moving to the cloud, its a great way to build your applications and helps you benefit in the long term. Once you get used to the style, it certainly improves your development speed, and removes dependencies on the components being built in other teams. And it certainly works well for large and small projects alike.

Tags Tags: , , ,
Categories: Azure
Posted By: Steven Nagy
Last Edit: 31 Oct 2009 @ 10 59 PM

E-mailPermalinkComments (0)

 26 Oct 2009 @ 4:29 PM 

Firstly this is pure speculation. Either that or it is known fact and I am behind the game (I’ve been out of action for a couple months, you may have noticed my absence in blogging). If I am the first person you have heard this from, then there is every chance that it is false, so once again, this is just speculation.

Recently there have been a spate of questionnaires going out to Azure consumers/clients. Being a good CTP user and evangelist of the platform, I filled out every single one that came my way. Some took hours, some took minutes. But while it would seem that Microsoft were collecting information from me, it also alluded/hinted at some features that might be released by Microsoft sometime in the future. This post is simply identifying those features that have already been discussed in those surveys.

Get on with it already

The feature name currently is ‘Managed VM Role’ and would essentially be an instance that you could remote to like any other server. This would fall into direct competition with GoGrid/EC2 type hosting where you provision server instances and get full terminal services access to the instance. In this case it would be custom Server 2008 instances that could still be managed by the Fabric Controller. Microsoft summarises the concept like so:

‘A mechanism to snapshot an entire application environment and create a Windows VM to be deployed and managed by Windows Azure together with the relevant data, registry settings, and the ability to choose and control OS versioning. In this case, the customer is responsible for installing security patches, OS updates, and upgrades by creating a new image snapshot updating the running VM roles using the Windows Azure upgrade facility’.

This would work in harmony with a ‘Managed Application Role’ which basically sounds like what they are already doing with Windows Azure, however it also hints at using a packaging facility like MSI for the deployment process. Also some elevated privileges might be possible in the final release (currently you can run in full trust but under a restricted user account).

Anything Else?

There’s a few other smaller bits and pieces hinted at, summarised below:

  • Cloud Storage Explorer (although there are already good candidates)
  • Better deployment story from Visual Studio (I’d like to see MSBuild tasks)
  • Better deployment feedback (provisioning process for example)
  • Design surface for your service oriented application (this would be way cool)

 

Remember as I said before, its all speculation at this point.

Tags Tags: , , ,
Categories: Azure
Posted By: Steven Nagy
Last Edit: 26 Oct 2009 @ 04 29 PM

E-mailPermalinkComments (1)

Foreword: Apologies for the title, I’m still not sure (after completing the entry) what it should be called.

Why would I use the Windows Azure Platform? Its a good question, one that I’ve had a lot of internal discussions on lately (fellow consultants from Readify). For most its quite a paradigm shift and therefore difficult to grok. Many believe that you can only build Azure apps from scratch and that it would be a lot of work to convert an existing product to use the Azure platform. I don’t want to say this is a false statement, but Azure is pretty big, bigger than most people realise.

I Can’t Use Azure Because…

Most of us are only familiar with the Windows Azure component which allows you to host either services or web pages. Most custom applications require a data store and for Microsoft developers, this tends to be SQL Server. Unfortunately there is no one-for-one mapping to easily port your database over to the data stores in the cloud (Windows Azure Storage, SQL Azure, etc). This means people feel resistance when they do consider the Azure services and write-off the whole platform.

When SQL Azure is presented as an option, people tend to pick on the little features that are missing, expecting a direct cloud equivalent for their data. But some things just don’t make sense for SQL Azure. People lose context: SQL Azure is a service. It should be treated like any other service within your architecture. You don’t need to be implementing the next service related buzzword (SOA, SaaS, S+S, etc) to get the benefits of the abstractions provided by services. If you build your services in an autonomous fashion, SQL Azure will fit right in with your story.

What about off vs on-premise data storage? I hear this one a lot as well. I want to control my data, I have no need for Azure. This is an easy answer for me, and I defer back to my last statement. Its a service driven world, your data should be the same. Where that service is located should be irrelevant. This is where the .Net Services ‘Service Bus’ steps up. It can route your data to your other services/applications extremely easily, with top level security all the way, so not even Microsoft can see what is being transmitted. What about my firewall, it will stop people from seeing my service right? No problem – the service bindings use outbound connections to connect to the Service Bus, meaning that you can host your own services on-premise, behind your firewall, and still get flawless connection to/from the cloud.

The Next Step In Developer Evolution

Modularity, loose-coupling, single-responsibility.. any of these terms ring familiar for you? As a developer I enjoy building applications that realise these design qualities. I use Inversion of Control and Dependency Injection wherever possible, and have realised that my code classes have somewhat turned into services. Not like ASMX or WCF services; just classes that have very defined purposes, are abstracted by a contract (interface), and provide a service to the rest of the application.

I won’t lie, since being introduced to IoC my programming style has changed, and I think that this happens for most developers who use it as well (regardless of implementation technology or language). You start viewing everything as services, even your Views (since we all love MVP, MVC, and MVVM). Quite often when I’m with a client discussing aspects of an application I might say “.. so we’ll just create a service for blah…” not realising that it might have a different meaning to them (however its not long before they agree with me and start referring to things the same way!).

imageSo I honestly believe that services are the next level of developer evolution (“devolution” anyone?), whether we mean actual web services or just classes that service our application. For me this even brings about new meaning for Service Oriented Architecture – design your systems to be service based whether those services are across the wire or not.

<Disclaimer> I am an advocate of smart clients and believe everything should be services and that web pages are evil and should only exist to help find smart clients</Disclaimer> 

So I Have To Redesign My App As Services?

Yes. Well no, but you should certainly think about it for all new applications, regardless of whether you are considering Azure or not. I honest believe it is just good design. As for existing apps, consider the key dependencies. These might be file storage, relational database, data mining, 3rd party components, etc. Write a list and detail each one individually. Is their a mechanism you can use to abstract the calls to that dependency? Perhaps IoC will work for you, or perhaps the ASP.Net Provider model will help you. Or perhaps you just need to wrap the calls up in a new class in a separate assembly.

The next step is how those dependencies will work in the cloud. Do you need to replace any? Can they also be moved to the cloud? Do they need to be rewritten as services? Do you need to expose their functionality from within your organisational boundaries? This is where a lot or a little work may need to happen. Those applications that already have looser coupling will find this part easy. For example, you may already have a class that handles your database calls. A customer class might have a create, update, and delete methods, which wraps calls to LINQ to SQL (L2S). Well its very easy to indentify your customer class as the service boundary, and move the L2S code to a new service. All you need now is to think about the security and you’re done!

Once you have a firm plan for dealing with those dependencies, the rest should be a piece of cake. Obviously what happens next will differ for web and smart client apps, but the dependencies are really the most difficult thing. When you have hard wired dependencies to 3rd party solutions (eg. K2) you might find that it is very difficult making the transition to Azure.

What About Products?

Well the same rules apply, only that you might get an added benefit from creating products that can easily by run on Azure. For example, check out SplendidCRM – a CRM product recently refactored to run on Azure. Why? Well what if you want a CRM product but don’t want to host it yourself? Kinda seems smart to me… allow the purchaser of your software to run it anywhere they choose, on or off premise. And then of course there is the multi-tenant applications designed to only run in the cloud, like Saasu and Salesforce. If you want to go viral, you need to be prepared to scale quickly!

Summary

Its hard to say exactly when you should consider Azure, but I guess the point of this post is not so much to answer that question, but rather to provide you with some insight into good design techniques, that when followed properly, will provide you with an application that can easily be deployed into Azure, or any other cloud platform for that matter. If we’re doing things right at the bottom level, then we can be flexible with the higher level architectural choices.

So please check out the links for any of the concepts I’ve mentioned above (or listed below) to ensure you and your team are familiar with them. And if you have any questions, please feel free to email me.

Some more links:

Tags Tags: , , , , ,
Categories: Azure
Posted By: Steven Nagy
Last Edit: 25 Oct 2009 @ 07 17 PM

E-mailPermalinkComments (0)

 26 Aug 2009 @ 1:42 PM 

Just a quick post to let you know about CloudCamp Sydney: its on tomorrow! (27th August 2009)

Register here:
http://www.cloudcamp.com/?page_id=1045

Unfortunately I can’t make it.

Tags Tags:
Categories: Cloud
Posted By: Steven Nagy
Last Edit: 26 Aug 2009 @ 01 42 PM

E-mailPermalinkComments (2)

 23 Aug 2009 @ 10:13 AM 

I recently received an email asking what the migration story is like for moving apps onto the Azure Services Platform, and I wanted to share my answer (which is only my opinion) with you all.

The thing about Azure is that it is an application platform. This means there’s certain interactions that are required in order to get your apps onto Azure.

In my opinion Azure is best suited for SOA, SaaS and S+S type applications; those that are heavily componentised and can exist within their own right. If your architecture is decoupled in this way then the migration to Azure becomes a lot easier. The service definition file that you package with your Azure Cloud Package is just that: a summary of all your various services and how you want them configured in the cloud.

We used to have cables like this for connecting our printers and scanners before USB came along. They were known as parallel cables and connected to your computer's parallel portCertainly ASP.NET and WCF applications are the easiest to move. I would see moving to Azure as an opportunity to decouple your applications and focus on SOA. Determining an amount of work for any app will be difficult, but in nearly all reasonably sized applications it won’t be as easy as copy/paste.

The majority of developers in the modern age are not overly experienced at building scalable, parallelisable applications. Most applications are not designed to handle multi-threaded, multi-instance scenarios.  While this isn’t an inhibitor, it does mean it’s difficult to leverage the platform effectively, and it means that a product owner of an existing product is more likely to need to scale by instance (add another server/instance) when in fact they aren’t leveraging their current instances effectively.

Herd migration

I don’t think that moving to the Azure platform by plonking in the files is the best strategy. I’d like  to think that it would fall into a ‘sprint goal’ to make any application able to leverage the Azure platform, and I think that would include a strong services aspect. Any large application will require a migration plan for any kind of move. Sometimes if you are even moving an application around in your own data centre, it can require weeks of planning. Azure is certainly the same, except that the migration may also require some development effort.

One final thing to think about is of course domain name pointers. In on-premise scenarios you already have your network sorted out, but in the cloud you need to think about what will be public facing, and what your naming strategy will be.

I don’t think we’ve seen the end of the Azure feature releases and I’m sure there will be something in the final release that will make the whole migration process easier.

Tags Tags: , ,
Categories: Azure
Posted By: Steven Nagy
Last Edit: 27 Jan 2010 @ 07 27 AM

E-mailPermalinkComments (3)

I’ve seen a few demos of Windows Azure and one of the common themes I see around the worker role is that people want to demonstrate scalability through increasing the number of instances in their service definition. That’s fine but we need to also remember that we are scaling up an entire virtual machine each time we increase our instance count, and maybe that just isn’t necessary when we consider parallelization instead.

When we create a new worker role, we get some boiler plate code that guides us into overriding the “Start” and “GetHealthStatus” methods. The latter is irrelevant to this discussion; the former is more important. The default template constructs the Start method in a way that indicates it should do some work and then Sleep.

public override void Start()
{
    while (true)
    {
        // Do Work
        Thread.Sleep(10000);
    }
}

The problem with this convention is two-fold. First, it assumes that one worker should be performing one role, but that’s not the case a lot of the time. Secondly, it doesn’t leverage parallel processing, in particular multi-threading.

The next obvious step is to break up your Start method and kick of multiple threads, each working on their own little piece of the application. But this kind of code is quite common, and I thought, wouldn’t it be better if we could just focus on what our individual application roles are without needing to think about how many workers/instances we need, and whether or not each of those roles should be run multi-threaded?

Thus, the need for a framework (although I shudder at the term) to help us separate that logic, and to provide some common classes to aid with parallelism. I’m not great with names, but for this release, I’ll call it: “WorkSharing”.

So What Does It Do?

The WorkSharing assemblies let you focus more on the roles of your application, the work that actually needs to be done, and it keeps this separate from when/where the work occurs.

You begin as usual by creating a Cloud application with a worker role. For the moment we don’t need to think about the worker role itself; instead we want to focus on what actual work our application needs to perform. We create a new class for every unit of work we need to do. In this example we’ll save time and create just one worker who will be instantiated a few different times.

public class MyCustomWorker : IWorker
    {
        private readonly string name;
        private static Random random = new Random();

        public MyCustomWorker(string name)
        {
            this.name = name;
        }

        public bool HasWorkToDo() { return true; }
        public void DoWork()
        {
            RoleManager.WriteToLog("Information", name + ": Before sleep");
            var wait = random.Next(700, 1200);
            Thread.Sleep(wait);
            RoleManager.WriteToLog("Information", name + ": After sleep");
        }
    }

The key is implementing the IWorker interface – this forces your class to expose two methods: “HasWorkToDo” and “DoWork”, both fairly self explanatory. The actual work that our class performs is two log entries with a random period of sleep in between. This will help us show the async work being performed later on.

Here is where you would define all the workers for your application. These don’t have to be in the same project as your cloud worker role – in fact it usually won’t be. If the roles are small but numerous, I’d put them in their own project. If they are each very large, you’d probably have one project per role. Either way, we’ve focused our attention on the work that needs to be done without coupling it with the “where” and “when”.

Heading back to our Azure worker role, we need to make some changes to the default template code. Strip out the override methods (although you can leave the health status override if you have special logic that needs to go there). We then change the inheritance of the worker role. Currently it inherits from ‘RoleEntryPoint’ but we will change this to ‘WorkSharingRole’ instead – this is a new class in the WorkSharing assemblies.

We want a parameterless constructor for our worker role as well, and it is in here that we define what it needs to do and how to do it. Here is some code illustrating sample usage of our custom worker:

public class WorkerRole : WorkSharingRole
{
    public WorkerRole()
    {
        base.SleepTime = 1000; 
        base.PrimaryWorker = new MyCustomWorker("Custom");
    }
}

Let’s step through the code. First, you can see that our worker inherits from ‘WorkSharingRole’ as mentioned before, and we have a parameterless constructor where we refer to two properties on the base class. ‘SleepTime’ is essentially the period (in milliseconds) between “executions” (a term I will explain further in a moment). The ‘PrimaryWorker’ property is of type IWorker which means we can assign our custom worker to it. That’s all that’s needed to get up and running, and when we fire it up, we can see in our development fabric the output from our worker role:

07/13/2009 03:48:38:648,Event=Information,Level=Info,ThreadId=4316,=Custom: Before sleep
07/13/2009 03:48:39:695,Event=Information,Level=Info,ThreadId=4316,=Custom: After sleep
07/13/2009 03:48:40:695,Event=Information,Level=Info,ThreadId=4316,=Working
07/13/2009 03:48:40:695,Event=Information,Level=Info,ThreadId=4316,=Custom: Before sleep
07/13/2009 03:48:41:744,Event=Information,Level=Info,ThreadId=4316,=Custom: After sleep

 

Ok so there’s nothing special there just yet, we haven’t really change much of the face of our app except that we’ve hidden away the loop. However there are a number of other IWorker implementations that are part of the WorkSharing assemblies, and it is these guys that will let you easily parallelize your work. Consider this change to the constructor:

public WorkerRole()
{
    base.SleepTime = 1000;
    base.PrimaryWorker = new WeightedWorker()
        .Add(new MyCustomWorker("AAA"), 2)
        .Add(new WaitingAsyncWorker()
            .Add(new MyCustomWorker("BBB"))
            .Add(new MyCustomWorker("CCC")));
}

Here we’ve introduced two new classes: WeightedWorker and WaitingAsyncWorker. The WeightedWorker allows us to state how often the worker role should be focusing on this particular task. it acts much like a ratio. In the above example, the WeightedWorker accepts a custom worker called ‘AAA’ with a weight of “2”, and a WaitingAsyncWorker with a weight of “1”. This means the custom worker will be called twice as often.

The WaitingAsyncWorker is one of 2 kinds of async workers that let you parallelize your work. In this case, it takes two custom workers, ‘BBB’ and ‘CCC’ which it will execute side-by-side. The WaitingAsyncWorker will then wait for both its children to finish executing.

Here’s the output you would see in the development fabric:

07/13/2009 02:37:06:688,Event=Information,Level=Info,ThreadId=5624,=AAA: Before sleep
07/13/2009 02:37:07:755,Event=Information,Level=Info,ThreadId=5624,=AAA: After sleep
07/13/2009 02:37:07:755,Event=Information,Level=Info,ThreadId=3528,=BBB: Before sleep
07/13/2009 02:37:07:755,Event=Information,Level=Info,ThreadId=5452,=CCC: Before sleep
07/13/2009 02:37:08:606,Event=Information,Level=Info,ThreadId=5452,=CCC: After sleep
07/13/2009 02:37:08:947,Event=Information,Level=Info,ThreadId=3528,=BBB: After sleep
07/13/2009 02:37:08:947,Event=Information,Level=Info,ThreadId=5624,=AAA: Before sleep
07/13/2009 02:37:10:061,Event=Information,Level=Info,ThreadId=5624,=AAA: After sleep

07/13/2009 02:37:11:062,Event=Information,Level=Info,ThreadId=5624,=AAA: Before sleep
07/13/2009 02:37:12:236,Event=Information,Level=Info,ThreadId=5624,=AAA: After sleep
07/13/2009 02:37:12:236,Event=Information,Level=Info,ThreadId=3528,=BBB: Before sleep
07/13/2009 02:37:12:236,Event=Information,Level=Info,ThreadId=5452,=CCC: Before sleep
07/13/2009 02:37:13:291,Event=Information,Level=Info,ThreadId=3528,=BBB: After sleep
07/13/2009 02:37:13:413,Event=Information,Level=Info,ThreadId=5452,=CCC: After sleep
07/13/2009 02:37:13:413,Event=Information,Level=Info,ThreadId=5624,=AAA: Before sleep
07/13/2009 02:37:14:245,Event=Information,Level=Info,ThreadId=5624,=AAA: After sleep

As you can see, the ‘AAA’ task executes twice, whilst tasks ‘BBB’ and ‘CCC’ could happen in any order and are both starting before the other finishes.

There are 2 other predefined workers in the WorkSharing framework. The ContinuousAsyncWorker also operates in an asynchronous fashion, however where the WaitingAsyncWorker will wait for all its children to finish before itself finishing, the ContinuousAsyncWorker will continuously keep working all of its children over and over. When each child finishes its work, it will kick off a new thread to start it again. This makes it a little different from all the other workers because it never really finishes its DoWork method – it just keeps kicking off its children over and over. For this reason, the DoWork method will return immediately after being called.

The final worker worth mentioning (or perhaps not really) is the LinearWorker which simply performs a number of tasks in the order defined. You can think of it as similar to the WeightedWorker except that it only fires off its children once each.

Is That A Fluent Interface I Doth Behold?

Yes and a meager one at that. Only the Add method will return the same object, letting you chain your adds together. But more important here is that you can make all workers children of other workers. In the above example we saw a WeightedWorker own a WaitingAsyncWorker. You could have any number of workers owning any others, as many levels deep as you want. It also lets you be creative – you might need to dynamically discover what work this worker will perform.

You Didn’t Explain ‘Executions’ Yet

Lets take the WaitingAsyncWorker from our example. The total amount of work that needs to be done by this worker is:

  1. Start all of its children
  2. Wait for all of its children to finish

After this, it has completed its DoWork method, which means it has completed its ‘Execution’. It may or may not get fired again. Now consider the WeightedWorker – its total sum of work is:

  1. Randomise the order of its children
  2. Call each of its children one at a time, waiting for each to finish before proceeding

… after which it has completed its execution. However in this example, its execution includes the execution of the WaitingAsyncWorker and all its children.

The top of the hierarchy is always the PrimaryWorker property of the WorkSharingRole class. Therefore its execution includes the execution of both the WeightedWorker and the WaitingAsyncWorker and all their children.

Between each execution of the PrimaryWorker there is a user defined pause. This is simply a Thread.Sleep call and defaults to 0 which means it won’t sleep between executions (which is a perfectly valid scenario).

Anything Else I Should Know About The Internals?

When the base WorkSharingRole class starts an execution, it calls the HasWorkToDo method on the PrimaryWorker. If the result is true then it proceeds to call the DoWork method. In the case of the prebaked workers, all calls to HasWorkToDo will actually forward the checks onto their children. If any child has work to do, it returns true – this is important because these workers don’t have any work of their own to do, they just call out to their children.

Likewise, when DoWork is called on one of the prebaked workers, it will in turn call the DoWork methods on its children (as per the descriptions given of each earlier).

Summary

You can download the framework here (full source and example applications including an Azure worker and a console app). Its free to use but I’d like to know how you think it can be improved. So far here is the list of things I’d like to add:

  • Events to hook into (such as OnInitialized and OnStart) [I don’t like the dependency on constructor]
  • More workers such as a worker where you can specify the number of repetitions of a task
  • Ability to change the worker hierarchy after the worker role has started
  • Configurability of worker hierarchy via XML

Please let me know what you think and have fun playing.

DOWNLOAD

Tags Tags: , , , ,
Categories: Azure
Posted By: Steven Nagy
Last Edit: 14 Jul 2009 @ 08 26 AM

E-mailPermalinkComments (2)

Very recently David Lemphers posted about one of the cool methods of debugging available in Windows Azure. In his blog post he talks about a method of spinning up a process that can execute command line type requests via the Process class, and then pushing the output back to your webform.

Its an excellent example of what you can do under full trust in Windows Azure. I liked this demo of David’s so much that I decided to throw it together quickly myself to have a play. David only shows a snippet of the code he used, so I thought I’d post the whole thing as a single ASPX file (no code behind) that you can just plonk into your cloud app. Remember to set ‘enableNativeCodeExecution’ to ‘true’ in your service definition file before attempting to use this diagnostic page.

Have fun, and thanks David

(create a new diagnostics.aspx file with no code behind, and copy this into its contents)

<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Diagnostics</title>
    <script language="CS" runat="server">       
        protected void btnRun_Click(object sender, EventArgs e)
        {
            var newProc = new System.Diagnostics.Process();

            newProc.StartInfo.UseShellExecute = false;
            newProc.StartInfo.RedirectStandardOutput = true;
            newProc.StartInfo.FileName = "cmd";
            newProc.StartInfo.Arguments = "/c " + txtInput.Text;

            newProc.EnableRaisingEvents = false;
            newProc.Start();

            txtOutput.Text += String.Format("{0}\r\n", newProc.StandardOutput.ReadToEnd());

            newProc.Close();
        }           
    </script>
    <style type="text/css">   
        textarea { width: 800px; }
        textarea.CommandOutput { height: 600px; background: black; color: White; }   
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>   
        <asp:ScriptManager ID="ScriptManager1" runat="server" />       
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                Output: <br />
                <asp:TextBox id="txtOutput" runat="server" TextMode="MultiLine" CssClass="CommandOutput" /><br />
                <br />

                Input: <br />
                <asp:TextBox id="txtInput" runat="server" TextMode="MultiLine" CssClass="CommandInput" /><br />
                <asp:Button ID="btnRun" runat="server" Text="Run" onclick="btnRun_Click" /><br />
            </ContentTemplate>
        </asp:UpdatePanel>   
    </div>
    </form>
</body>
</html>

Tags Tags: , ,
Categories: Azure
Posted By: Steven Nagy
Last Edit: 13 Jul 2009 @ 12 56 PM

E-mailPermalinkComments (3)

 03 Jun 2009 @ 7:40 PM 

 

azurebox I’ll admit, I was one of the first to lash back (in a nice way) at Microsoft about only letting US residents participate in their Azure programming competition. After all, the cloud is about all the internet right?

Well Microsoft has heard the call! The new CloudApp() competition is now open to residents, no matter how you are geo-located.

This is good news for me personally because it will twist my arm into delivering on an idea I’ve had for some time, and its also good news for the greater community of course, with a cash prize and Azure fame for the winner.

So check out the website now for the T&C’s and get that cloud app happening ASAP!

Tags Categories: Azure Posted By: Steven Nagy
Last Edit: 03 Jun 2009 @ 07 40 PM

E-mailPermalinkComments (0)

\/ More Options ...
Change Theme...
  • Users » 76
  • Posts/Pages » 38
  • Comments » 47
Change Theme...
  • VoidVoid
  • LifeLife
  • EarthEarth
  • WindWind « Default
  • WaterWater
  • FireFire
  • LiteLight
  • No Child Pages.