By Denis, a .NET Developer on Murano Software’s team
The growing popularity of cloud computing can easily be explained by the high ROI that users get. In contrast to using SOA, with cloud computing, users receive a great number of benefits with minimal capital expenditures. According to many studies, the main advantages of cloud technologies are the reduction in the costs of building and extending on-premises resources, the reduction in the effort and costs of IT management, and the increase in flexibility and scalability. There is no question that cloud computing is going to play a big part in the future hosting, scaling and managing of Web applications. Microsoft introduced a new operation system, Windows Azure, as “a cloud service operation system that serves as the development, service hosting and service management environment for Windows Azure platform”. The goal of Windows Azure is to provide developers “with on-demand compute and storage to host, scale and manage Web applications on the Internet through Microsoft® data centers”.
As a software development outsourcing company, Murano Software has always been on the cutting edge of technology. This has enabled us to develop successful Web-based software solutions quickly and make our customers happy. That’s why we probed into Microsoft’s cloud computing immediately after the initial presentation of Microsoft Windows Azure - Community Technology Preview (CTP).
We aimed at designing such a solution that would ensure real-time Web collaboration for multiple users. The solution had to be based on the Windows Azure platform and generalized into a framework.
The implementation of this solution gave us a good sense of Windows Azure technologies, capabilities and limitations.
1. Capabilities and limitations of various Azure technologies
During the exploration phase of the project, we analyzed the capabilities and limitations of various Azure technologies. The main parts of Microsoft’s Windows Azure platform are the following cloud technologies:
- Windows AzureCompute service
- SQL Azure (Learn more)
- .NET Services (Learn more)
The Compute service runs applications and provides two different “instance” (virtual machines) types for developers to use: Web Role Instances and Worker Role Instances. Web Role can accept incoming HTTP and HTTPS requests, but can’t initiate its own request for output. Windows Azure can’t ensure that multiple requests from the same user will be sent to the same Web Role. So the Web Role must be stateless to make an application scalable, and any client-specific state has to be written to Windows Azure storage, SQL Azure or passed back to the client after each request. Worker Role can’t accept requests from the outside. As a rule, it gets input via Queue (see figure 1). Worker Role can send output to outside via Queue or outside connections, and it is used for batch work.
Windows Azure storage is exploited to exchange data between different parts of an application, and it provides developers with blobs, tables and queues. Blobs are used to save binary data up to 50 gigabytes. Tables aren’t relational tables. They contain a set of entities with properties. A table has no fixed structure, so one table can contain entities with different amount of properties. Different entities can even have some properties that have equal names, but different types. A single table can hold terabytes of data. Windows Azure storage offers a way to partition a table between many servers to improve performance. It can be done by using different partition keys for different groups of data.
The main goal of Queue is to allow communication between different parts of Windows Azure applications. So Queues provide a way for Web Role Instances to communicate with Worker Role Instances. Data that’s part of a Queue’s message can reach up to eight kilobytes, which isn’t much, in fact.
2. Preliminaries (Solution concept)
We have to solve several tasks to find a solution that will allow multiple users to cooperate:
- What technologies of Windows Azure platform have to be used to process server side work?
- How to notify a user of changes made by other users in a system.
2.1. Technologies of the Windows Azure platform we use
Microsoft suggests we use Web Roles only for simple work processing, while Web Roles and Worker Roles should be used in conjunction to process time-consuming work. We decided to implement both variants in our solution to process simple and complex work. Then we implemented a simple mechanism of switching between the two variants, which entrusted a decision on task complexity to a developer.
When we use Web Role only, everything is simple. Let’s look at the variant when Web Roles and Worker Roles are used in conjunction (see figure 1).
Figure 1. This is the general scheme of the Compute service work originally offered by David Chappell.
Sending a lot of data to Worker Role makes Queue vulnerable. We decided to use a blob to save both input and result data for Worker Role. A link to this blob can be saved to Queue. Thus we avoid the Queue’s restriction.
Users communicate with Web Role using WCF, so each operation contract in Web role is the work requested by the user. If Web Role carries out simple work then everything is clear. But how will Worker Role know what kind of work it has to perform? Taking into account that our solution has to be generalized into a framework, we decided to implement the following interface:
public interface ITask : ICloneable
{
// Date and time of task created
DateTime CreatedDate { get; set; }
// Task’s unique identifier
Guid TaskId { get; set; }
// Property defines usage of background processing
bool IsBackgroundProcessing { get; set; }
// Current state of a task: Success, Skipped, Postponed, Failed, Unknown
TaskState State { get; set; }
// Property used for saving task’s result
object ResultData { get; set; }
// Property used for saving task’s input data
object InputData { get; set; }
// Property used transfering exception, occured while task execution
Exception ExecutionException { get; set; }
// Method defines essence of the task
object Execute();
}
Figure 2. General task interface
Developers have to implement a class that inherits from the interface. Execute method of the class determines work that has to be processed by an application based on our framework.
Using the interface gives us the following advantages:
- A developer needs only to implement any logic in Execute method without any changes in the framework.
- Class can be serialized and sent to Worker Role from Web Role via Queue. Thus any free Worker Role can get the class, deserialize it and run Execute method.
- Implemented class can be performed either by Web Role or Worker Role. A developer can choose which type of Role processes work. The IsBackgroundProcessing property determines what kind of processing has to be done.
Our framework implements various applications to allow multiple users to work together while the code is not changed inside the framework.
Any modern application can’t work without a database. Microsoft provides two types of storages: SQL Azure and Windows Azure storage. Usage of SQL Azure is similar to SQL Server. So Azure storage is more interesting for us as part of the Windows Azure platform. We decided to use Windows Azure storage in our solution. We implemented a mechanism that allows creating tables in Azure storage in the simplest way. This is a BaseEntity class implemented in the framework.
public abstract class BaseEntity : TableServiceEntity
{
protected BaseEntity()
{
CreatedDate = DateTime.UtcNow;
}
public DateTime CreatedDate { get; set; }
protected abstract void RebuildBuildRowKey();
}
A developer only needs to implement his own class that inherits from BaseEntity to determine a table in Azure storage.
public class ShapeEntity : BaseEntity
{
public string ShapeType { get; set; }
public long Color { get; set; }
public double Thickness { get; set; }
public double Opacity { get; set; }
public string XYPoints { get; set; }
public string BoardName { get; set; }
// This method can be overriden to implement
protected override void RebuildBuildRowKey()
{
throw new NotImplementedException();
}
}
A developer implements context that creates all tables.
public class PaintContext : TableServiceContext
{
public const string BoardTable = "Boards";
public const string ShapeTable = "Shapes";
public PaintContext(string baseAddress, StorageCredentials credentials) : base(baseAddress, credentials)
{ }
public IQueryable Boards
{
get { return CreateQuery(BoardTable); }
}
public IQueryable Shapes
{
get { return CreateQuery(ShapeTable); }
}
}
2.2. User notification
The solution that allows multiple users to cooperate has to include a mechanism to notify users of changes. Let’s call any work requested by a user a task. We considered three cases:
- One table is used for all tasks. Each task has a status showing if a task is completed or is in use. Each Web role makes requests to this table and checks the presence of tasks completed. If there is a completed task, then the task’s result is sent back to the user.
- Web Role creates new Queue for each user who makes request to it. The notification “task completed” will be added to all users’ Queues when a task is completed. Web Role checks these Queues to see if there is any notification of a completed task in loop. Web Role gets a link to a blob, which contains result data from the notification and sends it to the user.
- .Net Service Bus can be used to notify users or Web Role of the task’s completion.
We decided include the first and third cases in our solution. The first option is easy to implement, but produces a high load on the Storage Service, while a lot of Web Role Instances are constantly pulling the table. But the table contains all history of performed work. It can be used in a decision-making process about the sequence for the different tasks performing the same actions. Usage of .Net Service Bus is more complex in implementation, but it allows you to notify a user of the task’s completion either directly or through Web Role.
2.3. Other features implemented in the framework
It is worth mentioning that Worker Role is a virtual machine (VM). This VM uses one of the processor’s cores. There may arise a situation when our processor’s core isn’t being used fully. For example, Worker Role is calling outside services, such as the storage service or other services in the Internet, is waiting for a response. The processor is idle while waiting for a response. We implemented a simple mechanism to manage several threads under one Worker Role Instance. It allows you to load Worker Role as much as possible.
3. Overview of solution generalized to framework
Web Role accepts a request and selects one of the classes inherited from the task, depending on the called operation contract. Then the class's TaskId, InputData and IsBackgroundProcessing properties are filled by new Guid, Input data and IsBackgroundProcessing flag from the request. This class is put to a task manager where the class’s properties are saved to the Task table. Then the task manager either runs the class’s Execute method or sends the class to Worker Role.
Let’s look at the case when Web Role runs Execute method by itself. Web Role calls Execute method of the current instance of class and saves the results to a blob. It saves a link to this blob and updates the status into a Task table for the current instance of class. Web Role returns the result data to the user as a result of the called operation contract.
Now, let’s look at the case of using background processing. Task Manager saves the class’s InputData to a blob with the name “InputData”+TaskId, and a link to that blob is saved to Queue with the serialized instance of the class. Any free Worker Role gets a serialized class from Queue, deserializes it and fills Input data from the blob. Then Worker Role calls Execute method of the class. The results of Execute method working are saved to a blob with the name “ResultData”+TaskId. A link to the blob and the status “Task completed” are saved to the Task table. Web Role checks the Task table in loop and returns the results from the blob when the status of class has changed to completed state.
The other way of notification is using.Net Service Bus by Web Role. In this case, Worker Role, which is to be notified of class’s Execute method completion, creates a request to Service Bus. .Net Service Bus raises an event when the class’s Execute method has finished work, and all Web Role Instances subscribed to the event have been notified. Notified Web Role gets results from the blob and sends it to the customer. An address to the blob is stored to notification. If Web Role expects some results data, but there isn’t any data to return to the user, Web Role puts the class to Worker Role to repeat the performance.
We have investigated the case when only one of the collaborating users makes a request to Web Role to do some work and is notified of the task's completion. But other users have to be notified of changes made by the requested work, too.
There are three options that can be used by a developer:
- A developer can implement an individual operation contract in WCF that checks the Task table and returns all changes if there are any in loop.
- A developer can use .Net Service Bus for notification of users directly.
- A developer can implement a class that inherits from ITask. This class can take results requested by the user using some processing.
In the second case, users subscribe to event from .Net Service Bus. This event is raised if there are any changes in the system made by other users. The changes can be transmitted either inside event arguments or via calling the individual operation contract in WCF. So a developer can implement any algorithm of getting concrete results.
You can see the architecture of a scalable cloud application based on our framework in figure 4, as well as the sequence diagram in figure 3.
Figure 3. Sequence diagram shows processing of user’s request using Service Bus.
Figure 4. Architecture of a scalable cloud application based on our framework
The main framework capabilities are as follows. The workflow of performing any work depends on a scenario selected by a developer and can be expanded to achieve more complex goals. The flexibility of the workflow is controlled by the properties determined in the ITask interface. The rest of the logic and code remain the same for different kinds of goals. The behavior depends only on the type of the class inherited from ITask that is created in Web Role for each particular client request. Usage of .NET Service Bus adds flexibility to the Silverlight Client – Web Role communication.
Our solution for user notification is an alternative to polling duplex for Windows Azure platform, which was in a stage of development at that moment.
Demo applications
To show our framework in action, we implemented a cloud application that allows multiple users to draw many-colored shapes on the same board. Each user can see the changes made by others. Multidraw is a real-time collaborative drawing cloud application, using Silverlight and Microsoft Windows Azure, and you are welcome to see a video demonstrating how Multidraw works. The framework can be easily adapted for any similar task. A good sample of an application that can be created with the help of our architecture is a multi-edit grid that allows a multiuser edition of the same grid. The demo of the grid also appears in the video.

Figure 5. Screenshot of Multidraw application working in different browsers
Conclusion
We looked into new implementation of cloud computing presented in the Windows Azure platform by Microsoft. We developed a universal framework architecture that allows you to implement similar tasks with multiple-user interaction easily. We implemented working prototypes that allow multiple users to draw many-colored shapes on the same board and edit the same grid.