CharlieDigital / chrlschn

Personal blog using Astro
MIT License
0 stars 0 forks source link

blog/2023/10/dotnet-task-parallel-library-vs-system-threading-channels/ #4

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

@chrlschn - .NET Task Parallel Library vs System.Threading.Channels

Wondering which concurrency library is right for you? Let's dive in!

https://chrlschn.dev/blog/2023/10/dotnet-task-parallel-library-vs-system-threading-channels/

thriolsson commented 1 year ago

I think it would be interesting to compare with the Dataflow library: https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/dataflow-task-parallel-library

sonnemaf commented 1 year ago

What's wrong with this PLINQ solution?

await InstrumentedRun("PLinq @ 4", async () => {
    var tasks = workload.AsParallel()
                        .WithDegreeOfParallelism(4)
                        .Select(item => Task.Delay(item.Delay));

    await Task.WhenAll(tasks);
});
CharlieDigital commented 1 year ago

@thriolsson Michael Shpilt has comparisons of TPL Dataflow, Channels, Rx, and a couple of built in primitives showing TPL Dataflow performing just a bit slower than Channels. But TPL Dataflow covers different constructs.

@sonnemaf Nothing wrong with it, but that like Parallel.For, it is "throttled" by the 4 parallel tasks whereas the Channel has no such constraint so every task runs to blocking and is more "efficient" if your task is heavily I/O bound and you don't have upstream constraints.

h0useRus commented 1 year ago

Very good research, but how about stack allocation difference?