Concurrent data access as in Haxl and Stitch

2019-03-30 14:23发布

问题:

This is a follow-up to my previous question.

As I understand from Haxl and Stitch they use a monad for data access. The monad is actually a tree of data access commands. The children are the commands the node depends on. The siblings are executed concurrently.

The business logic creates the monad and then a separate function fetch interprets it.

Now, the question: Suppose I am performing a few data access operations concurrently. I can use an applicative functor (not a monad), which is just a list of commands (not a tree).

Does it make sense ? What if the list contains duplicate commands ?

回答1:

I think by construction of the Fetch values the possibility of repeating the same query is avoided, even in the same round of queries (when they are "siblings" as you say). If you look at the paper, the figure 4 explains the implementation of dataFetch, which is the constructor of Fetch values. It accounts for three possibilities:

  1. The request has never been made before
  2. The request has been made before AND it has been completed
  3. The request has been made before but it has not been completed yet

In the last case you will notice that the value returned has an empty sequence of BlockedRequests, because in this case some other Blocked fetch has it. This way, when the ap function is called with this value it won't concatenate the same repeated request.

BTW I have been trying to implement Haxl in Scala here.