plinq

Is PLinq Inherently Faster than System.Threading.Tasks.Parallel.ForEach

落爺英雄遲暮 提交于 2019-12-03 13:38:07
Summary : I changed from System.Threading.Tasks.Parallel.ForEach and Concurrent Data structure to a simple plinq (Parallel Linq) query. The speed up was amazing . So is plinq inherently faster than Parallel.ForEach? Or is it specific to the task. // Original Code // concurrent dictionary to store results var resultDict = new ConcurrentDictionary<string, MyResultType>(); Parallel.ForEach(items, item => { resultDict.TryAdd(item.Name, PerformWork(source)); }); // new code var results = items .AsParallel() .Select(item => new { item.Name, queryResult = PerformWork(item) }) .ToDictionary(kv => kv

Is there an asynchronous version of PLINQ?

老子叫甜甜 提交于 2019-12-03 09:00:40
问题 I want to execute a query over a stream of data while processing items in parallel with a certain degree of parallelism. Normally, I'd use PLINQ for that, but my work items are not CPU bound but IO bound. I want to use async IO. PLINQ does not support async work. What's the smartest way of running a PLINQ-style query, but with async work items? Here's a more detailed illustration of the problem: My goal is to process a potentially infinite stream of "items" in a way that is logically

Is there an asynchronous version of PLINQ?

烈酒焚心 提交于 2019-12-02 23:13:44
I want to execute a query over a stream of data while processing items in parallel with a certain degree of parallelism. Normally, I'd use PLINQ for that, but my work items are not CPU bound but IO bound. I want to use async IO. PLINQ does not support async work. What's the smartest way of running a PLINQ-style query, but with async work items? Here's a more detailed illustration of the problem: My goal is to process a potentially infinite stream of "items" in a way that is logically described by the following query: var items = new int[10]; //simulate data var results = from x in items

Is it OK to try to use Plinq in all Linq queries?

做~自己de王妃 提交于 2019-12-02 22:55:03
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. The apps will be deployed to multicore servers and I am OK to develop a little more code to deal with parallelism. What are the pitfalls of using plinq as a default? One pit fall is you lose the ability to leverage ordering in sets. Take the following code: var results = new int { 0 ,1 ,2 ,3 }; var doSomethingSpecial = (from r in results.AsParallel() select r / 2).ToArray(); You can't

Why is PLINQ slower than LINQ for this code?

假如想象 提交于 2019-12-02 05:49:59
问题 First off, I am running this on a dual core 2.66Ghz processor machine. I am not sure if I have the .AsParallel() call in the correct spot. I tried it directly on the range variable too and that was still slower. I don't understand why... Here are my results: Process non-parallel 1000 took 146 milliseconds Process parallel 1000 took 156 milliseconds Process non-parallel 5000 took 5187 milliseconds Process parallel 5000 took 5300 milliseconds using System; using System.Collections.Generic;

Why is PLINQ slower than LINQ for this code?

若如初见. 提交于 2019-12-02 03:07:20
First off, I am running this on a dual core 2.66Ghz processor machine. I am not sure if I have the .AsParallel() call in the correct spot. I tried it directly on the range variable too and that was still slower. I don't understand why... Here are my results: Process non-parallel 1000 took 146 milliseconds Process parallel 1000 took 156 milliseconds Process non-parallel 5000 took 5187 milliseconds Process parallel 5000 took 5300 milliseconds using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace DemoConsoleApp { internal class Program { private

Max tasks in TPL?

天大地大妈咪最大 提交于 2019-12-01 17:34:29
I want to use TPL in Worker process on Windows Azure. I'm looking to add an IJob the queue, this has a Run method, so the worker will consist of: loop get item off queue Use TPL to call IJob.Run, this is an async call But I'm a bit concerned about the maximum items I can add to TPL? I'm happy to build my own TPL Pool of some sort if required, just checking it capabilities. Cheers, Ash. Reed Copsey One of the main goals of the TPL is to remove the need to worry about this. By decomposing your work into Tasks instead of Threads, you're allowing the scheduler to handle the balancing of this more

Max tasks in TPL?

限于喜欢 提交于 2019-12-01 17:27:33
问题 I want to use TPL in Worker process on Windows Azure. I'm looking to add an IJob the queue, this has a Run method, so the worker will consist of: loop get item off queue Use TPL to call IJob.Run, this is an async call But I'm a bit concerned about the maximum items I can add to TPL? I'm happy to build my own TPL Pool of some sort if required, just checking it capabilities. Cheers, Ash. 回答1: One of the main goals of the TPL is to remove the need to worry about this. By decomposing your work

Ordered PLINQ ForAll

雨燕双飞 提交于 2019-12-01 15:23:15
The msdn documentation about order preservation in PLINQ states the following about ForAll() . Result when the source sequence is ordered : Executes nondeterministically in parallel Result when the source sequence is unordered : Executes nondeterministically in parallel Does this mean that ordered execution of the ForAll method is never guaranteed? I haven't used PLINQ before, but the following Code Review question seemed like an appropriate usage for it. At the bottom of my answer I write: Events.AsParallel().AsOrdered().ForAll( eventItem => { ... } ); After reading the documentation I

Plinq, Cores and WithDegreeOfParallelism?

自作多情 提交于 2019-12-01 03:48:33
AS far as I understood , Plinq decides how many thread to open ( each on a thread on different core) by cores count. __________ Core 1 Core 2 Core 3 Core 4 ___________ So If I Have a Plinq task which finds all the first 1000 prime numbers , Plink will open a new Thread on each Core in order to maximize the efficiency. So here , each core will be running on 1000/4 numbers , the logic of finding the prime numbers. However I've read that a blocking operations like IO should be used with WithDegreeOfParallelism so that the cpu won't think that this is an intensive cpu operation , and it allowed to