简体   繁体   中英

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

I'm new to Actor model. I'm planning on implementing the Actor model for one of my projects, so I started reading about Akka.Net. From the documentation, it appears that the state of the Actor is persisted throughout the life of the Actor.

1.Where is the state stored? On the ram? If so wouldn't we run out of ram space?

2.How do I implement Actor model when I have millions of records? Say I want to implement an Actor for customers table that has a million records. How would I load up the customers?

By default all actor state is represented directly in memory. You can choose to persist it (for scenarios using eventsourcing, there's an Akka.Persistence library), but this is opt in decision.

  1. Akka actors are pretty lightweight. 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.
  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. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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