我正在使用 akka 持久性尝试实现一个服务,其中我的状态可能非常大(假设它不适合 RAM)某些实体列表。假设用户希望所有实体的所有历史记录都可用。我可以在 akka 持久性中做到这一点吗?
现在我的演员状态是这样的。
case class System(var processes: Map[Long, Process] = Map()) {
def updated(event: Event): System = event match {
case ProcessDetectedEvent(time, activitySets, id, processType) =>
val process = Process(activitySets.coordinates, time, activitySets.channels, id, processType, false)
copy(processes = processes + (id -> process))
case ProcessMovedEvent(id, activitySets, time) =>
val process = Process(activitySets.coordinates, time, activitySets.channels, id, processes(id).processType, false)
copy(processes = processes + (id -> process))
case ProcessClosedEvent(time, id) =>
val currentProcess = processes(id)
val process = Process(currentProcess.coordinates, time, currentProcess.channels, id, currentProcess.processType, true)
copy(processes = processes + (id -> process))
case _ => this
}
}
如您所见,进程映射存储在内存中,因此如果进程数量很大,应用程序可能会耗尽内存。