0

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?

TheSugoiBoi
  • 160
  • 1
  • 13
  • Possible duplicate of [What would be the best way to search an IReliableDictionary?](http://stackoverflow.com/questions/36877614/what-would-be-the-best-way-to-search-an-ireliabledictionary) – LoekD Dec 23 '16 at 07:49

2 Answers2

0

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)
grokk
  • 1
  • I'm a little rusty with my LINQ. Doesn't that just return one value? I want to somehow pass in a list of keys and get a list/dictionary of values back. – TheSugoiBoi Dec 22 '16 at 22:10
  • This is exactly what select is doing. It will return IEnumerable (or in this case IAsyncEnumerable) of values matched by Where condition – grokk Dec 23 '16 at 05:52
0

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.

  • Sorry - I'm still new to this. What does page in and page out mean? I've seen some other people use this term but I couldn't find a definition online. – TheSugoiBoi Dec 29 '16 at 16:53
  • Reliable Dictionary keeps all of the visible state persisted on disk. It also keeps portion of the state in-memory for quick access. When Reliable Dictionary needs part of the state it does not have in-memory, it loads it into memory by reading it from disk. In other words pages it in. When state in-memory grows too large, it removes some out of the memory. In other words pages it out. This is a re-use of the OS term: [Paging](https://en.wikipedia.org/wiki/Paging). – Mert Coskun - MSFT Dec 29 '16 at 18:05