One call to Service Fabric Reliable Dictionary with multiple keys

1.1k views Asked by At

My situation:

  • Stateful Service that houses my reliable dictionary.
  • Stateless WebAPI to act as an endpoint so my other web applications can communicate with my Stateful Service.
  • My other web applications are hitting my stateless WebAPI over 5000 times per page-load to get data out of my reliable dictionary. I know I know... I'm the lucky guy that inherits this legacy code.

The problem:

The latency for each call is around 100 millseconds (I'm debugging locally if that makes any difference) but multiply that by 5000 and we're talking about minutes now.

Instead of passing keys to call my reliable dictionary over 5000 times...Can I just make ONE call to Service Fabric with multiple keys?

2

There are 2 answers

2
grokk On

You can use Eli Arbel's extension on IReliableDictionary https://gist.github.com/aelij/987d974c811865029564f1bbeffb6b47. Something like

      ` var data= await YouReliableDictionary;
        var values= (await data.CreateLinqAsyncEnumerable(txn))
            .Where(x => youMultipleKeys.Contains(x.Key))
            .Select(x=>x.Value)
2
Mert Coskun - MSFT On

It would be worth profiling latency to see where the time is spent. Two possible culprits that come to mind are

  1. Communication between the stateless front-end to stateful back-end
  2. Reliable Dictionary doing disk IO to page in values that where paged out to serve the reads.

Since you are running locally, I assume first is not a problem yet. However, batching read calls to the back-end service would be a good idea to reduce the number of round trips between your services. You can also consider having a cache for reads that do not need to come from the authoritative store. Since you control the communication, this is all in your power.

If the second is the current bottleneck, Reliable Dictionary does not expose a mechanism to batch multiple reads to reduce the number of disk IOs today. If you are willing to increase memory usage for lower latency reads, then you can use Reliable Dictionary Notifications to build an in-memory cache of the Reliable Dictionary you would like low latency reads from.