Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TPL DataFlow vs BlockingCollection

I understand that a BlockingCollection is best suited for a consumer/producer pattern. However, when do I use a ActionBlock from the TPL DataFlow library?

My initial understanding is for IO operations, keep the BlockingCollection while CPU intensive operations are bested suited for an ActionBlock. But I feel like this isn't the whole story... Any additional insight?

like image 341
poy Avatar asked Jan 16 '14 13:01

poy


1 Answers

TPL Dataflow is better suited for an actor based design. That means that if you want to chain producers and consumers it's much easier with TDF.

Another big plus for TPL dataflow is that it was built with async in mind. You can both produce and consume in a synchronous way and in an async way (and both at the same time), which is very useful. (I mostly produce in a synchronous way and consume in a non-blocking async way).

You can also very easily set a bounded capacity and degree of parallelism.

TL;DR: BlockingCollection is a simple and general tool. TPL Dataflow is much more robust, but can be an overkill or a bad fit for specific problems.

like image 78
i3arnon Avatar answered Oct 05 '22 18:10

i3arnon