Ask and Futures vs. Tell and Receive

232 views
Skip to first unread message

Oliver Schulz

unread,
Mar 11, 2012, 10:58:22 AM3/11/12
to akka...@googlegroups.com
Hi,

I've been wondering: What are the performance and scalability characteristics
of using the ask-Pattern and Futures to handle actor replies versus handling
the replies in the receive block of the actor which sent the request?

As far as I know, ask generates a temporary actor every time. On the other
hand, in many cases (e.g. an actor which has to exchange messages with
other actors to fulfill a request, before processing the next one) ask/Futures
seems easier to code. How high is the price?


Cheers,

Oliver

Roland Kuhn

unread,
Mar 11, 2012, 1:04:40 PM3/11/12
to akka...@googlegroups.com
Hi Oliver,

The price is not zero, but very close to it: the temporary actor is a very simplified one (special AskActorRef) which avoid the asynchronous creation overhead and just pipes the received message into a Promise (synchronously). The cost is therefore a few object allocations (AskActorRef, Promise, TimerTask, eventually an Either) and an entry in a ConcurrentHashMap (for registering the actor’s path so that remoting can find it).

So the usual applies: write the least complicated and still correct code, make it easier to read and understand and let somebody else worry about performance unless forced otherwise.

Regards,

Roland Kuhn
Typesafe – The software stack for applications that scale.
twitter: @rolandkuhn


Oliver Schulz

unread,
Mar 11, 2012, 1:21:59 PM3/11/12
to akka...@googlegroups.com

The price is not zero, but very close to it: the temporary actor is a very simplified one (special AskActorRef) which avoid the
[...]
So the usual applies: write the least complicated and still correct code, make it easier to read and understand and let somebody else worry about performance unless forced otherwise.

Thanks - that's the answer I was hoping for! :-)
 
Reply all
Reply to author
Forward
0 new messages