Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top