简体   繁体   中英

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

我正在编写一个小型计算程序,对blob文件进行大量读取操作......我是否应该去工作角色或Web角色....

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.

最终是工作者角色,顾名思义,Web角色旨在回答Web请求,并且根据IIS设置,Web请求可能在1分钟左右后超时。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM