服务结构提醒 [英] Service Fabric Reminders
问题描述
文档说:
提醒是一种在指定时间触发参与者的持久性回调的机制.它们的功能类似于计时器.但是与计时器不同的是,提醒会在所有情况下触发,直到行动者明确注销它们或明确删除行动者为止.具体来说,由于Actor运行时会保留有关Actor提醒的信息,因此会在Actor停用和故障转移期间触发提醒.
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
中设置).
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
).
Actor闲置后的前15分钟会发生什么,因此GC并被停用了..那么,如何知道45分钟后重新创建Actor呢?以及它如何知道用于创建Actor的Actor ID?
What happens after the first 15 minutes the Actor is idle so is GC'd and deactivated.. so how does it know to recreate the actor 45minutes later? And how does it know what actor ID to use to create the Actor with?
请问一下,我想知道这些模式是如何工作的:
Asking becasue I am wondering how these patterns work:
https://dajbych.net/azure-service-fabric-scheduled-tasks
推荐答案
假设我们将提醒设置为1小时后运行,但是Actor的空闲超时时间为10分钟,扫描间隔为2分钟(在actor的ActorGarbageCollectionSettings中设置).
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).
Actor闲置后的前15分钟会发生什么,因此GC并被停用了..
What happens after the first 15 minutes the Actor is idle so is GC'd and deactivated..
发生的情况是,Azure Service Fabric会在需要时自动激活actor,并执行提醒代码.使用actor框架(OnActivateAsync/OnDeactivateAsync)提供的事件和虚拟方法,可以很容易地对其进行跟踪.实际上,我有一个 repo ,它准确地显示了使用基于EventSource的日志记录机制.
What happens is that the actor is automatically activated when needed by Azure Service Fabric and de reminder code is executed. Using the events and virtual methods provided by the actor framework (OnActivateAsync / OnDeactivateAsync) this is easy to track. In fact, I have a repo that shows exactly that using the EventSource based logging mechanism.
关于ASF实际上如何跟踪计时器和提醒,我们只能猜测,它们正在开源项目,因此也许您已经可以在源代码.
As to how ASF actually tracks the timers and reminders we can only guess, they are open sourcing the project so maybe you can already look it up at the source code.
EDIT: I see it uses a timer internally, see https://github.com/Azure/service-fabric-services-and-actors-dotnet/blob/develop/src/Microsoft.ServiceFabric.Actors/Runtime/ActorReminder.cs
There is an ActorManager that keeps track of all reminders of a specific ActorId
in a ConcurrentDictionary
.