F# on Windows Azure

F# on Windows Azure

Windows Azure was announced yesterday, and along with it, the first CTP of the SDK and Visual Studio tools. If you haven’t yet tried it, go take a look. On top of serving as a hosting service for web applications, Azure also provides a really simple way to do distributed compute and storage in the cloud.

Azure supports running .NET applications, which means you can build Azure worker roles using F#! The tools released with Azure don’t have F# support out of the box though, so I’ve posted a few simple templates and samples up on Code Gallery.

Worker Roles

The code above defines the implementation of a Worker Role – a process which runs in the background, waiting for work to do, and then processing these work requests. The worker role is set to run 4 instance simultaneously, which means that there will be 4 instances of this worker processing work items as they come in. This gives an implicit parallelism – in fact, the initial release of Azure will run one process per core, so you really are getting effective parallelism this way. Notice also that this requires that the worker processes are inherently stateless. Both aspects make typical functional design approaches that are common in F# natural for developing these worker roles.

Queues and Blobs

This sample uses two of the three data formats supported by Windows Azure. The queue storage holds the work items. The blob storage holds the pages visited during the web crawl. When an instance of the worker role Starts, it connects to the blob store and the queue store, then puts an initial work item in the queue and goes into a loop processing work items out of the queue.

Digitake - The Windows Azure SDK actually includes a local cloud emulation environment, called the "dev fabric", which allows you to start experimenting with building Azure apps right now, even if you don't yet have access to deploy the app into the production cloud.