简体   繁体   English

状态存储在Actor模型(Akka.net)中的哪个位置?

[英]Where is the state stored in Actor model (Akka.net)?

I'm new to Actor model. 我是Actor模特的新手。 I'm planning on implementing the Actor model for one of my projects, so I started reading about Akka.Net. 我正计划为我的一个项目实现Actor模型,所以我开始阅读有关Akka.Net的内容。 From the documentation, it appears that the state of the Actor is persisted throughout the life of the Actor. 从文档中可以看出,Actor的状态在Actor的整个生命周期中都是持久的。

1.Where is the state stored? 1.国家存储在哪里? On the ram? 在公羊? If so wouldn't we run out of ram space? 如果是这样,我们不会用完ram空间?

2.How do I implement Actor model when I have millions of records? 2.当我有数百万条记录时,如何实现Actor模型? Say I want to implement an Actor for customers table that has a million records. 假设我想为拥有一百万条记录的customers表实现一个Actor。 How would I load up the customers? 我如何加载客户?

By default all actor state is represented directly in memory. 默认情况下,所有actor状态都直接表示在内存中。 You can choose to persist it (for scenarios using eventsourcing, there's an Akka.Persistence library), but this is opt in decision. 您可以选择保留它(对于使用事件源的场景,有一个Akka.Persistence库),但这是选择决定。

  1. Akka actors are pretty lightweight. Akka演员非常轻巧。 Moderate hardware can easily have millions of active actors. 适度的硬件可以轻松拥有数百万活跃的参与者。 Of course, there is possibility to run out of memory. 当然,有可能耗尽内存。 In this case you can dispose actors that are not currently in use, and if this is still not enough, decide to go distributed and spin up an Akka cluster over several machines. 在这种情况下,您可以处置当前未使用的actor,如果仍然不够,则决定分发并在多台计算机上启动Akka群集。
  2. Usually there's no sense in projecting every table record as an actor. 通常将每个表记录投影为演员是没有意义的。 More useful approach here is to apply DDD (Domain Driven Design) principles: actors map very well on Aggregate Roots concepts known from that methodology. 这里更有用的方法是应用DDD(领域驱动设计)原则:演员很好地映射了从该方法中已知的聚合根概念。 In case of actor load strategy, usually people won't load all of them up front, instead they are creating them lazily as they are needed, and often dispose them after some period of inactivity (so when you know, that target actor won't be used for the next couple of minutes or hours). 在演员加载策略的情况下,通常人们不会预先加载所有这些,而是​​他们在需要时懒洋洋地创建它们,并且经常在一段时间不活动后处理它们(所以当你知道时,那个目标演员赢了'用于接下来的几分钟或几小时)。

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

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