Reputation: 91
What is more efficient in Akka.net, talking to actor selections or interacting with an IActorRef being passed in a message?
Upvotes: 0
Views: 562
Reputation: 41
I think perhaps you're coming at this in the wrong way. I don't know for sure which is 'more efficient' in terms of performance. (Although @Horusiath gives some great guidance on the differences between the two)
The thing is that using ActorSelection is a bit of an anti-pattern in itself and its generally recommended that you use IActorRefs. See point #3 on this blog: Petabridge: The Top 7 Mistakes Newbies Make with Akka.NET
In short; when using Actor Refs, the location of the actor is transparent. The actor you're attempting to interact with could be anywhere in your cluster and it wouldn't matter when using an IActorRef.
That being said, they also have a nice little blog on when ActorSelection might be useful... Petabridge: When Should I Use Actor Selection?
I'd recommend giving both of those links a read through if you're weighing up which to use in your code. Hope this helps!
Upvotes: 2
Reputation: 7542
The best answer would be to benchmark it for your case, as this may depend on multiple conditions (like local/remote communication). When we're talking about communication within the same process, IActorRef
should always be faster. In remote communication the difference may be smaller, but stil in favor of IActorRef
.
That being said, it's important to get the difference between two:
IActorRef
is no longer valid. If it will be created some time later, your old IActorRef
doesn't necessary have to point to it. This is one of the reasons, why you may Context.Watch(actorRef)
to be notified when your actor dies.Upvotes: 2