6
votes

I'm working on a Service Fabric project using ReliableActors with a state. I save and delete things in the state of the actor, and have some re-activation logic that I want to test.

Is there a way to manually deactivate or garbage collect an actor? I would optimally have a test loading data into the actor, deactivating it, and then run some function to ensure that the actor still opperates as intended.

2

2 Answers

3
votes

You can adjust the time an actor is considered as idle to force more frequent garbage collection. Code from the documentation:

ActorRuntime.RegisterActorAsync<MyActor>((context, actorType) =>
        new ActorService(context, actorType,
                settings:
                    new ActorServiceSettings()
                    {
                        ActorGarbageCollectionSettings =
                            new ActorGarbageCollectionSettings(idleTimeoutInSeconds: 20, scanIntervalInSeconds:20)
                    }))
        .GetAwaiter()
        .GetResult();

As you can see, there are two parameters: idleTimeoutInSeconds — after that time an actor that is doing nothing could be considered for deactivation; scanIntervalInSeconds — time interval in which service fabric will check actors on their inactivity.

1
votes

If you mean delete when you say "deactivate", you can use the following:

await myActorServiceProxy.DeleteActorAsync(actorToDelete, cancellationToken)

An actor is activated the first time a call is made to any of its methods. An actor is deactivated (garbage collected by the Actors runtime) if it is not used for a configurable period of time. An actor and its state can also be deleted manually at any time.

https://github.com/Azure/azure-content/blob/master/articles/service-fabric/service-fabric-reliable-actors-lifecycle.md