In my previous post I’ve shown how easy is to publish a web application to an Azure web role, a detail I’ve omitted is that among WebRole settings there’s the number of role instances you wish to activate:


As you increase this number, the number of VM created by Azure infrastructure and made available to load balancer increases and your “site” can satisfy a larger number or incoming requests.
Sounds great (and it is indeed) but increasing instance count has the side effect to increase your Azure billing so the right compromise is would be to ‘adjust’ the number of roles depending on application load, not going below 2 in order to fulfill Azure 99% SLA.

Azure won’t automatically change the number of instances for you, but it give you everything you need to plan your load handling strategy.

Let’s imagine our application being a Movie Ticket application: it quite obvious to expect a load increase on weekends and a decrease during weekdays so we could decide to upgrade instances count starting from Friday afternoon and decrease it on Sunday evening in order to better balance the service/cost ratio.
Azure exposes a series of management API that allows to perform automatic deployments and change role configuration (including instance count) in form of free (not billed) secure REST calls, but the goal of this post is to show you the  quick ‘n’ lazy way through an utility called csmanage.
Let’s start downloading csmanage from  since this utility just issues REST calls and since Azure requires those calls to be secured (I don’t think you want everyone playing with your instances strategy…) we need to add a digital certificate to our service through Azure management portal.
Since certificate can be self-signed we can use IIS or makecert to issue it and then login into Azure portal and upload it:


BTW: This step is required even if you opt for direct REST management call.

We now need to configure csmanage so that all REST calls will be properly signed with the same certificate, so let’s edit the file csmanage.exe.config and insert certificate matching info:

<add key="CheckServerCertificate" value="true"/>
<!-- Insert your subscriptionId as shown by the Windows Azure developer portal -->
<add key="SubscriptionId" value="???"/>
<!-- Insert your certificate thumbprint without spaces -->
<add key="CertificateThumbprint" value="51CB8B2??????E660A636ABA58EAA451481"/>
We’re done! now we can use csmanage command line options to interact with our role, inside usage.txt file you can however find all command supported by csmanage.
To change the number of role instance all we need to do is to change role’s configuration, on my solution I’ve just created several copies of role’s .cscfg file (see an example below) naming them small/medium/big.cscfg
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="AzureHost" xmlns="" osFamily="1" osVersion="*">
<Role name="DemoSilverlight.Web">
<Instances count="3" />
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
then I just issue this csmanage command: csmanage /change-deployment-config /config:big.cscfg /slot:production /hosted-service: DemoBlog   and wait a few minutes for Azure to update the configuration.
Just add this command to Window Task Schedule and you can easily schedule your role configuration without any other intervention.
Technorati Tags: ,