Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActorSelection versus ActorRef - migrating from actorFor to actorSelection

Tags:

scala

akka

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 ActorRefs.

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 ActorRefs) so long as there is only one actor for that selection and you are only telling 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?

like image 662
user650654 Avatar asked Jul 18 '14 22:07

user650654


1 Answers

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.

like image 123
sourcedelica Avatar answered Nov 05 '22 05:11

sourcedelica