如何使用PLINQ在C#中实现MapReduce?

Ram*_*din 7 c# mapreduce plinq c#-4.0 asp.net-mvc-3

如何使用PLINQ在C#中实现MapReduce?

假设您有7-8个WebServices来收集数据,并且每次接收(异步方式)您必须将这些数据放入数据库的某些表中,在我的例子中它是SQL Server 2008.例如,您从每个数据库获取的数据Web服务是:

 <employees>
  <employee>
   <name>Ramiz</name>
  </employee>
  <employee>
   <name>Aamir</name>
  </employee>
  <employee>
   <name>Zubair</name>
  </employee>
</employees>
Run Code Online (Sandbox Code Playgroud)

并且,在每次收到响应时,这些数据都会进入表名 - 员工:

Employee
===
EmployeeID (PK)
EmployeeName
Run Code Online (Sandbox Code Playgroud)

一旦数据进入表格,它必须返回json到客户端,即ASP.NET(MVC 3)应用程序使用客户端JavaScript(ajax)进行此调用.

假设,WebServiceEmployee1已返回数据,其他6个正在队列中(仍在尝试获取数据).然后,它应该将结果集注册到表而不是等待其他6并将插入的员工的数据返回到json中的客户端.而且,保持联系并做其他人同样的方式.

请参阅我的工具箱,我有ASP.NET MVC 3(Razor),SQL SERVER 2008 R2,jQuery.

谢谢.

Pet*_*hie 1

如果不清楚要执行的处理,我建议阅读以下 MSDN 文档:http://bit.ly/Ir7Nvk 它使用 PLINQ 描述了 map/reduce,示例如下:

public IDMultisetItemList PotentialFriendsPLinq(SubscriberID id, 
                                           int maxCandidates)
{
  var candidates = 
    subscribers[id].Friends.AsParallel()                    
    .SelectMany(friend => subscribers[friend].Friends)
    .Where(foaf => foaf != id && 
           !(subscribers[id].Friends.Contains(foaf)))
    .GroupBy(foaf => foaf)                               
    .Select(foafGroup => new IDMultisetItem(foafGroup.Key,
                                       foafGroup.Count()));
  return Multiset.MostNumerous(candidates, maxCandidates);
}
Run Code Online (Sandbox Code Playgroud)

“映射”是Friends.AsParallelSelectManyWhere和,“缩减”阶段是GroupBySelect