Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka.Net and cache coherence

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

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

like image 333
Lars KJ Avatar asked Oct 19 '22 03:10

Lars KJ


1 Answers

In terms of cache coherence - the actor's state is only ever read on a single thread at a time (whichever thread is processing the actor's mailbox) and typically that actor is going to process up to 30 messages at a time before yielding the thread to another actor. It's similar to how quantums work in the normal Windows / Linux scheduler.

Therefore, you can view the updates to an actor's memory as transactional - there's no way for two processors to access an actor's memory at the same time since it's private and accessible by only a single thread at a given time. As a result of this cache coherency isn't an issue to begin with because the actor model forces a linearizable history of reads and writes to the state.

like image 169
Aaronontheweb Avatar answered Nov 11 '22 10:11

Aaronontheweb