Why is an actor “asking” for a pattern considered an anti-pattern or “code smell”?

From what I put together, the ask pattern is considered bad practice and should be avoided. Instead, the recommended model is the actor-on-demand model. However, for me this does not make sense, since the "ask" template does just that - it creates an easy actor for each request. So why is it considered bad, especially when futures are much more complex and able to handle the sorting of multiple shipments / receivers more elegantly?

+8
scala actor akka
source share
1 answer

From Akka docs :

“There are consequences to using a request, because something needs to be tracked when it expires, there must be something that connects Promise to ActorRef, and it must also be accessible via remote access. Therefore, always prefer to talk about performance, and only ask if necessary. "

But sometimes you want to send a message from outside the actor, in which case you can use ask . Using ask ensures that you get a response at the specified timeout, and sometimes what you want. However, when you use the ask pattern, you must ask yourself if you can just use Future instead.

There is a place for ask , but it should have very limited use due to the above reasons.

You do not need to use an actor on request. Some actors must be long-lived, and some not. If an actor performs a potentially dangerous or blocking operation, you can create one for each request. Whatever your application logic.

+8
source share

All Articles