Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the use cases for TPL Dataflow over Reactive Extensions (Rx)

I'm specifically looking at writing some signal processing algorithms in one or other, or maybe some combination of both of these.

Performance isn't a big concern, clarity of expressing intent is more important.

I'd be looking to implement the following 'Blocks' and compose them:

  • Filters (both FIR and IIR)
  • Phase Detectors
  • Integrators
  • Mixers
  • Function Generator
  • PLL (using the above as building blocks)

I get that Rx can be considered as 'Linq-to-streams', and TPL is an abstraction over concurrency. I also get that Rx uses TPL internally to manage its asynchronous bits and that TPL dataflow adds composability to TPL.

So both are asynchronous, both are composable, both are quite high level (Rx moreso). Where should each be used, both generally and in my Signal Processing items above?

like image 817
stevenrcfox Avatar asked Feb 28 '12 18:02

stevenrcfox


1 Answers

It depends on what kind of primitives you're dealing with - Rx and TPL are much more richer if you're using amplified types to push data, but if you're dealing with individual samples (such as a IObservable<byte>, ISourceBlock<float> etc.) it might be tedious to work with.

Having recently implemented a Function Generator, FFT, power spectra quantiser among others, I started out with Rx (this wasn't a case for concurrency/parallelism where TPL excels), but found that I spent more time trying to make it work in the Rx model - I eventually settled for System.Stream.

It worked out well for me and was surprisingly composable. However, performance and avoiding GC were top on my list, so if you don't mind either, I'd suggest Rx - you can do some really cool things with reactive combinators.

like image 133
Asti Avatar answered Sep 28 '22 18:09

Asti