The relationship between actor and thread

What is the relationship between actor and thread? How does actor achieve high concurrency with thread ?

Hi @schahaha,
Please note this is a bit simplified.

Akka actors run “on top” of a Thread Pool. This means code within the actors will be running on those threads.
Akka Actors process “one message at a time” so you don’t have to worry about locks. Of course one can run into some concurrency issues if modifying the actor’s internal state in the wrong place.

Regarding how Akka Actors achieve high concurrency, is all due to well tuned code underneath that produces a really low overhead. Why I think you can design highly concurrent systems with Akka Actors is because the Actor Model itself forces you to design and break your architecture in a more concurrent way.

It’s the messages that are being processed on threads in parallel, not the actors. So message after message is processed (on each thread), and depending what actor the message belongs to, that’s the actor that will run on that thread at that moment for that message - and then the next, and so forth. So an actor does not belong to a particular thread (unless you configure it to). And since an actor is so lightweight, like a function, this parallel processing of messages is really fast, and the utilization of threads very high.

Probably I should have written an Actor’s behavior instead of just actor.

Sorry, my post wasn’t a correction of your post or anything like that, I was just having a go at answering the question myself

1 Like

No worries!
I was doubting between answering with a somewhat eagle-eye-view of the thing or one a bit more detailed… I guess OP’s interactions with the Actor Model have been limited until now. Would be good to hear from them if our answers clarified the thing for them