每个实例运行多个 WorkerRoles [英] Run multiple WorkerRoles per instance

查看:33
本文介绍了每个实例运行多个 WorkerRoles的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个 WorkerRole 只做很短的时间,把它们放在一个实例中是浪费金钱.我们可以将它们合并为一个,但会一团糟,在不久的将来,它们应该在负载增加时独立工作.

I have several WorkerRole that only do job for a short time, and it would be a waste of money to put them in a single instance each. We could merge them in a single one, but it'd be a mess and in the far future they are supposed to work independently when the load increases.

有没有办法像创建多站点"WebRole 一样创建多角色"WorkerRole?

Is there a way to create a "multi role" WorkerRole in the same way you can create a "multi site" WebRole?

在消极的情况下,我想我可以创建一个主辅助角色",它能够从给定的文件夹加载程序集,使用反射查找 RoleEntryPoint 派生类,创建实例并调用 .Run().OnStart() 方法.这个主工作者角色"也会重新抛出意外异常,并在 .OnStop() 的所有子 RoleEntryPoint 中调用 .OnStop()叫来了主人.它会起作用吗?我应该注意什么?

In negative case, I think I can create a "master worker role", that is able to load the assemblies from a given folder, look for RoleEntryPoint derivated classes with reflection, create instances and invoke the .Run() or .OnStart() method. This "master worker role" will also rethrown unexpected exceptions, and call .OnStop() in all sub RoleEntryPoints when .OnStop() is called in the master one. Would it work? What should I be aware of?

推荐答案

正如其他人提到的,这是最大化实例利用率的一种非常常见的技术.可能有一些示例和框架"抽象了工作人员基础结构和您想要完成的实际工作,包括这个(我们的)示例中的一个:http://msdn.microsoft.com/en-us/library/ff966483.aspx(向下滚动到内部实现")

As mentioned by others, this is a very common technique for maximizing utilization of your instances. There may examples and "frameworks" that abstract the worker infrastructure and the actual work you want to be done, including one in this (our) sample: http://msdn.microsoft.com/en-us/library/ff966483.aspx (scroll down to "inside the implementation")

最常见的触发工作的方式是:

Te most common ways of triggering work are:

  1. 定时工作人员(如cron"工作)
  2. 基于消息的工作人员(由消息的存在触发的工作).

上面提到的代码示例为#2 实现了进一步的抽象,并且很容易为#1 扩展.

The code sample mentioned above implements further abstractions for #2 and is easily extensible for #1.

请记住,所有与队列的交互都基于轮询.工作人员不会因为队列中的新消息而醒来.您需要主动查询队列以获取新消息.查询太频繁会让微软高兴,但你可能不会:-).每个查询都算作一次计费交易(其中 10K = 0.01 美元).一个好的做法是轮询队列以获取具有某种延迟回退的消息.另外,批量获取消息.

Bear in mind though that all interactions with queues are based on polling. The worker will not wake up with a new message on the queue. You need to actively query the queue for new messages. Querying too often will make Microsoft happy, but probably not you :-). Each query counts as a transaction that is billed (10K of those = $0.01). A good practice is to poll the queue for messages with some kind of delayed back-off. Also, get messages in batches.

最后,将此发挥到极致,您还可以在单​​个实例中组合 Web 角色和辅助角色.请参见此处的示例:http://blog.smarx.com/posts/web-page-image-capture-in-windows-azure

Finally, taking this to an extreme, you can also combine web roles and worker roles in a single instance. See here for an example: http://blog.smarx.com/posts/web-page-image-capture-in-windows-azure

这篇关于每个实例运行多个 WorkerRoles的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆