简体   繁体   English

我可以在Akka.NET中保存整个Actor系统的状态吗?

[英]Can I save the state of my entire Actor System in Akka.NET?

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. 我一直在阅读和研究Akka.NET上的内容,并认为它非常适合我将要开发的非常基本的在线多人游戏。

I've been particular interested in the Persistence module within Akka.NET. 我对Akka.NET中的Persistence模块特别感兴趣。 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). 我希望能够做的是在任何时间点拍摄整个Actor系统的快照,并在我选择的时间恢复该快照(本质上是游戏状态的“保存/加载”机制)。 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. Actor持久性的保存和加载似乎是自动发生的,而我希望手动快照系统的当前状态并在我选择的时间进行还原。

Is such a scenario possible with Akka.NET persistence? 使用Akka.NET持久性是否可能出现这种情况?

Akka.NET persistence uses event sourcing as its way to persist and recreate actor state. Akka.NET持久性使用事件源作为其持久性和重新创建参与者状态的方式。 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". 然后,您向高层参与者发送一条消息,内容为“ 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. 如果您愿意,此快照存储可以仅基于文件,并且可以随时使用它来恢复完整状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM