Search code examples
akkaakka-clusterakka-grpc

Will Akka ShardRegion be a performance bottleneck if `ask` pattern is used instead of `tell`?


I'm a novice to Akka, and I want to create a distributed service by Akka gRPC and cluster sharding, which provides data retrieval service to clients.

So some RequestActor (maybe no such an actor at all with gRPC, I'm not sure) receives a client request, and forwards it to another ProcessingActor by shardRegion for query result.

There're two choices for this:

  • tell pattern
    shardRegion ! Request(raw_request, localRequestActor)

  • ask pattern
    shardRegion ? raw_request pipeTo(localRequestActor)

My questions are,

  1. As all requests will be forwarded via shardRegion actor, so if I use the ask pattern, will shardRegion actor be the performance bottleneck? Or shardRegion just creates an internal actor to handle the future-promise stuff, and once the request is forwarded, shardRegion will not be involved any longer?

  2. I know there's some performance/resource implication in ask compared with tell; on the other hand, ask provides the timeout mechanism, and we'll have to do it by ourselves with tell. As this is a request-response interaction, which is a better choice in my case?

Thanks!


Solution

  • You don't have any additional performance implication when using AskPattern with a shard region actor as an recipient. Because the actor which handles the Ask is created on the machine/ jvm where you instantiate the AskPattern. The shard region actor will not know about it.

    In general it is a better practice to use tell and internal timeout handling within your actor for performance reasons. But if performance is not an issue for you, it's fair to use AskPattern due to less code IMHO.