Skip to content

PersistentHubActor configuration

Andrey Leskov edited this page Jul 29, 2016 · 2 revisions

PersistentHub actors manage all sagas and aggregate work. Idea is to have at most once actor for any aggregate or saga running in GridDomai, and keep them in memory only on demand.

By default PersistentHub will create a persistent child actor for any new saga \ aggregate, and keep it in internal list. Initialization is performed on receiving a message with new id. After a child had been initialized all following commands will not trigger child state load from persistence, as child actor will already have up-to-date state. But we cannot hold all child actors in memory forever, as it will took all memory\processor time. PersistenceHub deactivate children after a time of their inactivity.

Behavior is controlled by IPersistentChildsRecycleConfiguration instance passed to hub in constructor.

public interface IPersistentChildsRecycleConfiguration
{
    TimeSpan ChildClearPeriod { get; }
    TimeSpan ChildMaxInactiveTime { get; }
}

Every ChildClearPeriod period hub will scan children seaching for not active in last ChildMaxInactiveTime period. All found children will be gracefully stopped by sending ShutdownRequest message.No additional checks are perfomed.

Child activity is tracked by hub itself on each message resend to child. So it does not care about any direct messages to child actor, if will be presented.

To provide your own settings for aggregates \sagas recycling, register your own implementation of IPersistentChildsRecycleConfiguration in container configuration, passed to GridNode.

class BulkInsertOptimizedChildRecycleConfiguration : IPersistentChildsRecycleConfiguration
{
    public TimeSpan ChildClearPeriod => TimeSpan.FromSeconds(60);
    public TimeSpan ChildMaxInactiveTime => TimeSpan.FromMinutes(30);
}

var containerConfiguration = new CustomContainerConfigration(
    c => c.RegisterType<IPersistentChildsRecycleConfiguration, BulkInsertOptimizedChildRecycleConfiguration>);

Do not register it in a container, because it will be overridden with default value:

public class DefaultPersistentChildsRecycleConfiguration : IPersistentChildsRecycleConfiguration
{
    public TimeSpan ChildClearPeriod { get; } = TimeSpan.FromMinutes(1);
    public TimeSpan ChildMaxInactiveTime { get; } = TimeSpan.FromMinutes(30);
} 
Clone this wiki locally