Service Fabric Reminders

风流意气都作罢 提交于 2019-12-23 19:28:31

问题


Documentation says:

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.

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.. 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://www.codit.eu/blog/2016/08/25/how-to-enable-automatic-scheduling-in-service-fabric-actors/

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


回答1:


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..

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.

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.

Edit 2: it is explicitly stated in the docs you added in your question:

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.



来源:https://stackoverflow.com/questions/44117425/service-fabric-reminders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!