10

I am writing a small computation program with lot of read operations on blob files... Should I have to go for worker role or a web role....

veda
  • 5,488
  • 14
  • 53
  • 76

5 Answers5

13

The only difference between a web role and a worker role is that in the web role, IIS (actually Hosted Web Core) gets started and pointed at your app data directory. You can still put code in WebRole.cs that does exactly the same thing as you would do in your worker role, so the decision should really be "Do you want IIS?" If so, use a web role. If not, use a worker role.

user94559
  • 54,841
  • 6
  • 85
  • 93
5

Definitively a worker role, web role is, as the name suggest, designed to answer web requests, and depending on IIS settings, web requests are likely to timeout after 1min or so.

Joannes Vermorel
  • 8,551
  • 10
  • 60
  • 95
2

It's hard to give a definitive answer without more information, but at first glance I would say a worker role. This is like a back-end Windows service, as opposed to something which answers HTTP requests as they arrive.

John
  • 5,046
  • 8
  • 33
  • 37
2

Regarding your question about how to host a worker role: it's the exact same process as hosting a web role - just add a new role to your project, and choose Worker Role instead of Web Role. Roles are nothing more than "virtual machines." And when you select the number of "instances," well that equates to how many virtual machines are running. What @smarx was explaining simply says web roles (or web Virtual Machines) have IIS at your disposal, where worker roles do not.

To see what a worker role is doing, there are two relatively common patterns:

  • put up your own web server (your role can actually launch programs at startup, including such fine things as web servers). In this case, the worker role would return stuff to your caller just as something in a web role. Just without IIS helping out.
  • Communicate tasks to your worker role with a queue. In this case, your worker role reads some message from the queue (you choose formatting of the message). It then acts upon it. Then it goes and reads the next message. Example: You create a photo-sharing site. You put a website up on a web role, and you have an option for a user to upload a photo. You then store it in a database (or table), and put a queue message like "Create Thumbnails for Picture #123". The worker role reads this message, fetches picture #123 from the database, and creates a few thumbnails that it shoves back in the database. That process might take a really long time, but your website visitor never even notices.

If you want to see some great getting-started videos, check out the Cloud Cover Show. Episode 3 talks specifically about creating worker roles, and @smarx shows how to host the Mongoose html server from a worker role.

David Makogon
  • 64,809
  • 21
  • 130
  • 175
0

I'll make it simple

  • web role is for hosting an IIS based web application.

  • worker role is for any other application.

The only real difference between the two is that IIS is installed on the Web Role and your application will be deployed into it.

Marko
  • 19,347
  • 13
  • 45
  • 61