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....
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.
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.
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.
Can anyone give me an example of how to host a worker role....I find most of the examples are for web role...
If I run the program on a worker role, How can I see the results..
Can anyone tell me, how to do or an example of showing how to do will be much better....
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.