Azure Roles and Instances
Asked Answered
R

2

7

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.

Rein answered 10/2, 2012 at 23:38 Comment(0)
T
5

"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.

Treasure answered 11/2, 2012 at 6:55 Comment(0)
U
0

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.

Uella answered 11/2, 2012 at 0:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.