Angel \”Java\” Lopez on Blog

February 13, 2012

Azure: Links, News and Resources (3)

Filed under: .NET, Azure, Cloud Computing, Links — ajlopez @ 1:54 pm

Previous Post

More links I collected during my work and research.

Cyan – Simpler than Azure
http://cyannet.codeplex.com/
Cyan is a .NET dynamic client for the Azure Table Storage REST API.

Azure Table Storage & Dynamic TableServiceEntity
http://stackoverflow.com/questions/7522235/azure-table-storage-dynamic-tableserviceentity

richorama / AzureSugar
https://github.com/richorama/AzureSugar
Syntactic sugar to make Azure development a little sweeter
Support is also available for using dynamic types (or dictionaries) to insert and query table storage.

Azure Table Storage with dynamic entities objects
http://ruiromanoblog.wordpress.com/2009/05/15/azure-table-storage-with-dynamic-entities-objects/

WindowsAzure / azure-sdk-for-node
https://github.com/WindowsAzure/azure-sdk-for-node/tree/dev/examples/myevents

Accessing Azure Role Environment information from NodeJS
http://nodeblog.cloudapp.net/accessing-azure-role-environment-information-from-node

Windows Azure Startup task to run npm install to avoid deploying node modules
http://nodeblog.cloudapp.net/startup-task-to-run-npm-in-azure

Leveraging Node.js’ libuv in Windows Azure
http://msdn.microsoft.com/en-us/library/hh527737(v=VS.103).aspx

Getting the samples to work on the Azure Node.js SDK
http://coderead.wordpress.com/2012/01/03/getting-the-samples-to-work-on-the-azure-node-js-sdk/

Microsoft will add Linux virtual machines to Windows Azure
http://arstechnica.com/business/news/2012/01/microsoft-will-add-linux-virtual-machines-to-windows-azure.ars

Create Hosted Service using Windows Azure Management API
http://debugmode.net/2012/01/02/create-hosted-service-using-windows-azure-management-api/

Microsoft Windows Azure PaaS Gets Node.js Update
http://www.talkincloud.com/microsoft-windows-azure-paas-gets-node-js-update/

How to deploy WordPress using the Windows Azure SDK for PHP WordPress scaffold
http://azurephp.interoperabilitybridges.com/articles/how-to-deploy-wordpress-using-the-windows-azure-sdk-for-php-wordpress-scaffold

Advertising Company Adopts Cloud Computing, Gets 400 Percent Improvement
http://www.microsoft.com/casestudies/Case_Study_Detail.aspx?CaseStudyID=4000008145

Kobojo
Game Developer Meets Demand and Prepares for Success with Scalable Cloud Solution
http://www.microsoft.com/casestudies/Case_Study_Detail.aspx?CaseStudyID=4000008216

What is Windows Azure?
http://www.youtube.com/watch?feature=player_embedded&v=poDRw_Xi3Aw

Azure On GitHub
https://github.com/blog/1010-azure-on-github

Azure: Running Multiple Web Sites in a Single WebRole
http://blog.elastacloud.com/2011/01/11/azure-running-multiple-web-sites-in-a-single-webrole/

Deploying independent web applications to Windows Azure using single web role
http://weblogs.asp.net/gunnarpeipman/archive/2011/12/29/deploying-independent-web-applications-to-windows-azure-using-single-web-role.aspx

Modificar el tiempo de vida del token proporcionado por Windows Azure AppFabric Access Control
http://www.returngis.net/2011/12/modificar-el-tiempo-de-vida-del-token-proporcionado-por-windows-azure-appfabric-access-control/

Windows Azure Multi Application
http://azuremultiapp.codeplex.com/
Windows Azure Multi Application is a complete sample solution that allow deploy dinamically aplications to existing role instance.
After deploy admin tool new application can be deployed, without modify initial azure deployment. Each application can be deployed independently and can be of different types; ASP.NET WebForms, ASP.NET MVC, Windows Service, Console Application…

How to combine a Worker Role and an MVC4 Web Role into a single Azure instance
http://blog.liamcavanagh.com/2011/12/how-to-combine-a-worker-role-with-a-mvc4-web-role-into-a-single-instance/

Hadoop Streaming and F# MapReduce
http://blogs.msdn.com/b/carlnol/archive/2011/12/16/hadoop-streaming-and-f-mapreduce.aspx

Windows Azure Architecture Guide – Part 2 – Code Samples
http://www.microsoft.com/download/en/details.aspx?id=27878

Windows Azure + a pinch of UK
http://paper.li/ericnel/1314797915

Using Amazon and Azure Cloud Services in your Delphi XE2 and C++Builder XE2 Applications
http://www.youtube.com/watch?v=BRFbiRcLtkc&feature=player_embedded

What’s new in Windows Azure
http://www.infoworld.com/d/microsoft-windows/whats-new-in-windows-azure-181578

Microsoft Azure gets an open source rival
http://www.infoworld.com/d/open-source-software/microsoft-azure-gets-open-source-rival-181845

Introduction to the Hadoop on Azure Interactive JavaScript Console
http://www.youtube.com/watch?v=alPMYcomUEs

Node.JS in Windows Azure
http://channel9.msdn.com/Events/windowsazure/learn/Node-JS-in-Windows-Azure

Azure price cuts, bigger databases, now with node.js and MongoDB support, Hadoop on its way
http://arstechnica.com/microsoft/news/2011/12/azure-price-cuts-bigger-databases-now-with-nodejs-and-mongodb-support-hadoop-on-its-way.ars?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+arstechnica/index+(Ars+Technica+-+Featured+Content)

Improved Developer Experience, Interoperability, and Scalability on Windows Azure
http://blogs.msdn.com/b/windowsazure/archive/2011/12/12/improved-developer-experience-interoperability-and-scalability-on-windows-azure.aspx

Azure Node.js Developer Center
https://www.windowsazure.com/en-us/develop/nodejs/

Deploying Node.js Applications to Windows Azure via Blobs or Git Sync
http://blog.smarx.com/posts/deploying-node-js-applications-to-windows-azure-via-blobs-or-git-sync

Ten Basic Troubleshooting Tips for Windows Azure
http://www.davidaiken.com/2011/11/15/ten-basic-troubleshooting-tips-for-windows-azure/

Now Available! Updated Windows Azure SDK & Windows Azure HPC Scheduler SDK
http://blogs.msdn.com/b/windowsazure/archive/2011/11/14/updated-windows-azure-sdk-amp-windows-azure-hpc-scheduler-sdk.aspx

My Links
http://delicious.com/ajlopez/azure

January 3, 2012

What is Windows Azure?

Filed under: Azure, Cloud Computing, Video — ajlopez @ 11:06 am

Past year, I wrote many blog post about Azure programming. Maybe, you know about cloud computing in general, but not about Azure in particular. Today, thanks to Windows Azure + a pinch of UK published by Eric Nelson (@ericnel), I found this video, that explain in simple terms the key technical pieces of Azure:

http://www.youtube.com/watch?v=poDRw_Xi3Aw

For more information about the video, see Steve Marx (@smarx) post:

What is Windows Azure? (a Hand-Drawn Video)

It has an interesting section title: “How I Made It”.

Notice the difference of compute nodes and storage nodes. Both service can be emulated in your local machine, thanks to Azure tools for Visual Studio.

My links about azure:

http://delicious.com/ajlopez/azure

A post about Azure, games and Node.js is comming.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

November 21, 2011

Azure: Links, News and Resources (2)

Filed under: Azure, Cloud Computing, Links — ajlopez @ 9:22 am

Previous Post
Next Post

More links related to Azure:

http://en.wikipedia.org/wiki/Azure_Services_Platform

The Windows Azure Platform[2] is a Microsoft cloud platform used to build, host and scale web applications through Microsoft data centers. Windows Azure Platform is thus classified as platform as a service and forms part of Microsoft’s cloud computing strategy, along with their software as a service offering, Microsoft Online Services. The platform consists of various on-demand services hosted in Microsoft data centers and commoditized through three product brands. These are Windows Azure[3] (an operating system providing scalable compute and storage facilities), SQL Azure (a cloud-based, scale-out version of SQL Server) and Windows Azure AppFabric (a collection of services supporting applications both in the cloud and on premise).

Moving Channel9.msdn.com to Windows Azure
http://www.infoq.com/articles/Channel-9-Azure

Build 2011: Windows Azure Tackles the ‘One True Login’ Puzzle
http://www.readwriteweb.com/cloud/2011/09/build-2011-windows-azure-tackl.php

Microsoft to eat its own cloud dog food with Photosynth
http://www.zdnet.com/blog/microsoft/microsoft-to-eat-its-own-cloud-dog-food-with-photosynth/11104

Command-Query Separation on Windows Azure
http://ntotten.com/2011/10/command-query-separation-on-windows-azure/

How to Manage Expiration of Blob Content
http://msdn.microsoft.com/en-us/library/windowsazure/gg680306.aspx

Windows Azure Design Patterns, Part 1: Architectural Symbols
http://davidpallmann.blogspot.com/2011/07/windows-azure-design-patterns-part-1.html

Windows Azure Accelerator for Web Roles Version 1.1
http://ntotten.com/2011/08/windows-azure-accelerator-for-web-roles-version-1-1/

Running Processes in Windows Azure
http://ntotten.com/2011/09/running-processes-in-windows-azure/

pekkah / AzureSamples
https://github.com/pekkah/AzureSamples/tree/master/DataSample

Exercise 1: Using Worker Role External Endpoints
http://msdn.microsoft.com/en-us/gg457890

Building Web APIs in Windows Azure with WCF to reach any device
http://channel9.msdn.com/Events/BUILD/BUILD2011/SAC-798T

pofallon / node-azure
https://github.com/pofallon/node-azure
A node.js library for accessing the Windows Azure REST API’s

Introducing Geo-replication for Windows Azure Storage
http://blogs.msdn.com/b/windowsazurestorage/archive/2011/09/15/introducing-geo-replication-for-windows-azure-storage.aspx

Windows Azure Tables: Introducing Upsert and Query Projection
http://blogs.msdn.com/b/windowsazurestorage/archive/2011/09/15/windows-azure-tables-introducing-upsert-and-query-projection.aspx

Windows Azure Blobs: Improved HTTP Headers for Resume on Download and a Change in If-Match Conditions
http://blogs.msdn.com/b/windowsazurestorage/archive/2011/09/15/windows-azure-blobs-improved-http-headers-for-resume-on-download-and-a-change-in-if-match-conditions.aspx

CloudCopy Command Line Tool
http://cloudcopy.codeplex.com/

Windows Azure Toolkits for Devices – Now With Android!
http://www.wadewegner.com/2011/08/windows-azure-toolkits-for-devices-now-with-android/

Microsoft rolls out Windows Azure toolkit for Android
http://www.zdnet.com/blog/microsoft/microsoft-rolls-out-windows-azure-toolkit-for-android/10503

Windows Azure SDK for PHP
http://blogs.msdn.com/b/mvplead/archive/2011/08/31/windows-azure-sdk-for-php.aspx

Azure Tip: Consider Remote Desktop when Planning Role Endpoints
http://www.davidmakogon.com/2011/01/azure-tip-consider-remote-desktop-when.html

Memcached in Windows Azure
http://blog.smarx.com/posts/memcached-in-windows-azure

NodeJS on Windows Azure
http://ntotten.com/2011/08/nodejs-on-windows-azure/

Using Windows Azure to use as a TCP Server
http://stackoverflow.com/questions/6173763/using-windows-azure-to-use-as-a-tcp-server

Windows Azure Tip: Go Beyond 5 Endpoints per Role, beyond 25 per Deployment
http://www.davidmakogon.com/2011/05/windows-azure-tip-go-beyond-5-endpoints.html

Lightweight Tracing to Windows Azure Tables
http://blog.smarx.com/posts/lightweight-tracing-to-windows-azure-tables

Using ELMAH in Windows Azure with Table Storage
http://www.wadewegner.com/2011/08/using-elmah-in-windows-azure-with-table-storage/

Windows Phone 7 Push Notification QuickApp / Web Service (With Azure Publishing Instructions!)
http://channel9.msdn.com/posts/Windows-Phone-7-Push-Notification-QuickApp–Web-Service-With-Azure-Publishing-Instructions

Various Options to Manage Session State in Windows Azure
http://geeks.netindonesia.net/blogs/wely/archive/2011/08/13/various-options-to-manage-session-state-in-windows-azure.aspx

Windows Azure & WF 4.0 – Creating a Workflow-Driven WorkerRole
http://agileculture.net/lboffi/2011/08/12/windows-azure-wf-40-creating-a-workflow-driven-workerrole/

Microsoft announced Windows Azure Storage Analytics
http://bartwullems.blogspot.com/2011/08/microsoft-announced-windows-azure.html

Azure Cloud to Capture RenderMan
http://www.hpcinthecloud.com/hpccloud/2011-08-08/azure_cloud_to_capture_renderman.html

igrating SQL server Data to SQL Azure using BCP << Paras Doshi
http://beyondrelational.com/blogs/parasdoshi/archive/2011/08/08/migrating-sql-server-data-to-sql-azure-using-bcp-lt-lt-paras-doshi.aspx

Using Windows Azure Blob Storage and CDN with WordPress
http://www.wadewegner.com/2011/08/using-windows-azure-blob-storage-and-cdn-with-wordpress/

Practical Testing Techniques for Windows Azure Applications
http://www.devproconnections.com/article/cloud-computing2/cloud-test-windows-azure-136179

Daytona: Iterative MapReduce on Windows Azure
http://research.microsoft.com/en-us/projects/daytona/default.aspx

Connecting to SQL Azure from Ruby Applications
http://msdnrss.thecoderblogs.com/2011/08/connecting-to-sql-azure-from-ruby-applications/

Ideas about NoSql on Windows Azure: Azure Storage
http://blog.fabse.net/2011/08/02/ideas-about-nosql-on-windows-azure-azure-storage/

Architecture of Tankster– Scale (Part 2)
http://ntotten.com/2011/07/architecture-of-tankster-scale-part-2/

Windows Azure CDN Helpers
http://ntotten.com/2011/06/windows-azure-cdn-helpers/

Social Gaming on Windows Azure
http://channel9.msdn.com/Series/Social-Gaming-on-Windows-Azure

Extending the Windows Azure Accelerator for Web Roles with PHP and MVC3
http://ntotten.com/2011/07/extending-the-windows-azure-accelerator-for-web-roles-with-php-and-mvc3/

Ajax, Cross Domain, jQuery, WCF Web API or MVC, Windows Azure
http://blogs.southworks.net/mwoloski/2011/07/02/ajax-cross-domain-jquery-wcf-web-api-or-mvc-windows-azure/

smarx / blobedit
https://github.com/smarx/blobedit
Simple UI (based on Ace) to edit code files in Windows Azure blob storage

sriramk / winazurestorage
https://github.com/sriramk/winazurestorage
Python client wrapper for Windows Azure storage

Azure BlobStorage Javascript Library
http://azureblobstoragejs.codeplex.com/

Using Windows Azure Page Blobs and How to Efficiently Upload and Download Page Blobs
http://blogs.msdn.com/b/windowsazurestorage/archive/2010/04/11/using-windows-azure-page-blobs-and-how-to-efficiently-upload-and-download-page-blobs.aspx

Building Java applications on Windows Azure gets easier with the new version of the Eclipse plugin
http://blogs.msdn.com/b/interoperability/archive/2011/06/23/building-java-applications-on-windows-azure-gets-easier-with-the-new-version-of-the-eclipse-plugin.aspx

My Links
http://delicious.com/ajlopez/azure

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

February 15, 2011

Azure: Fractal application

Filed under: .NET, Azure, Cloud Computing, Distributed Computing — ajlopez @ 10:21 am

In January, I reimplemented my Fractal application, now using Azure (my Azure-related posts). The idea is to calculate each sector of a fractal image, using the power of worker roles, store the result in blobs, and consume them from a WinForm application.

This is the solution:

The source code is in my AjCodeKatas Google project. The code is at:

http://code.google.com/p/ajcodekatas/source/browse/#svn/trunk/Azure/AzureFractak

If you are lazy to use SVN, this is the current frozen code: AzureFractal.zip.

The projects in the solution:

AzureFractal: the Azure cloud definition.

Fractal: it contains my original code from previous fractal applications. An independent library class.

Fractal.Azure: serialization utilities of fractal info, and a service facade to post that info to a Azure message queue.

AzureLibrary: utility classes I used in other Azure examples. They are evolving in each example.

FractalWorkerRole: the worker role that consumes messages indicating what sector (rectangle) of the Mandelbrot fractal to calculate.

Fractal.GUI: a client WinForm project that sends and receives message to/from the worker role, using Azure queues.

You should configure the solution to have a multiple startup:

The WinForm application sends a message to a queue, with the info about the fractal sector to calculate:

private void Calculate()
{
    Bitmap bitmap = new Bitmap(pcbFractal.Width, 
       pcbFractal.Height);
    pcbFractal.Image = bitmap;
    pcbFractal.Refresh();
    realWidth = realDelta * pcbFractal.Width;
    imgHeight = imgDelta * pcbFractal.Height;
    realMin = realCenter - realWidth / 2;
    imgMin = imgCenter - imgHeight / 2;
    int width = pcbFractal.Width;
    int height = pcbFractal.Height;
    Guid id = Guid.NewGuid();
    SectorInfo sectorinfo = new SectorInfo()
    {
        Id = id,
        FromX = 0,
        FromY = 0,
        Width = width,
        Height = height,
        RealMinimum = realMin,
        ImgMinimum = imgMin,
        Delta = realDelta,
        MaxIterations = colors.Length,
        MaxValue = 4
    };
    Calculator calculator = new Calculator();
    this.queue.AddMessage(
        SectorUtilities.FromSectorInfoToMessage(sectorinfo));
}

The worker role reads messages from the queue, and deserialize SectorInfo:

while (true)
{
    CloudQueueMessage msg = queue.GetMessage();
    if (msg != null)
    {
        Trace.WriteLine(string.Format("Processing {0}", msg.AsString));
        SectorInfo info = SectorUtilities.FromMessageToSectorInfo(msg);

If the sector is too big, new messages are generated:

if (info.Width > 100 || info.Height > 100)
{
    Trace.WriteLine("Splitting message...");
    for (int x = 0; x < info.Width; x += 100)
        for (int y = 0; y < info.Height; y += 100)
        {
            SectorInfo newinfo = info.Clone();
            newinfo.FromX = x + info.FromX;
            newinfo.FromY = y + info.FromY;
            newinfo.Width = Math.Min(100, info.Width - x);
            newinfo.Height = Math.Min(100, info.Height - y);
            CloudQueueMessage newmsg = 
              SectorUtilities.FromSectorInfoToMessage(newinfo);
            queue.AddMessage(newmsg);
        }
}

If the sector is small enough, then it is processed:

Trace.WriteLine("Processing message...");
Sector sector = calculator.CalculateSector(info);
string blobname = string.Format("{0}.{1}.{2}.{3}.{4}", 
info.Id, sector.FromX, sector.FromY, sector.Width, sector.Height);
CloudBlob blob = blobContainer.GetBlobReference(blobname);
MemoryStream stream = new MemoryStream();
BinaryWriter writer =new BinaryWriter(stream);
foreach (int value in sector.Values)
    writer.Write(value);
writer.Flush();
stream.Seek(0, SeekOrigin.Begin);
blob.UploadFromStream(stream);
stream.Close();
CloudQueueMessage outmsg = new CloudQueueMessage(blobname);
outqueue.AddMessage(outmsg);

A blob with the result is generated, and a message is sent to another queue to notify the client application.

The WinForm has a thread with a loop reading messages from the second queue:

string blobname = msg.AsString;
CloudBlob blob = this.blobContainer.GetBlobReference(blobname);
MemoryStream stream = new MemoryStream();
blob.DownloadToStream(stream);
blob.Delete();
this.inqueue.DeleteMessage(msg);
string[] parameters = blobname.Split('.');
Guid id = new Guid(parameters[0]);
int fromx = Int32.Parse(parameters[1]);
int fromy = Int32.Parse(parameters[2]);
int width = Int32.Parse(parameters[3]);
int height = Int32.Parse(parameters[4]);
int[] values = new int[width * height];
stream.Seek(0, SeekOrigin.Begin);
BinaryReader reader = new BinaryReader(stream);
for (int k = 0; k < values.Length; k++)
    values[k] = reader.ReadInt32();
stream.Close();
this.Invoke((Action<int,int,int,int,int[]>) ((x,y,h,w,v) 
=> 
this.DrawValues(x,y,h,w,v)), fromx, fromy, width, height, values);

Note the use of .Invoke to run the drawing of the image in the UI thread.

This is the WinForm app, after click on Calculate button. Note that the sectors are arriving:

There are some blob sectors that are still not arrived. You can drag the mouse to have a new sector:

You can change the colors, clicking on New Colors button:

This is a sample application, a “proof-of-concept”. Probably, you will get a better performance if you use a single machine. But the idea is that you can defer work to worker roles, specially if the work can be do in parallel (imagine a parallel render machine, for animations). If you run these an application in Azure, with many worker roles, the performance could be improved.

Next steps: implement a distributed web crawler, try distributed genetic algorithm, running in the Azure cloud.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

February 8, 2011

Azure: A simple Application using Tables

Filed under: .NET, ASP.NET, Azure, Cloud Computing — ajlopez @ 10:24 am

Continuing with my Azure examples, this time I wrote a simple CRUD Web applications, using Tables, using Azure Storage Client.

It’s a classic ASP.NET application, this is the view for Customer/Index action:

You can download the solution from my AjCodeKatas Google project. The code is at:

http://code.google.com/p/ajcodekatas/source/browse/#svn/trunk/Azure/AzureCustomers

If you want the current frozen version: AzureCustomers.zip.

The simple entity Customer:

public class Customer : TableServiceEntity
{
    public Customer()
        : this(Guid.NewGuid().ToString())
    {
    }
    public Customer(string id)
        : base(id, string.Empty)
    {
    }
    public string Name { get; set; }
    public string Address { get; set; }
    public string Notes { get; set; }
}

I’m using the PartitionKey as the primary key, filling it with a Guid. The RowKey is the empty string. In a less simple application, I could save the invoices of a customer using the same partition key, and identifing each invoice with its RowKey.

A DataContext is in charge of expose an IQueryable of Customers:

public class DataContext : TableServiceContext
{
    public const string CustomerTableName = "Customers";
    public DataContext(string baseAddress, StorageCredentials credentials)
        : base(baseAddress, credentials)
    {
        this.IgnoreResourceNotFoundException = true;
    }
    public DataContext(CloudStorageAccount storageAccount)
        : base(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials)
    {
        this.IgnoreResourceNotFoundException = true;
    }       
    public IQueryable<Customer> Customers
    {
        get
        {
            return this.CreateQuery<Customer>(CustomerTableName);
        }
    }
}

Note the IgnoreNotFoundException: if true, I can retrieve an inexistent customer, and instead of raise an exception, return a null value.

There is a service to access and manage Customers:

public class CustomerServices
{
    private DataContext context;
    public CustomerServices(DataContext context)
    {
        this.context = context;
    }
    public Customer GetCustomerById(string id)
    {
        return this.context.Customers.Where(c => c.PartitionKey == id).SingleOrDefault();
    }
    public IEnumerable<Customer> GetCustomerList()
    {
        return this.context.Customers.ToList().OrderBy(c => c.Name);
    }
    public void AddCustomer(Customer customer)
    {
        this.context.AddObject(DataContext.CustomerTableName, customer);
        this.context.SaveChanges();
    }
    public void UpdateCustomer(Customer customer)
    {
        this.context.AttachTo(DataContext.CustomerTableName, customer, "*");
        this.context.UpdateObject(customer);
        this.context.SaveChanges();
    }
    public void DeleteCustomerById(string id)
    {
        Customer c = this.GetCustomerById(id);
        this.context.DeleteObject(c);
        this.context.SaveChanges();
    }
}

Note the Attach using ETag (third parameter) of “*” (any). This way, I can update the customer attaching the “in-memory-created” one to the data context, without retrieving it from the database. This approarch is viable if I have all the data of the customer. In most application you change only some fields, so you should retrieve the object, change it, and then, save the changes.

Using the service to retrieve the customers:

CloudStorageAccount storage = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
CustomerServices services = new CustomerServices(new DataContext(storage));
this.grdCustomerList.DataSource = services.GetCustomerList();
this.grdCustomerList.DataBind();

Note: it’s a sample application, simple and direct. A real application should separate the view model from the business model, and maybe, use an ASP.NET MVC front end. I will write this example, using MVC. In another series (out of Azure), I want to write an app using ASP.NET MVC AND TDD.

Next steps in Azure: a distributed fractal application, a distributed web crawler, implement a distributed genetic algorithm, using worker roles.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

December 13, 2010

Azure: Multithreads in Worker Role, an example

Filed under: .NET, Azure, Cloud Computing, Distributed Computing — ajlopez @ 9:41 am

In my previous post, I implemented a simple worker role, consuming and producing numbers from/to a queue. Now, I have a new app:

The worker role implements the generation of a Collatz sequence. See:

http://mathworld.wolfram.com/CollatzProblem.html
http://en.wikipedia.org/wiki/Collatz_conjecture
http://www.ericr.nl/wondrous/

You can download the solution from my AjCodeKatas Google project. The code is at:

http://code.google.com/p/ajcodekatas/source/browse/#svn/trunk/Azure/AzureCollatz

The initial page is simple:

The number range is send to the queue:

protected void btnProcess_Click(object sender, EventArgs e)
{
    int from = Convert.ToInt32(txtFromNumber.Text);
    int to = Convert.ToInt32(txtToNumber.Text);
    for (int k=from; k<=to; k++) 
    {
        CloudQueueMessage msg = new CloudQueueMessage(k.ToString());
        WebRole.Instance.NumbersQueue.AddMessage(msg);
    }
}

The worker role gets each of these message, and calculates the Collatz sequence:

I added a new feature in Azure.Library: a MessageProcessor that can consumes message from a queue, in its own thread:

public MessageProcessor(CloudQueue queue, Func<CloudQueueMessage, bool> process)
{
    this.queue = queue;
    this.process = process;
}
public void Start()
{
    Thread thread = new Thread(new ThreadStart(this.Run));
    thread.Start();
}
public void Run()
{
    while (true)
    {
        try
        {
            CloudQueueMessage msg = this.queue.GetMessage();
            if (this.ProcessMessage(msg))
                this.queue.DeleteMessage(msg);
        }
        catch (Exception ex)
        {
            Trace.WriteLine(ex.Message, "Error");
        }
    }
}
public virtual bool ProcessMessage(CloudQueueMessage msg)
{
    if (msg != null && this.process != null)
        return this.process(msg);
    Trace.WriteLine("Working", "Information");
    Thread.Sleep(10000);
    return false;
}

Then, the worker role is launching a fixed number (12) of MessageProcessor. In this way, each instance is dedicated to process many message. I guess that this is not needed in this example. But it was an easy “proof of concept” to test the idea. Part of Run method in worker role;

QueueUtilities qutil = new QueueUtilities(account);
CloudQueue queue = qutil.CreateQueueIfNotExists("numbers");
CloudQueueClient qclient = account.CreateCloudQueueClient();
for (int k=0; k<11; k++) 
{
    CloudQueue q = qclient.GetQueueReference("numbers");
    MessageProcessor p = new MessageProcessor(q, this.ProcessMessage);
    p.Start();
}
MessageProcessor processor = new MessageProcessor(queue, this.ProcessMessage);
processor.Run();

The ProcessMessage is in charge of the real work:

private bool ProcessMessage(CloudQueueMessage msg)
{
    int number = Convert.ToInt32(msg.AsString);
    List<int> numbers = new List<int>() { number };
    while (number > 1)
    {
        if ((number % 2) == 0)
        {
            number = number / 2;
            numbers.Add(number);
        }
        else
        {
            number = number * 3 + 1;
            numbers.Add(number);
        }
    }
    StringBuilder builder = new StringBuilder();
    builder.Append("Result:");
    foreach (int n in numbers)
    {
        builder.Append(" ");
        builder.Append(n);
    }
    Trace.WriteLine(builder.ToString(), "Information");
    return true;
}

The code of this example is in my

Next steps: more distributed apps (genetic algorithm, web crawler…)

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

December 9, 2010

Azure: a simple application

Filed under: .NET, Azure, Cloud Computing, Distributed Computing — ajlopez @ 9:19 am

This is my first post here, about Azure programming. An easy start: an application with one web role, and one worker role:

You can download the solution from my AjCodeKatas Google project. The code is at:

http://code.google.com/p/ajcodekatas/source/browse/#svn/trunk/Azure/AzureNumbers

In the initial web page you can enter a number to process:

If you send the number 10, this data is send to a queue:

protected void btnProcess_Click(object sender, EventArgs e)
{
    int number = Convert.ToInt32(txtNumber.Text);
    CloudQueueMessage msg = new CloudQueueMessage(number.ToString());
    WebRole.NumbersQueue.AddMessage(msg);
}

The worker role is reading the queue. It decrements the number, and if the result is still positive, it is reinjected in the queue:

        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("NumberWorkerRole entry point called", "Information");
            CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            QueueUtilities qutil = new QueueUtilities(account);
            CloudQueue queue = qutil.CreateQueueIfNotExists("numbers");
            while (true)
            {
                CloudQueueMessage msg = queue.GetMessage();
                if (msg != null)
                {
                    int number = Convert.ToInt32(msg.AsString);
                    Trace.WriteLine(string.Format("Processing number: {0}", number), "Information");
                    number--;
                    if (number > 0)
                    {
                        CloudQueueMessage newmsg = new CloudQueueMessage(number.ToString());
                        queue.AddMessage(newmsg);
                    }
                    queue.DeleteMessage(msg);
                }
                else
                {
                    Thread.Sleep(10000);
                    Trace.WriteLine("Working", "Information");
                }
            }
        }

You can see the output at Development Fabric UI:

Note the use of AzureLibrary to create a Queue:

        public CloudQueue CreateQueueIfNotExists(string queuename)
        {
            CloudQueueClient queueStorage = this.account.CreateCloudQueueClient();
            CloudQueue queue = queueStorage.GetQueueReference(queuename);
            
            Trace.WriteLine("Creating queue...", "Information");
            Boolean queuecreated = false;
            while (queuecreated == false)
            {
                try
                {
                    queue.CreateIfNotExist();
                    queuecreated = true;
                }
                catch (StorageClientException e)
                {
                    if (e.ErrorCode == StorageErrorCode.TransportError)
                    {
                        Trace.TraceError(string.Format("Connect failure! The most likely reason is that the local " +
                            "Development Storage tool is not running or your storage account configuration is incorrect. " +
                            "Message: '{0}'", e.Message));
                        System.Threading.Thread.Sleep(5000);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return queue;
        }

I borrowed part of this code from Azure SDK samples.

Next steps to explore:

- Add instrumentation to worker role

- Use more instances, and generate more message (an explosion-like pattern)

- Add multithreading support in the worker role

- Example using table and blob storage

And the big ones:

- Inject and run AjSharp (or AjTalk) code at worker roles

- Implements a distributed application using roles (distributed genetic algorithm, distributed fractal or ray-tracer, montecarlo simulation, etc…)

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

April 2, 2010

Twitter as the Ultimate Service Bus for Applications

I want to describe a proposal about using Twitter from applications. I guess this idea is not new, and that there are some real implementations in twittersphere. My point is to describe something simple and extensible.

Suppose you want to operate in a virtual marketplace. Actually, you are going to a website, enter your offer, wait for replies. An alternative method could be to use a Twitter account to send offer messages.

Something like this:

Every other application could read the feed from @ajmarket and then take action: response, make a counteroffer, publish it in a website, do market analysis, etc.

I propose a message format:

If you need to send more information, you can add links to data (possibly in JSON format, ok, it could be XML, but I prefer JSON):

Each application should define the valid verbs and arguments. The application that reads the messages (or write new ones) can be distributed, no need to have a entry point, in a URL. Twitter account is the more flexible entry point for such kind of applications.

Imagine you can build anything that involves many applications sending messages to possible many applications.

Even more: each application twitter account could be viewed as an agent. If you need to plan a trip, an “intelligent” application could be listen on Twitter, and take conversations with other Twitter agents to resolve your plan or problem.

The underlying application could run in Azure, Amazon, your own center. You can switch or support other message transport, Yammer instead of Twitter, or anything alike in the future.

Abstract: use Twitter as a pubsub channel, with a simple but flexible message format.

It should be something like this out there.

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

October 31, 2009

NHibernate running in the Azure Cloud

Filed under: .NET, Azure, Cloud Computing, NHibernate — ajlopez @ 1:12 pm

Yesterday, I was talking with Fabio Maulo (@fabiomaulo) about many things, related to software development, teaching programming and, of course, NHibernate. We are living in Buenos Aires, Argentina, and it was a pleasure to talk with him, as usual. Í’m following Fabio in Twitter, and I’m a suscriber of his blog. Fabio is collaborating with NHibernate project for years, and he is a recognized developer in the .NET software community.

He told me details about a site built using NHibernate, and running on SQL Azure. You can see it online (Spanish content, Mexican site):

http://salondetokio.autocosmos.com.mx/

Fabio and his team worked hard to write this site, in less of a month (I’m waiting the team posts, with more detailed info, so, I’ll write only about the public parts here).

Curiously, the site is running using WebForms, but without ViewState, and without form tags embracing the full body inner HTML. All we are waiting Maulo and his team, explaining the implementation details. The code is based on using Model View Presenter, and it was build using tests, mocks and stubs, from presentation to persistence. Hey, Fabio! Please, write about the process and architecture decisions! :-)

More info about NHibernate and Azure:

NHibernate on the cloud: SQL Azure Ayende NHibernate test results on Azure

Quick news NHibernate with SQL Azure Fabio’s first steps “All work… even the SchemaExport.” !!

NHibernate dialect for SQL Azure Adjustments for SchemaExport

I’m collecting links about NHibernate and Azure at:

http://delicious.com/ajlopez/nhibernate+azure

There is an excellent post serie from Brad Adams, explaining Azure, Azure SQL, NHibernate, Silverlight, RIA .NET Service, and more:

Index for Business Apps example for Silverligth 3 RTM and .NET RIA Services July Update

Related to NHibernate and Azure, in that series:

Part 20: NHibernate
Part 23: Azure

Any other project using NHibernate on the cloud?

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

Theme: Shocking Blue Green. Get a free blog at WordPress.com

Follow

Get every new post delivered to your Inbox.

Join 67 other followers