Let's rokk! [Tudor Cret's blog]

January 25, 2010

Behind ciripescu.ro, a Windows Azure cloud application (part 3)

Filed under: Technologies — Tudor Cret @ 2:13 pm
Tags: , , , , , , ,

Let’s go deeper(2) – worker role and queues

As mentioned above a worker role can be compared with a windows service. A little thing that sits quiet and it waits for its job. You tell it what to do, it knows how, you give it some input or not and it does its job. Also a worker can be seen as a background unit ready to execute a task. It depends on each one imagination and needs on how worker roles are used. Currently ciripescu.ro uses a worker role for email sending. It represents a “smart” email sender. Why smart? First of all we import a list of yahoo contacts to which an invitation has to be send. A person has 200 or 300 contact emails in his/her list. You can’t block the user until you send those emails. Also if you have online 10 users then you’ll have to send 2000-3000 emails in the same time. But what are doing if you have 500 users in the same time?  Also another problem appears. Yahoo for example banns you, if you send a large amount of emails per minute from the same email addres, even if you sign that emails. It sees that emails as spam. To avoid all these in the worker role we’ve built a scheduler for emails sending, of course giving priority to urgent mails such as ‘Welcome email’  or ‘Password reset. We’ve used queues to “tell” the worker the recepient(s) and the body of that email. More about Queues and communication can be found in Windows Azure training kit and Windows Azure SDK.

Azure Queues are a wonderful mechanism. They allow the communication between process threads or roles and they are based on a producer-consumer system. I can say that somehow they resolve the concurency problems of a distributed system. Ciripescu.ro uses one queue for sending urgent emails and another one for the rest of the emails, not urgent – that are sheduled upon a timetable. In the figure below you can see defined queues and how a new item (invitation message) is added to the queue, in web role:

Adding a new item to Azure Queue

Now the worker will consume the item recently added and it will deliver an invitation mail to ciripescu.ro upon a well known delivery timetable, like in the figure below:

Consuming a queue item


First we get the queue used for sending invitations emails (service.GetQueue(…)), we check if the queue exists/has items(queue.DoesQueueExist()) and then we consume the item by sending and email and deleting the item from queue(queue.DeleteMessage(..)).

In the beginnings of Windows Azure(winter 2009) a worker once started it would entered in  sleep state if it has nothing to process, or we needed to have an up and running worker all the time in order to process emails. For this an infinite loop was created (‘while(true)’), and the loop was triggered when the worker starts. In the last release of Azure this is resolved and all code inside the infinite loop should be passed to Run()  method defined by the role.

Azure costs…a lot of money from a developer point of view. And because at the beginnings of Azure the number of workers was limited to one, we’ve found a trick to limit the numbers of workers –  now is good to save some money.  What if when a worker starts you start more threads, each thread processing what a worker would normally do? Of course that you lose in performance, but it is a solution….

Outro or instead of conclusions

 Microsoft announced that upgrade from Community Technology Preview (CTP) accounts of the Windows® Azure™ platform (i.e., Windows Azure, SQL Azure and/or Windows Azure platform AppFabric) to paid commercial subscriptions is available, starting with January 4th. And IT COSTS.  The problems about the costs are relative. How much can an Azure application costs you can be calculated here using TCO and ROI.  Probably it’s a long discussion about which companies are going to pay for Azure, who is going to develop applications using Azure (since testing in the real cloud costs…etc) and more pages are required for this analysis. But for sure Azure is dedicated to enterprise applications,  to large companies which don’t want to invest more money in their own hardware and datacenters, which doesn’t want to invest more in sys admins. It’s sure that those may watch Azure as a storm in their activity. It’s sure that in the next years the biggest applications of the world will be in the cloud. Not only Micro$osft cloud…the others too. It’s sure that for small companies it will be hard to develop Azure applications.  We want to see Microsoft that comes and says: “No….it’s not sure…because…at least for the pricing…”. On the other hand Microsoft invested a lot in data centers and they must recover their money. Also you don’t need the cloud to host a simple web application with a small database in backend. There are enough companies to do this almost for nothing.

 Also it’s sure that www.ciripescu.ro will live as long as Azure will be in CTP. It’s sure that we liked to work with azure and to develop this application. I say “WE” because we are two of us who plays with Azure for almost one year. And here I want to thanks to my  colleague and friend Tudor Carean for his work at this project. 

In the end I would point what we liked most at windows azure, but also what we don’t like so much, when building http://www.ciripescu.ro:

  • Azure costs….a lot. For Ciripescu.ro it costs too much to pay after the CTP account will be disabled. It’s better to develop a non-cloud version and to host it on-premises.
  • We don’t like Azure Tables storage model(used at ciripescu.ro), because sometimes it is too rigid.  It is a good model, but it could have been better.
  • When deploying the application to the cloud it takes some time. The whole deployment mechanism is a black box process. You are not sure how much time to estimate with deployment.
  • Azure is  a new paradigm (at least for us),  it introduces the concept of cloud and cloud computing.
  • We like the idea of “worker role” and “web role” and the possibility of building hybrid applications .
  • Azure adoption was easy, it happened for just one time to reinstall windows because of Azure CTP kits 🙂
  • We like the idea of scalability and how it is implemented – “Azure is one click scalable”.
  • Availability and durability are also strong points of Azure.

Probably there are more others too…

Source code of the entire application is available on codeplex at http://ciripescu.codeplex.com/ .  For additional informations please contact me using contact details from the about page or send an email at contact [at] bitstarsolutions.com.


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: