Concurrent data access as in Haxl and Stitch

别说谁变了你拦得住时间么 提交于 2019-12-05 00:08:33

问题


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.



来源:https://stackoverflow.com/questions/27687378/concurrent-data-access-as-in-haxl-and-stitch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!