theDavidAiken

theDavidAiken

(6 comments, 78 posts)

This user hasn't shared any profile information

Home page: http://davidaiken.com

Posts by theDavidAiken

Windows Azure Memcached plugin

Update: Fixed broken link.

Cutting a really long story short. I wanted an easy way of adding caching to a Windows Azure project. Several people I know are already using Memcached, while waiting for our own caching service to go into production. I thought, this should be a plugin.

A plugin is exactly what it sounds, it is something that gets “plugged” into your role at build time. You can see the existing plugins on you have installed by looking at C:\Program Files\Windows Azure SDK\v1.3\bin\plugins. You should see plugins for diagnostics, RemoteAccess and more.

To make your own plugin is fairly easy – if you look in any of the plugin folders you will see a .CSPLUGIN file. You should be able to work out how this works. If you cannot, you probably don’t want to be building your own.

For the Memcached plugin, all I really need is the memcached.exe file (and any dependencies( I used the version from http://www.urielkatz.com/archive/detail/memcached-64-bit-windows/)), plus a little wrapper to read the config and launch memcached with the correct parameters – and of course the CSPLUGIN file:

<?xml version="1.0" ?>
<RoleModule
  xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"
  namespace="Memcached64Plugin">
  <Startup>
    <Task commandLine="Memcached64Plugin.exe" taskType="background" executionContext="limited"/>
  </Startup>
  <Endpoints>
    <InternalEndpoint name="Endpoint" protocol="tcp" port="11212" />
  </Endpoints>
  <ConfigurationSettings>
    <Setting name="CacheSizeInMB"/>
  </ConfigurationSettings>
</RoleModule>

What the above essentially does is:

  1. Adds a startup task
  2. Adds an InternalEndpoint for port 11212
  3. Adds a CacheSizeInMb setting

The little wrapper was written as a console app:

static void Main()
{

    var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Memcached64Plugin.Endpoint"].IPEndpoint;
    var cacheSize = RoleEnvironment.GetConfigurationSettingValue("Memcached64Plugin.CacheSizeInMB");
    var startupInfo = new ProcessStartInfo("memcached.exe", string.Format("-m {0} -p {1}", cacheSize, endpoint.Port));

    Process.Start(startupInfo);
}

Note when we read the values we use the format <name of the plugin>.<key>, rather than just <key>, in this case Memcached64Plugin.Endpoint, rather than just Endpoint.

Once you build the solution and copy the files into the plugin folder, you can then use the Imports tag in your ServiceConfiguration.csdef file:

 <Import moduleName="Memcached64Plugin" />

This will magically add the correct settings to your ServiceConfiguration.cscfg file as shown:

    <ConfigurationSettings>
      <Setting name="Memcached64Plugin.CacheSizeInMB" value="512" />

Note, you won’t see the internal port or the startup task.

When you build and deploy (or even run in the Compute Emulator) the plugin will be packaged up with your code and executed on boot.

For the client side, I used the enyim client, which you can grab from http://memcached.enyim.com/.

You can grab a list of memcached servers using the RoleEnvironment, something like:

RoleEnvironment.Roles["WebRole1"].Instances.Select(instance => instance.InstanceEndpoints["Memcached64Plugin.Endpoint"].IPEndpoint)

Note the role is WebRole1 and the port we are looking for is the one we defined in the CSPLUGIN!

You should also write some code to handle a topology change, including adding more instances (or removing instances). You can do this by adding code to handle the RoleEnvironment.Changed event, and rebuilding your server list.

You can grab my plugin below, minus the memcached.exe and required dll. You can download those from the http://www.urielkatz.com/archive/detail/memcached-64-bit-windows/.

THIS POSTING IS PROVIDED “AS IS” WITH NO WARRANTIES, AND CONFERS NO RIGHTS

PS: No, this was nothing to do with PowerShell, I hit an issue with that which I’m still working on – cross your fingers – it will be splendid.

Windows Azure Diagnostics Viewer

I’ve just finished publishing a prototype of the Windows Azure Diagnostics Viewer onto code gallery at http://code.msdn.microsoft.com/wazdmon.

The Windows Azure Diagnostics Viewer is a prototype web application that can be used to view and analyze Windows Azure Diagnostics information.

Windows Azure Diagnostics Monitor Screenshot

The Windows Azure Diagnostics Viewer has 2 components, a website and a scheduler. The website provides a UI to allow you to view diagnostics information collected by Windows Azure, including performance counter graphs, logs as well as some customer data including Windows Azure Queue statistics and service status data.

The website is designed to be “injected” into an existing worker role by adding references to a few dll’s as well as the website “exe”. The goal here is to make adding the viewer to a project painless – although in the prototype there are still several steps to complete.

Once started, the viewer website uses the HWC to host the website.

As well as simply viewing data collected by the existing Windows Azure Diagnostics system, the viewer can also display pre-aggregated data as well as information about Queue lengths and even service status. It does this with the help of the scheduler.

The scheduler is also designed to be “injected” into a role, and simply executes specified tasks. These tasks are contained in dll’s which are loaded from blob storage. The viewer provides shortcuts to common tasks, such as queue length collection and data aggregation.

Whilst this is a prototype, it has inspired some other thinking and ideas. You can expect a rev for the new SDK shortly after the new SDK hits as we’d like to take advantage of some of the new SDK features.

Anyway, check it out and let us know what you think.

THIS POSTING IS PROVIDED “AS IS” WITH NO WARRANTIES, AND CONFERS NO RIGHTS

Fabrikam Shipping SaaS Sample

My good friend Vittorio Bertocci has just posted a new demo that shows how you can build multi-tenant applications on Windows Azure called Fabrikam Shipping.

FabrikamShipping SaaS is a complete subscription based solution running on the Windows Azure platform and publicly available thru www.fabrikamshipping.com. It offers a web-based customer onboarding UI, which anybody can use for creating test subscriptions and obtain their very own application instance, dynamically provisioned by a simple but powerful provisioning engine. Thanks to our partnership with our friends evangelists at PayPal, it even demonstrates how to integrate payments and billing via an external provider!

Find out more at Vittorio’s blog – http://blogs.msdn.com/b/vbertocci/archive/2010/10/07/new-online-demo-introducing-fabrikamshipping-saas.aspx.

THIS POSTING IS PROVIDED “AS IS” WITH NO WARRANTIES, AND CONFERS NO RIGHTS

theDavidAiken's RSS Feed
Go to Top