These are chat archives for akkadotnet/akka.net
and how to deal with them:
In akka.net, currently I've found 2 ways of dealing with loading/harvesing persistent actors.
- you have some aggregate coordinator, which you request for your aggregates. If has internal collection of children aggregates - if they are already loaded, they are returned immediately. If not it will create them and return. In my example there is a limit of allowed children buffer, so that you won't overuse the memory. If limit is passed it will harvest X actors to free part the buffer. Coordinator is a proxy for messages send to aggregates - it also buffers messages waiting for aggregates to being recreated.
- Same think - aggregate coordinator returns aggregates on demand. But here each aggregate uses
Context.SetReceiveTimeoutmethod to identify if it's not used for some period of time. If so, it will receive
ReceiveTimeoutmessage. Then it should send some kind of
Passivatemessage back to coordinator and stop itself. Passivate is necessary so that coordinator knows not to send any messages to the dying aggregate. If there are some messages pending, coordinator caches them, then recreates an aggregate and finally sends waiting messages back to it.
Difference between 1 and 2 is that first defines some pool of actors, that you won't exceed, but you won't know if actor is not used for a longer period of time and be able to automatically free the aggregate pool. In second you don't have a pool, but each actor knows, for how long it has not been used and it's able to "recycle" itself if no longer needed. Cons is that you could possibly have more actors at the moment, than your memory is allowed to fit. Ofc you can create a hybrid of both approaches.
Akka.Cluster.Shardingwill do under the hood