Akka has deprecated actorFor
in favor of actorSelection
. The former returns an ActorRef
while the latter returns an ActorSelection
which could be a collection of ActorRef
s.
When migrating from actorFor
to actorSelection
, you have a couple of optoins:
Option 1: Both ActorSelection
and ActorRef
have a tell
method, so you could almost exchange actorSelection
for actorFor
(this is not always true - ask
is not the same and actorSelection
could point to multiple ActorRef
s) so long as there is only one actor for that selection and you are only tell
ing the actor.
Option 2: Get an ActorRef
from the ActorSelection
. This can be done using either Identify
(which involves a couple more messages) or resolveOne
(which involves a Future
).
In Option 1, what kind of overhead does ActorSelection
add compared to the ActorRef
from actorFor
?
Is there a better option than the ones listed above?
There is overhead for using ActorSelection
versus ActorRef
, specifically:
It is not as performant as with ActorRef, since it has to traverse the hierarchy of actors in the path. If you use remote sends the actor selection traversal will unlikely be the bottleneck, but you have to verify that for your specific usage. We optimized ActorSelection in 2.3.x, so it will be faster when you update to that version.
Source: Post by Patrik Nordwall on the Akka User list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With