0
votes

When working with Scala Akka, we still think about blocking IO, and try to avoid it with patterns, I feel it makes no difference from using threads. Implicitly async IO is a huge differentiator, Erlang and Go provide it at language level, while Scala Akka does not. I feel Scala Akka is not real actor model.

There's a popular blog post Don't use Actors for concurrency, but it's not really a problem of actor model, it's purely a problem of Akka.

2

2 Answers

4
votes

Akka implements the Actor Model as specified by Carl Hewitt et al in 1973: an actor can upon reception of a message

  • send a finite number of messages to actors it knows
  • create a finite number of actors
  • determine the behavior to be applied to the next message

Nowhere does this say anything about how exactly I/O is supposed to be handled. Translating blocking method calls into actor-suspending method calls automatically is on the other hand a violation of the model: actors only act upon messages, nothing else, and declaring some arbitrary method calls to prevent that from happening for some (possibly unbounded) time is not part of the model.

Akka provides IO facilities for network operations that are presented in an Actor Model fashion by exposing an ActorRef that commands can be sent to and results can be received from. Akka Streams includes asynchronous consumption and production of data from and to I/O channels.

I hope this explains why my overall answer is that the premise of the question is flawed.

2
votes

The premise of your question is inaccurate ("...Scala Akka does not."). From the akka documentation:

Actors give you:

Simple and high-level abstractions for concurrency and parallelism. Asynchronous, non-blocking and highly performant event-driven programming model. Very lightweight event-driven processes (several million actors per GB of heap memory).

A basic example of asynchronous message passing to an Actor:

val actorSystem = ActorSystem()

val actorRef = actorSystem actorOf Props[SomeActor]

val message = ???  //some message value

actorRef ! message //asynchronous message passing

In fact, akka exceeds the original Actor Model specification with the ability to lookup Actors by name.

For IO specifically, akka offers many non-blocking solutions:

Granted, Scala the language does not have an embedded Actor Model. But it provides Futures and parallel collections for concurrent computation.

The gist of the blog you quoted was that Futures are much better for concurrent computation (which I agree with), while Actors are for maintaining state. It wasn't claiming that Actors are incapable of concurrency.

Plus, akka is not just Actors. There are Agents, finite state machines, akka streams (implementing the reactive manifesto), and the akka-http library.