0

I've been reading through and researching a fair bit on Akka.NET and feel that it's a good fit for a very basic online multiplayer game that I will be developing.

I've been particular interested in the Persistence module within Akka.NET. What I would love to be able to do is take a snapshot of my entire Actor system at any point in time and have that snapshot restored at a time of my choosing (essentially a Save/Load mechanic for the game state). This Saving and Loading of Actor persistence appears to happen quite automatically, whereas I would be looking to manually snapshot the current state of the system and restore at a time of my choosing.

Is such a scenario possible with Akka.NET persistence?

Nafeez Abrar
  • 1,045
  • 10
  • 27
ProxyTech
  • 1,105
  • 8
  • 19

1 Answers1

0

Akka.NET persistence uses event sourcing as its way to persist and recreate actor state. It also supports creating snapshots of the full current state, but this should be regarded as a performance optimalisation and cannot be used alone. Also note that persistence works on a per-actor basis. You cannot freeze the whole system into one state.

However, what you can do is the following: you implement persistence, but just never persist any events. Then you send in a message to the top-level actor that says something like "SaveSnapshotRecursive". All actors receiving that message will save a snapshot and forward the message to their children (they should also record in the snapshot the list of their current children). This snapshot store can just be file based if you like that and you can at any moment use it to restore the full state.

Teun D
  • 5,045
  • 1
  • 34
  • 44
  • Ah, that does sound like a plan... Thank you! So these snapshots would need to be recursively restored then too I take it? Is one able to selectively restore a snapshot by name etc? – ProxyTech Nov 04 '17 at 16:54
  • @ProxyTech If you restore, the Akka.Persistence module will check for snapshots. I think it will use only the latest one. But of course, you could save several and put the one in place that you need. Then it will try to replay all events since the making of the snapshot. But as you have none, that doesn't matter. The nodes should all restore their children, which in turn will get their state from the snapshot, including the list of their children. – Teun D Nov 04 '17 at 21:59