Actor-based programming is quite appealing and holds a lot of potential.
- Being message-based, it looks like the perfect fit for distributed, horizontally scalable applications.
- With actor methods assured of thread safety while operating in a multi-threading environment, actor-based programming looks like it could become the ideal light-weight alternative to EJB.
- Vertical scaling comes naturally when using actors, and should be much more maintainable than the equivalent code written with threads and locks.
Developers new to actor-based programming quickly become enthralled. It is event-base programming, but with thread safety and modularity. The code is clean and easy to write--as long as the actors are kept small and focused on a single concern. But trouble starts when you start dealing with performance issues.
You try writing a simple benchmark and, as soon as you crank up the numbers you get an out of memory exception. Oh! Actors use one-way messages and there is no flow control. So you add ACK messages to your actors. Suddenly everything is just a bit less clear and application code is a bit more difficult to write.
Now you have your benchmarks working and look at the numbers. Disaster! Actors pass all messages between threads, and that introduces a huge amount of latency. You ask some developers who have more experience with actor-based programming and you are told that you are using actors the wrong way.
A well designed actor-based application minimizes the number of messages that are passed between actors, at least where performance is important. So you stop using small actors which address only a single concern. You loose modularity and clearity. And your actors become big bowls of spaghetti. Actor-based programming becomes ever so much less interesting.
On the other hand, we can change the way actors work, and realize the real potential of actor-based programming. We can introduce 2-way messaging through the use of continuations. And we can minimize the passing of messages between threads. Then we can use small, tightly focused actors with clean/readable code without having to give up performance.