Sunday, September 26, 2010

Combining Roles on Windows Azure

Now why would you want to do that? Azure provides a nice separation of roles in web role and a worker role – why do you want to combine those you’ll ask. Multiple reasons – saving cost being the primary. The most requested feature on the Windows Azure feature voting forum is “Make it less expensive to run my very small service on Windows Azure.” and rightly so. If you wish to host your “small service” on the cloud it makes sense to minimize the cost. Even for large scale services this can help to maximize the use of resources. Let’s crunch some numbers to see this in action.

Assume that your “simple service” consists of a simple website that provides the UI to the users. There is also a background worker for sending registration emails, sending newsletters and does some nightly batch processing of your data. Let’s say you don’t need a full blown SQL server and are happy with the semi structured data storage that Windows Azure table storage provides. These assumptions are not unrealistic for a large number of  simple websites, in fact most startup websites will start with this model and then scale out as the traffic increases and that’s exactly what Windows Azure enables you to do. So with these very realistic scenario let’s examine what will it cost to host such a service on Windows Azure. We will only focus on the compute cost as that’s what you will save on (& is the biggest cost for a small service) when you combine roles so we can safely ignore the storage, bandwidth and other costs of hosting on Azure as they are all usage based.

Here’s what the compute instances cost on Windows Azure.

  • Small instance (default): $0.12 per hour
  • Medium instance: $0.24 per hour
  • Large instance: $0.48 per hour
  • Extra large instance: $0.96 per hour

Let’s say you will use the small instances for both your roles. So your monthly cost comes out to be,

30 (days in a month) * 24 (hours in a day) * 0.12 (cost per hour) * 2 (number of instances)
= $172.80 per month

Now you are wondering the worker role is just sitting there doing nothing for most of those hours. Shouldn’t you only count the “compute hours” in which the role is actually is alive and doing work instead of the full 24 hours for a day. Well, that’s not how Windows Azure billing work. It’s pay as you go alright but not at that granularity so you end up paying as long as your have reserved the VM, even in the suspended state. May be some day Azure will be able to provide that level of billing granularity – may be we should request that feature on the forum :-) But till then the only way to save cost here will be - if we just got rid of one role entirely and still do all the work with just one role. Turns out it’s very easy to do that on Windows Azure.

To understand how to do that we first need to understand how web and worker role differs in Windows Azure. One obvious difference  is the web role will have an IIS installed on the VM and the work role will not. What else? Well, turns out that’s about it. In every other sense as far as Window Azure is concerned those roles are pretty much the same. You could potentially have your worker role listen on port 8080 and receive web traffic and your web role have a Run()method that does the background work. When you create a Cloud project in Visual studio, by default in the webrole.cs the template does not add a Run() method like it does in your worker role but there is nothing that stops you from doing that either because the WebRole class also derives from the same RoleEntryPoint which workers derive from as well.

public class WebRole : RoleEntryPoint
public override void Run()
// This is a sample worker implementation. Replace with your logic.
Trace.WriteLine("WorkerRole1 entry point called", "Information");

while (true)
Trace.WriteLine("Working", "Information");

As simple as that. Once your web role gets provisioned Azure fabric will start start IIS and deploy your application as well as start a worker which you can use to do some background processing. The thing to note that both of these processes are running on the same VM and will share the resources so this technique should not be used where a consistently high throughput is required at all the times by either your website or your background worker. But if you are able to use this technique you end up cutting your compute cost in half for your small service.

Hope that helps.


  1. nice piece of information, I had come to know about your internet site from my friend vinay, delhi,i have read atleast 4 posts of yours by now, and let me tell you, your website gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new post, once again hats off to you! Thanx a ton once again, Regards windows azure training in hyderabad

    1. I feel this is among the such a lot vital info for me. And i am satisfied studying your article. However wanna commentary on few general things, The website style is ideal, the articles is truly nice
      Tangki Panel
      Tangki Fiberglass
      Jual Septic Tank

  2. thanks for sharing wonderful blog with us. its really more helpful to our institute candidates to get aware some useful knowledge keep sharing more information.
    Dot Net training in Chennai

  3. I didn't spend much time to visit many websites. But today I found this accidentally and I got more information from your site.
    Windows Azure course in Chennai | Azure Training center in Chennai | Microsoft windows azure Training

  4. best windows azure online training in hyderabad with work support and job assistance and high quality training facilities and well expert faculty
    to Register you free demo please visit
    windows azure training in hyderabad

  5. Nice Blog. Thank you for Sharing. Enterprise Resource Planning Software Solutions in Chennai. For more details contact us
    erp in chennai | erp software providers chennai

  6. The best thing is that your blog really informative thanks for your great information!
    erp software in chennai | erp solutions in chennai | erp software development company in chennai

  7. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

  8. Good and nice post... thanks for sharing your information... it is very useful to me...
    Android Training in chennai | IOS Training in chennai

  9. Interesting post! This is really helpful for me. I like it! Thanks for sharing!

    Webseiten Gestaltung Lüdenscheid

  10. Interesting post! This is really helpful for me. I like it! Thanks for sharing!
    microsoft office online


  11. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating. Power BI Online Training .

  12. Interesting post! This is really helpful for me. I like it! Thanks for sharing!
    WebDesign Lüdenscheid

  13. The strategy you posted was nice. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
    Photoshop Training Institute in Chennai | Photoshop Training Institute in Velachery

  14. It’s hard to come by experienced people about this subject, but you seem like you know what you’re talking about! Thanks

    Coreldraw Training Institute in Chennai | Photoshop Training Institute in Chennai | CorelDraw Training Institute in Velachery

  15. I enjoy what you guys are usually up too. This sort of clever work and coverage! Keep up the wonderful works guys I’ve added you guys to my blog roll..,

    white label website builder

    mobile website builder

  16. The website is looking bit flashy and it catches the visitors eyes. A design is pretty simple .
    regionale stellenbörse

  17. A fascinating discussion is definitely worth comment. I do think that you need to write more techno on this topic, it might not be a taboo matter but typically people do not speak about such subjects. To the next! All the best!!

  18. I have to search sites with relevant information on given topic and provide them to teacher our opinion and the article. i really enjoy to read this
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

  19. it was a wonderful chance to visit this kind of site and I am happy to know. thank you so much for giving us a chance to have this opportunity.. This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points.

    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery