Akka.Net and cache consistency

I am trying to wrap my head around how akka.net concurrency handles cache consistency. Let's say I have an Actor that stores some kind of state as an instance field, I understand that only one message is processed at a time. But each message can be processed by a different thread from the thread pool, possibly on a different core / socket. How does akka.net ensure that another thread sees all the changes made to the status field?

A somewhat similar discussion regarding akka https://www.lightbend.com/blog/akka-and-the-java-memory-model , but I'm not sure that the cache consistency issue was answered properly (see the last comment).

+4
source share
1 answer

In terms of cache coherency, an actor’s state is only ever read in one thread at a time (which thread processes the actor’s mailbox), and usually this actor is going to process up to 30 messages at a time before transferring the thread to another actor. This is similar to how quants work in the regular Windows / Linux scheduler.

Therefore, you can view updates in the actors' memory as transactional - there is no way for two processors to simultaneously access active memory, since it is private and available only to one thread at a time. As a result of this, cache coherence is not a problem to start with, because the actor model forces the linearized read and write history to state.

+2

Source: https://habr.com/ru/post/1652695/


All Articles