Service Fabric 中升级时的预热服务

Warmup services on upgrade in Service Fabric

我们想知道在 Service Fabric 中是否有一种内置的方式来预热服务作为服务升级的一部分,类似于您可以预热的各种方式,例如基于 IIS 的应用程序池在被请求击中之前。理想情况下,我们希望各个服务在被视为已启动并可供其他服务联系之前执行一些预热任务作为其初始化的一部分(可能是缓存加载、恢复等)。此预热应该是升级域处理的一部分,因此升级过程应该等待预热完成并且服务报告为 OK/Ready。

其他人如何处理此类情况,控制向服务结构发送信号以表明特定服务已完全启动并准备好与其他服务联系的过程?

卫生政策中有这样的概念:

HealthCheckWaitDurationSec The time to wait (in seconds) after the upgrade has finished on the upgrade domain before Service Fabric evaluates the health of the application. This duration can also be considered as the time an application should be running before it can be considered healthy. If the health check passes, the upgrade process proceeds to the next upgrade domain. If the health check fails, Service Fabric waits for an interval (the UpgradeHealthCheckInterval) before retrying the health check again until the HealthCheckRetryTimeout is reached. The default and recommended value is 0 seconds.

Source

不过这是一个固定的等待期。

您还可以发出健康事件 yourself。例如,您可以在热身时报告健康状况 'Unknown'。并调整您的健康政策 (HealthCheckWaitDurationSec) 来检查这一点。

报告健康状况会有所帮助。你不能报告Unknown,你必须尽早报告Error,然后在你的服务准备好后清除Error。 Warning 和 Ok 不影响升级。要清除错误,您的服务可以报告运行状况良好,RemoveWhenExpired=true,低 TTL(阅读 how to report 上的更多信息)。

您必须根据最大预热时间增加 HealthCheckRetryTimeout。否则,如果执行健康检查并且集群被评估为错误,升级将失败(并根据您的策略回滚或暂停)。

因此,事件的顺序是:

  • 您的服务报告错误 - "Warming up in progress"
  • 升级等待固定的 HealthCheckWaitDurationSec(您可以将其设置为最短预热时间)
  • 升级执行健康检查:如果服务尚未预热,则健康状态为错误,因此升级会重试,直到达到 HealthCheckRetryTimeout 或您的服务不再处于错误状态(预热完成且您的服务已清除)错误)。