Multiple worker roles on the same instance
Asked Answered
C

3

7

How can I setup Windows Azure to multiple worker roles is running on the same instance? Is it possible?

Compiler answered 31/5, 2012 at 6:28 Comment(0)
B
8

I think you misunderstand what a Worker Role is. Web and Worker Roles are Window Server VMs, the main difference being Web Roles have IIS running. You may have multiple instances of each.

There's really no such thing as "multiple worker roles in the same instance." Think of Worker Role as a template for your virtual machine: the startup scripts and the event-handling code to deal with messages such as startup and shutdown, along with the code you write that gets packaged and run inside the virtual machine.

From the OnStart() or Run(), you may run pretty much any code you want. Kick off multiple threads, run server code (like Tomcat), etc. Whatever code you have will run in each instance. As you scale out to multiple instances, this same VM template is used on each of those instances.

Please see this answer as well, where I provide a bit more detail.

Blamable answered 31/5, 2012 at 10:55 Comment(0)
M
5

Like David mentioned in his answer you can kick off multiple threads. One of my customers did this by using the ThreadedRoleEntryPoint class.

This class allows you to use multiple worker role entry point classes (even from multiple assemblies) and run them in the same role:

    public override void Run()
    {
        Trace.TraceInformation("WebRole::Run begin", "Information");

        List<WorkerEntryPoint> workers = new List<WorkerEntryPoint>();

        workers.Add(new Worker1());
        workers.Add(new Worker2());

        base.Run(workers.ToArray());

        Trace.TraceInformation("WebRole::Run end", "Information");
    }

The advantage here is that you could start small and run all worker roles (not actually worker roles, but let's call them processes or workers) in a single role (that you actually deploy).

Then, when your business starts growing, you could start using dedicated roles meaning you'll have at least 1 instance running per worker role. And when this needs to happen, the impact on your code will be minimal since the workers passed to the ThreadedRoleEntryPoint inherit from WorkerEntryPoint that looks a lot like the RoleEntryPoint class.

Martyrize answered 31/5, 2012 at 12:38 Comment(0)
D
-2

Yes, you can. Here is the design pattern http://www.31a2ba2a-b718-11dc-8314-0800200c9a66.com/2010/12/running-multiple-threads-on-windows.html

Dustindustman answered 3/6, 2012 at 17:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.