服务结构提醒

Service Fabric Reminders

Documentation 说:

Reminders are a mechanism to trigger persistent callbacks on an actor at specified times. Their functionality is similar to timers. But unlike timers, reminders are triggered under all circumstances until the actor explicitly unregisters them or the actor is explicitly deleted. Specifically, reminders are triggered across actor deactivations and failovers because the Actors runtime persists information about the actor's reminders.

假设我们在 1 小时后将提醒设置为 运行,但 Actor 的空闲超时为 10 分钟,扫描间隔为 2 分钟(在 Actor 的 ActorGarbageCollectionSettings 中设置) .

在 Actor 空闲的前 15 分钟之后会发生什么,因此会进行 GC 和停用。那么它如何知道在 45 分钟后重新创建 Actor?它如何知道使用哪个演员 ID 来创建演员?

询问是因为我想知道这些模式是如何工作的:

https://www.codit.eu/blog/2016/08/25/how-to-enable-automatic-scheduling-in-service-fabric-actors/

https://dajbych.net/azure-service-fabric-scheduled-tasks

Let's say we have a reminder set to run after 1h, but the Actor has an idle timeout of 10 minutes and scan interval of, say 2 minutes (set in the actor's ActorGarbageCollectionSettings).

What happens after the first 15 minutes the Actor is idle so is GC'd and deactivated..

发生的事情是当 Azure Service Fabric 需要时自动激活参与者并执行提醒代码。使用参与者框架 (OnActivateAsync / OnDeactivateAsync) 提供的事件和虚拟方法,这很容易跟踪。事实上,我有一个 repo 可以准确显示使用基于 EventSource 的日志记录机制。

至于 ASF 如何实际跟踪计时器和提醒,我们只能猜测,他们正在开源该项目,所以也许您已经可以在 source code.

上查看它了

编辑:我看到它在内部使用了一个定时器,参见https://github.com/Azure/service-fabric-services-and-actors-dotnet/blob/develop/src/Microsoft.ServiceFabric.Actors/Runtime/ActorReminder.cs

有一个 ActorManager 可以跟踪 ConcurrentDictionary 中特定 ActorId 的所有提醒。

编辑 2:在您在问题中添加的 docs 中明确说明:

Reminders are a mechanism to trigger persistent callbacks on an actor at specified times. Their functionality is similar to timers. But unlike timers, reminders are triggered under all circumstances until the actor explicitly unregisters them or the actor is explicitly deleted. Specifically, reminders are triggered across actor deactivations and failovers because the Actors runtime persists information about the actor's reminders.