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 Blog. Thank you for Sharing. Enterprise Resource Planning Software Solutions in Chennai. For more details contact us
    erp in chennai | erp software providers chennai

  2. 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

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


  4. 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 .

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

  6. 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

  7. 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

  8. 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

  9. 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!!

  10. 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

  11. 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


  12. Is a Yorkie a good family dog?
    Yorkies, like many other Toy breeds, make good pets for people; they're especially good for senior citizens, people with medical issues, and those who may worry about the size and strength of a larger dog. ... They're loving, devoted, and very affectionate: This makes them great personal companions and good family pets.

    Do Yorkshire terriers bark a lot?
    yorkies for sale
    Yorkshire Terriers are little dogs with huge personalities. teacup yorkies for sale With those huge personalities come a fierce territorial bark. Any time your phone rings, someone speaks or knocks on your door, or your doorbell chimes, your Yorkshire Terrier will likely bark. Outside noises aren't even required for barking for some Yorkies. yorkie puppies for sale

    How much do Yorkshire terriers cost?
    yorkie for sale near me
    Typical Yorkie prices range from $1,500 to $3,000, but the cost can fall far below or above that range. Prices will vary based on the puppy's lineage, appearance, health, and the breeder. It's also possible to adopt an older Yorkie for significantly less through a rescue shelter. yorkie for sale


  13. Are Yorkies good for first time dog owners?
    yorkshire terrier for sale
    The Yorkshire terrier is a great starter dog for those who want a little lap dog. This breed is affectionate towards its owner and may even act protective around strangers. teacup yorkie puppies for sale The Yorkie has a moderate energy level and only needs basic exercise.

    Are Yorkie Poo good for first time owners?
    tea cup yorkie puppy for sale
    It is the ideal pet for people who don't want to deal with pet fur at home or in their cars. This is the ideal pet for first time dog owners, since it trains easily and needs only moderate grooming maintenance. Yorkie poos are good with kids. It will play with them, is energetic and affectionate.

    Are Yorkie hypoallergenic? Yes
    yorkshire terrier for sale near me
    How much does a Yorkie Poo puppy cost?
    Yorkie Poo puppies range in price from $1,000 to $3,500, depending on the puppy's coloring and the breeder.

    Are Yorkie Poos good dogs?
    yorkie puppies for sale
    The Yorkipoo is a gentle and loving dog who can do well with children. He's not recommended for homes with very young children, since he can be easily injured when improperly handled. A Yorkipoo can make an excellent companion for an older, more considerate child.


  14. Do Yorkshire Terriers bite?
    Puppies bite beginning at a very young age. They learn this behavior while still with their littermates, long before you bring your Yorkie puppy into your home. yorkshire puppies for sale If the biting can be corrected while a Yorkie is still a puppy, training works best. ... This will be very similar to when a puppy yelps in pain. teacup chihuahuas for sale

    What are Teacup Yorkies?
    Teacup Yorkie is a smaller version of the same pure breed Yorkie, also known as Toy Yorkie or Micro Yorkshire Terrier. It's a tiny dog breed at about 5 to 7 inches tall, weighing between 2 to 4 pounds. The average lifespan of the Teacup Yorkie is around 12 years. yorkie terrier for sale

    Why do they cut Yorkies tails off?
    The main reason that Yorkie tails are docked are for aesthetic purposes. The natural tail is long and sticks up beyond the height of the head. A docked Yorkie has a tail that sticks straight up below the level of the head, which creates clean lines when the hair is worn at show length. yorkie puppies for sale

  15. Reimage PC Repair License Key helps you to free your browser and distinctive programs effortlessly. You can free up your treasured picture with the help Free Reimage Repair License Key