问题描述:

Possible Duplicate:

Good use case for Akka

I understand why using the AKKA actors framework for embarrassing parallel problems makes sense.

What about problems that don't involve heavy computation and don't need to parallelised at all but are still highly distributed. For example, thousands of distributed clients who can increment or decrement a specific counter?

网友答案:

Besides the obvious distributability and scalability arguments there are other aspects which are really nice about actors.

  • The actor model allows the complete decoupling between message passing and error handling; these two are tightly woven together in traditional OO. When you call a method, you get the return value but you must also handle all possible errors. When you send a message to an actor, you only get the response back, while all failures are handled by the actor’s supervisor.

  • Another nice thing is the improved encapsulation: in “normal” OO you’ll typically see too many things exposed on an object, and if not you can still go in using reflection. Akka actors are completely encapsulated (unless you cheat by sending around “this” references), nobody messes with the state but the actors themselves.

  • Tying into the previous point, the fact that message reception is the only entry point into an actor’s behavior makes them much easier to reason about than normal OO code, where each public (or protected) method may be used as an entrance. You don’t need these invocations to be concurrent in order to miss unplanned interactions.

网友答案:

Actors are a model of computation that lends itself to both distribution and concurrency (and ultimately parallelism) (due to isolation and message passing). So Actors can be used where you only have 1 thread of execution on one single machine, or thousands of threads of execution over thousands of machines.

相关阅读:
Top