简体   繁体   English

Azure云服务OnStop

[英]Azure Cloud-Service OnStop

I using Azure Cloud Worker Role for processing incoming task from queues. 我使用Azure云工作者角色来处理队列中的传入任务。 Processing of each task can take up to several hours and each worker-role can handle up to N tasks simultaneously. 每个任务的处理可能要花费几个小时,并且每个角色最多可以同时处理N个任务。 Basically, it's working. 基本上,它可以正常工作。

Now, you can read in documentation that from time to time, the worker role can be shutdown (for software update, OS upgrade, ...). 现在,您可以阅读文档 ,该文档可以不时关闭工作角色(用于软件更新,操作系统升级等)。 Basically, it's fine. 基本上没关系。 But, this planned shutdown cannot forcedly stop the worker-role already running tasks . 但是, 这种计划内的关闭无法强制停止已经在运行的工作角色

Expected: 预期:

When calling the OnStop() method by the environment: 在环境调用OnStop()方法时:

  1. the worker role will stop getting new tasks for processing. worker角色将停止获取新任务进行处理。
  2. Wait for running tasks completion. 等待正在运行的任务完成。
  3. Continue with the planned shutdown. 继续计划的关闭。

Actual: 实际:

OnStop() method can be block for up to 5 minutes . OnStop()方法最多可以阻止5分钟 I cannot guaranty that I'll finish processing the task in 5 minutes - so, this is problem... My task is being killed in the middle of processing and this became unstable situation for my software. 我无法保证我会在5分钟内完成任务的处理-因此,这是个问题...我的任务在处理过程中被杀死,这对我的软件来说是不稳定的情况。

How I'm can avoid this 5 minutes limit? 我如何避免5分钟的限制? Any tip will be welcome. 任何提示都将受到欢迎。

How I'm can avoid this 5 minutes limit? 我如何避免5分钟的限制?

Unfortunately, you can't. 不幸的是,你不能。 This is a hard limit imposed from Azure side. 这是从Azure方面强加的硬限制。 You will need to work around that. 您将需要解决此问题。

There are two possible solutions I can think of and both of them would require you to rethink about your current architecture: 我想到了两种可能的解决方案,而这两种解决方案都需要您重新考虑当前的体系结构:

  1. Break your one big task into many smaller tasks and create some kind of work flow. 将您的一项大任务分解为许多较小的任务,并创建某种工作流程。
  2. Make your task idempotent so that even if it gets terminated in between (because of worker role shutdown or error in task itself) and when it gets pick up by another instance, it starts again in such a way that your output of the task is not corrupted. 使您的任务具有幂等性,以便即使它在两次执行之间终止(由于辅助角色关闭或任务本身出错)而又在另一个实例执行任务时终止,它也以不会导致任务输出的方式重新启动损坏。

No, you cannot bypass this limit. 不,您不能绕过此限制。 In general you should not rely on any of your instances running continuously for any long period of time. 通常,您不应依赖任何长时间连续运行的实例。 Instances may be suddenly stopped or they may suddenly disappear (because of an underlying server failure). 实例可能突然停止或可能突然消失(由于基础服务器故障)。 You software should be designed such that when an instance is restarted (possibly redeployed) or some other instance finds capacity to take a previously released work item that work item is reprocessed without any adverse effects. 您应该对软件进行设计,以使其在重新启动(可能重新部署)实例或其他某个实例时具有处理先前发布的工作项的能力,从而可以对该工作项进行重新处理而不会产生任何不利影响。

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

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