是否确定要尽量使用PLINQ在所有的LINQ查询? [英] Is it OK to try to use Plinq in all Linq queries?

查看:173
本文介绍了是否确定要尽量使用PLINQ在所有的LINQ查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到PLINQ将自动使用非并行LINQ如果发现PLINQ要贵些。所以我想,为什么不使用PLINQ的一切(如果可能),并让运行时决定使用哪一个。

I read that PLinq will automatically use non parallel Linq if it finds PLinq to be more expensive. So I figured then why not use PLinq for everything (when possible) and let the runtime decide which one to use.

该应用程序将被部署到多核服务器和我行制定了多一点code处理并行。

The apps will be deployed to multicore servers and I am OK to develop a little more code to deal with parallelism.

什么是使用PLINQ作为默认的陷阱?

What are the pitfalls of using plinq as a default?

推荐答案

一个坑里跌倒是你失去了利用排序中集的能力。

One pit fall is you lose the ability to leverage ordering in sets.

看看下面code:

var results = new int { 0 ,1 ,2 ,3 };
var doSomethingSpecial = (from r in results.AsParallel() select r / 2).ToArray();

您不能对未来的结果,为了使结果计数的可以的是集合所有排列。这是最大的缺陷之一,在这个意义上,如果你正在处理有序的数据,那么你可能会失去排序的成本,由于性能优势。

You can't count on the results coming in order so the result could be any permutations of the set. This is one of the largest pitfalls, in the sense if you are dealing with ordered data, then you could be losing the performance benefits due of the cost of sorting.

另一个问题是你失去抓称为异常的能力。所以我不能赶上一个空指针异常(不是说你应该永远做到这一点),甚至赶上出现FormatException。

Another issue is you lose the ability to catch known exceptions. So i couldn't catch a null pointer exception (not saying you should ever do that) or even catch a FormatException.

有一吨reasonse为什么你不应该总是使用PLINQ在任何情况下,我将重点介绍只是多了一个。不要看太多爆棚成自动使用非并行LINQ的,它只能处理障碍的情况下查询是简单的,或者是过于复杂,并行运行。

There are a tons of reasonse why you should not always use Plinq in all cases, and i will highlight just one more. Don't read too uch into the "automatic use of non parallel Linq", it can only handle the barrier cases where the query is to simple, or would be too complex to run parallel.

始终牢记越PLINQ使用的资源越多,你会被消耗在服务器上,这是从其他正在运行的线程带走。

Always keep in mind that the more use PLINQ the more resources you will be consuming on the server, which are taking away from other running threads.

资源:

MSDN PLNQ白皮书

保罗·金梅尔在PLINQ

这篇关于是否确定要尽量使用PLINQ在所有的LINQ查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆