简体   繁体   English

使用某些命令自动缩放云服务

[英]Autoscaling of Cloud services which works with some commands

I have custom workers as Cloud services(classic) on Azure.我在 Azure 上将自定义工作器作为云服务(经典)。 I have scheduled autoscaling of amount of instances for business hours (5) and others (20).我已经安排了工作时间 (5) 和其他时间 (20) 实例数量的自动缩放。

Sometimes there is a problem when some workers are working with commands but it is the beginning of business hours, so instances are "killed" (scale down).有时当一些工作人员正在处理命令时会出现问题,但这是营业时间的开始,因此实例被“杀死”(缩小)。 As result commands aren't finished.结果命令没有完成。 Commands are messages from Azure queues.命令是来自 Azure 队列的消息。 So basically that messages are returned to the queue.所以基本上消息返回到队列。 But it takes some time for another worker to grab that message again.但是另一个工人需要一些时间才能再次获取该消息。

So the question - is there an automatic way of scaling workers only after they finished working with message/command?所以问题是 - 只有在完成消息/命令的工作后,是否有一种自动扩展工作人员的方法?

See the answers at How to Stop single Instance/VM of WebRole/WorkerRole .请参阅如何停止 WebRole/WorkerRole 的单个实例/VM 中的答案

In short, you can use the Delete Role Instances API ( https://docs.microsoft.com/en-us/previous-versions/azure/reference/dn469418(v=azure.100) ) to specify which role instances you want to shut down.简而言之,您可以使用删除角色实例 API ( https://docs.microsoft.com/en-us/previous-versions/azure/reference/dn469418(v=azure.100) ) 来指定您想要的角色实例去关机。 However, this doesn't work with autoscale, and you would have to write some code to determine which instances you want to have shut down.但是,这不适用于自动缩放,您必须编写一些代码来确定要关闭哪些实例。

Generally the better solution is to ensure the work that the worker role instances are doing is idempotent and can be easily resumed.通常,更好的解决方案是确保辅助角色实例正在执行的工作是幂等的并且可以轻松恢复。 It sounds like you already have that design but there are issues with the amount of time it takes, in which case you may have opportunities to break each 'command' into smaller units of work so that progress can be maintained if the processing of that command is picked up later by a new instance.听起来您已经有了这种设计,但是它所花费的时间存在问题,在这种情况下,您可能有机会将每个“命令”分解为更小的工作单元,以便在处理该命令时可以保持进度稍后被一个新实例接收。

Your role's OnStop will be called when it's getting torn down.你的角色的OnStop会在它被拆除时被调用。 Per the docs:根据文档:

Once the OnStop method has finished executing, the role will be stopped.一旦 OnStop 方法完成执行,角色将被停止。 If other code requires time to exit gracefully you should keep the OnStop thread busy until execution is complete.如果其他代码需要时间才能正常退出,您应该保持 OnStop 线程忙碌,直到执行完成。

You can take advantage of this 5 minute grace period to drain active work from the role instance.您可以利用这 5 分钟的宽限期从角色实例中清除活动工作。 If you share a cancellation token throughout your tasks, eg, you can cancel in-flight work during OnStop and handle the cancellation to promptly make the work visible on the queue again instead of waiting for the timeout.如果您在整个任务中共享一个取消令牌,例如,您可以在OnStop期间取消OnStop工作并处理取消以立即使工作再次在队列中可见,而不是等待超时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM