开发者

Whether to use a worker role or a web role : Windows Azure

I am writing a开发者_如何学C small computation program with lot of read operations on blob files... Should I have to go for worker role or a web role....


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.


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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜