Azure Roles and Instances

爱⌒轻易说出口 提交于 2019-11-28 03:59:04

问题


Can I have a Web Role and a Worker role run on the same instance, or do I have to obtain 2 separate hosting instances and pay twice the amount I would otherwise?

I have a WCF Web API that I want to host on Azure. I also have a Worker Role that listens to a Queue in Azure Storage. Every time a message is added to the Queue, it will obtain that and run a small task depending on the message.

I was wondering if I can just run these two on the same instance or not.


回答1:


"Worker Role" and "Web Role" are just simple templates for "Windows Server 2008 with IIS running" and "Windows Server 2008 without IIS running." The key is that a "role" is a definition of a Windows Server virtual machine. For each "role" you have one or more instances.

In Windows Azure, both role types have the ability to install software, modify registry settings, etc. in either a startup script or OnStart() handler, and both let you run code in the Run() method.

In your case, you can run your WCF Web Service in a Web Role, and then in your Run() method (in the same role), kick off a process that listens to queue messages posted by your WCF web services. No need to have a new role.

Now: Once you get into high-volume situations, you might want to split your code into separate roles, so you can scale them independently (both in VM size and VM quantity).

I posted another answer about this here.




回答2:


It completely depends on your requirement. You can simply have a Worker Role that exposes an external endpoint as described here and expose a WCF Service. You can also have Web Role that is a WCF Service and spin up a background thread that checks the queue. What is the Worker doing with the message? What process is performed? That also has an impact on the solution.

A key thing you need to consider is whether the scaling requirement between your WCF Service and the queue retrieving tasks are the same. If they are a single role should be good enough to start with.



来源:https://stackoverflow.com/questions/9236370/azure-roles-and-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!