TPL Dataflow with C#

You need TPL if you are developing a system that:

  • Deals with large data
  • Latency issues affect the application
  • Parallel execution is required.
  • Data larger than the hardware specifications (Supply 20GB data into an 8GB RAM)

 

When to NOT use TPL Dataflow

  • Not suitable only for code organization and readability
  • Micro optimization (anything executed in millisecond range)
  • When the persistence State is important (TPL Dataflow mostly exists in memory)
  • Run sequential problems in parallel
  • If TPL overhead becomes an issue, then it is not ideal for the problem

 

It is a library that simplifies implementation for solutions that deal with large data, systems with latency issues or

just need high-performance parallel execution.

 

Characteristics:

  • Execute branches in multiple cores
  • Execute tasks asynchronously
  • It is a push architecture, not a pull. The consumer is offered the Message.

 

TPL Dataflow is designed for developing applications with a non-linear execution circle. It is capable of running multiple branches of code at once, at multiple processor cores, and is also able to run different tasks asynchronously.

 

Asynchronous aspects:

  • Accessing data/resources from different sources from the network
  • Require context synchronization from tasks returning results.

 

Control Flow Programming vs Dataflow Programming

Imagine CFP to be a straight line with multiple workers, each deciding if should process every item. The Dataflow is a parallel line with multiple branches. The way we construct this line will determine which branch (worker) will deal with each item.

 

CFP:

W1

->

W2

->

W3

 

 

Dataflow Programming

W1

->

W2

->

W5

 

->

W3

 

 

 

->

W4

->

W6

 

 

Task Level Parallelization

  • Offers no resource duplication
  • Auto Scaling
  • Prone to run into problems

 

Pitfall of Parallel programming for small amounts of data:

  • The more nested we get the more tasks we create
  • The more tasks we create, the more threads we require from the Operating System
  • The more threads we require, the more threads the Operating System has to manage

This is an expected behavior if the amount of data we process is significantly small making the thread creation and synchronization overhead larger than the gains of running.

 

Benefits of using Dataflow architecture design:

  • Code readability
  • Business mapping
  • Global code orchestration
  • Separation of business and execution logic

 

Task Parallel Library installation

It is a NuGet package published by System.Threading.Tasks.Dataflow


Articles:
TPL interfaces

Ready to spice up your coding game? Discover TPL Dataflow Interfaces for a fun, smooth data flow experience! Let's dive in and get creative!

View

TPL Tricks of Trade

Ready to turbocharge your TPL game? Get the inside scoop on awesome tips and tricks of the trade to level up your template skills! 🚀 #TPLTips

View

Buffer, Transform, Action and go...

Dive into TPL fun with Buffer, Transform, and Action Blocks! Learn how to wield these tools like a coding ninja in our latest blog post! 💻✨ #TPLmagic

View

TPL for RESTful example

Turn your pics into pixel masterpieces with TPL magic at your RESTful API applicaiton! Learn how to spice up images like a digital Picasso! 🎨✨ #TPLartistry

View

Boradcast Block for Rest Api

BroadcastBlock in C#'s TPL: Your data's social butterfly—sharing the love across async streams! 🦋✨ Get ready to spread those bits and bytes! 🚀 #DataSharingFun

View

Multiple HttpClient Get Requests

Have you created an API and want to test its performance without isolating the code? TPL is very handy! Here is an example of sending multiple Get requests 🚀

View

Multiple Concurrent Post Requests

So you have created an API and you want to test it under workload! Using TPL it is easy to send multiple concurrent requests! End to end workload test!

View

Action Block

ActionBlock in C#'s TPL: Your handy async data processor! 🚀 Just toss it some tasks, kick back, and let it handle the rest like a boss! 💪 #AsyncMagic

View

Batch Block

BatcBlock in C#'s TPL: Like a superhero squad for your async data—batching up tasks with style! 🦸‍♂️💥 #AsyncAdventures #SharpDressedCode

View

Transform Block

TransformBlock in C#'s TPL: Your data's makeover maestro! 🎩💫 Just drop in your data, step back and watch it emerge dazzling! ✨ #DataGlowUp

View

TransformMany Block

TransformManyBlock in C#'s TPL: Turning one thing into many—like a data magician! 🎩✨ Get ready for some serious data-multiplying fun! 🚀 #DataAlchemy

View

BoradCast Block

BroadcastBlock in C#'s TPL: Spreading data vibes like a party DJ! 🎵🎉 Pump up the volume on your async data flow! 🔊 #DataPartyTime #BroadcastAwesomeness!

View

Buffer Block

BufferBlock in C#'s TPL: Your data's cozy waiting room—chillin' while async tasks line up! 🛋️✨ Keep that data comfy and queued for action! 🚀 #DataLounge

View

Join Block

JoinBlock in C#'s TPL: Where async streams mingle—like a data matchmaking party! 💘🚀 Get ready for some serious data connections! 🔗 #DataMatchmaker

View

Write Once Block

WriteOnceBlock in C#'s TPL: The one-time data messenger—like a trusty postman delivering data surprises! Only once, not twice! 📬✨ #DataSecrets

View