Has got any real benefit of PLINQ?
Asked Answered
O

2

9

Recently I made a couple of measures about Linq and Plinq. I can't see in which situation has a real significant benefit of Plinq.

I've found many examples such as:

Enumerable.Range(0, 10000).AsParallel().ForAll(_ => Thread.Sleep(50000));

This is totally useless example, because it can be parallized with degree of 10000 and yes then will be faster 10000 times, but it's rare in a business application to loop 10000 times and making "IO jobs".

If somebody can mention an example please post it.

Plinq is only available for Linq to Objects and Linq to XML. Not suggested to use it in application which runs on webserver(it has own thread management). So our opportunities are reduced to desktop applications which have multiple cores.

Usually I write linq queries which runs sequentially in fractions of a second. If I parallize it and it really will run parallel then will be faster, but who cares? I think it is still fast enough. The end user won't see any difference.

I can imagine an example when somebody gets all data from DB and running query in memory. Then maybe it's useful, but it's a wrong design.

TPL is a good stuff for asyncron programming, but I'm still not sure Plinq is a useful tool.

Does anybody have positive experience about that?

Odorous answered 17/12, 2013 at 9:10 Comment(3)
"Do Not Assume That Parallel Is Always Faster"...You need to look at Potential Pitfalls with PLINQ!!Caudate
Thanks, I've already looked into :)Odorous
No need to fix what's not broken. PLINQ could make sense for large data on multi-core computers.Anemophilous
C
9

The key scenario in which you get benefit from PLINQ is something like this:

int[] src = Enumerable.Range(0, 100).ToArray();
var query = src.AsParallel()
               .Select(x => ExpensiveFunc(x));

And you do get real benefits.

See the article here for more details on when it's useful.

I've seen benefits when, for example, I'm trying to evaluate an expensive iterative numerical method in order to compute a series of Y values from a set of X points for graphing.

Calliecalligraphy answered 17/12, 2013 at 9:14 Comment(3)
Have you ever written code like this? I understand the benefit of PLINQ theoretically, but I can't imagine the implementation of ExpensiveFunc, I still believe this is a wrong design. What should be inside ExpensiveFunc which is significantly faster in parallel?Odorous
Yes, I have. I was using a 24 core machine, and was trying to calculate 1000 data points, each which take about 200 ms of numerical thrashing to compute individually. The processing time came down from about 3 minutes to less than 15 seconds, and my CPU was nicely maxed out on most of the cores. PLINQ isn't a magic solution, but there are situations in which it brings real benefits. (In my case, the code inside ExpensiveFunc was doing iterative matrix multiplication to compute discrete point voltages for a semiconductor device simulation)Calliecalligraphy
You're welcome. If you feel this answers your question, please mark as the accepted answer! Thanks! :)Calliecalligraphy
S
0

try doing it on a much larger peice of data or a more complex task

_objects.AsParallel().Select(ConvertObject);

bool ConvertObject(object item)
{
//some long running task
}

i use PLinq for a number of Data warehouse ETLs as it can be fast to write and easy to maintain (at a cost perhaps of overall performance)

I Suppose the business case here is speed of development.

Schrecklichkeit answered 17/12, 2013 at 9:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.