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

1

16

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?

Supernal answered 28/2, 2012 at 18:27 Comment(3)
@Paul R Thanks for the edit, hadn't noticed that!Supernal
@Overflow did you settle on an approach? Can you tell us what it is?Jovita
I'll be using both. TPL Dataflow as my basic building blocks, Rx as the implementation inside the blocks. I'm hoping that will get my aims of composability and readable implementation.Supernal
J
7

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.

Jovita answered 1/3, 2012 at 23:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.