SlideShare a Scribd company logo
PARALLEL & ASYNC
PROCESSING USING TPL
DATAFLOW
Petru Rebeja
Parallel & async processing using tpl dataflow
AGENDA
• What is Dataflow?
• When to use it?
• How to use it?
• Q&A
THE BIG PICTURE
CLR Thread Pool
Tasks
PLINQ Parallel Loops
Concurrent Collections
Dataflow
DATAFLOW BENEFITS
• Effortless use of multi-threading
• Performance boost via painless optimization
• Development focus is on the ‘what’ rather than ‘how’
DATAFLOW USAGES
High throughput, low-latency scenarios
Robotics
Manufacturing
Imaging Biology
Oil & Gas
Finance
PROGRAMMING MODEL
• Actor-based programming
• In-process message passing
• Components (blocks) for creating data processing pipelines
ARCHITECTURE
IDataflowBlock
ISourceBlock<TOutput> ITargetBlock<TInput>
IPropagatorBlock<Tinput,Toutput>
COMPOSITION
Source
Target
Propagator
Optional
Transform
BUFFERING BLOCKS
BufferBlock<T>
BroadcastBlock<T>
WriteOnceBlock<T>
EXECUTION BLOCKS
ActionBlock<T>
TransformBlock<T,V>
TransformManyBlock<T,V>
GROUPING BLOCKS
BatchBlock<T>
JoinBlock<T1,T2,…>
BatchedJoinBlock<T1,T2>
BEHAVIOR CONFIGURATION OPTIONS
• BufferBlock<T>
• BroadcastBlock<T>
• WriteOnceBlock<T>
DataflowBlockOptions
• ActionBlock<T>
• TransformBlock<TIn, TOut>
• TransformManyBlock<TIn, TOut>
ExecutionDataflowBlockOptions
• BatchBlock<T>
• JoinBlock<T1, T2[, T3]>
• BatchedJoinBlock<T1, T2>
GroupingDataflowBlockOptions
COMPLETION & CANCELLATION
• To know when a block completes await block.Completion
or add a continuation task to it
• To propagate completion from source to target, set
DataflowLinkOptions.PropagateCompletion when
linking
• Set DataflowBlockOptions.CancellationToken to
enable cancellation
ERROR HANDLING
• If the exception does not affect the integrity of the
pipeline – use a try/catch inside the block
• Otherwise, handle errors outside of the pipeline by
• Adding a continuation to block.Completion
• Propagating errors through the pipeline
DEALING WITH CONCURRENCY
• Rule of thumb: avoid shared state whenever possible.
• Use ConcurrentExclusiveSchedulerPair to perform
updates on shared state
• Be aware of the caveats with
ConcurrentExclusiveSchedulerPair
CREATING CUSTOM BLOCKS
The easy way:
DataflowBlock.Encapsulate<TInput, TOutput>(
target, source)
CREATING CUSTOM BLOCKS
The hard(core) way:
class CustomBlock:
IPropagatorBlock<TInput, TOutput>
{
}
CREATING CUSTOM BLOCKS
Either way you choose, don’t forget to:
• Propagate completion
• Pool for cancellation
REFERENCES & FURTHER READING
Dataflow (Task Parallel Library) http://msdn.microsoft.com/en-us/library/hh228603(v=vs.110).aspx
Stephen Toub
TPL Dataflow Tour
http://channel9.msdn.com/posts/TPL-Dataflow-Tour
Joseph Albahari
The Future of .NET Parallel
Programming
http://channel9.msdn.com/events/TechEd/Australia/Tech-Ed-Australia-
2011/DEV308
Stephen Toub
Inside TPL Dataflow
http://channel9.msdn.com/Shows/Going+Deep/Stephen-Toub-Inside-TPL-
Dataflow
Alexey Kursov
Pipeline TPL Dataflow Usage examples
https://www.youtube.com/watch?v=AI9KxgDF43k
https://www.youtube.com/watch?v=AI9KxgDF43k
Richard Blewett, Andrew Clymer
Pro Asynchronous Programming with
.NET
APRESS 2013
ISBN: 978-1430259206
AKKA.NET http://getakka.net/
QUESTIONS?
THANK YOU!
Petru.Rebeja@gmail.com
Parallel & Async Processing using TPL
Dataflow

More Related Content

Similar to Parallel & async processing using tpl dataflow (20)

PPTX
Parallel Programming
Mindfire Solutions
 
PPTX
Training – Going Async
Betclic Everest Group Tech Team
 
PPT
MTaulty_DevWeek_Parallel
ukdpe
 
PPTX
Parallel extensions in .Net 4.0
Dima Maleev
 
PPTX
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
Panagiotis Kanavos
 
PPTX
C# Parallel programming
Umeshwaran V
 
PPTX
Parallel Computing For Managed Developers
Bala Subra
 
PPT
Task and Data Parallelism
Sasha Goldshtein
 
PPSX
Task Parallel Library Data Flows
SANKARSAN BOSE
 
PPSX
Dev con kolkata 2011 tpl dataflows
Abhishek Sur
 
PPTX
.NET Multithreading/Multitasking
Sasha Kravchuk
 
PPTX
Asynchronous programming
Chester Hartin
 
PPTX
C# 5 deep drive into asynchronous programming
Praveen Prajapati
 
PPTX
Parallel and Asynchronous Programming - ITProDevConnections 2012 (Greek)
Panagiotis Kanavos
 
PPTX
parallel-asynchronous-programming-java.pptx
2022ac05156
 
PPTX
Multi core programming 1
Robin Aggarwal
 
PDF
.Net Multithreading and Parallelization
Dmitri Nesteruk
 
ZIP
.Net 4.0 Threading and Parallel Programming
Alex Moore
 
PPTX
Parallel programming patterns (UA)
Oleksandr Pavlyshak
 
PPTX
Parallel programming patterns - Олександр Павлишак
Igor Bronovskyy
 
Parallel Programming
Mindfire Solutions
 
Training – Going Async
Betclic Everest Group Tech Team
 
MTaulty_DevWeek_Parallel
ukdpe
 
Parallel extensions in .Net 4.0
Dima Maleev
 
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
Panagiotis Kanavos
 
C# Parallel programming
Umeshwaran V
 
Parallel Computing For Managed Developers
Bala Subra
 
Task and Data Parallelism
Sasha Goldshtein
 
Task Parallel Library Data Flows
SANKARSAN BOSE
 
Dev con kolkata 2011 tpl dataflows
Abhishek Sur
 
.NET Multithreading/Multitasking
Sasha Kravchuk
 
Asynchronous programming
Chester Hartin
 
C# 5 deep drive into asynchronous programming
Praveen Prajapati
 
Parallel and Asynchronous Programming - ITProDevConnections 2012 (Greek)
Panagiotis Kanavos
 
parallel-asynchronous-programming-java.pptx
2022ac05156
 
Multi core programming 1
Robin Aggarwal
 
.Net Multithreading and Parallelization
Dmitri Nesteruk
 
.Net 4.0 Threading and Parallel Programming
Alex Moore
 
Parallel programming patterns (UA)
Oleksandr Pavlyshak
 
Parallel programming patterns - Олександр Павлишак
Igor Bronovskyy
 

More from Codecamp Romania (20)

PDF
Cezar chitac the edge of experience
Codecamp Romania
 
PPTX
Cloud powered search
Codecamp Romania
 
PPTX
Business analysis techniques exercise your 6-pack
Codecamp Romania
 
PPTX
Bpm company code camp - configuration or coding with pega
Codecamp Romania
 
PPT
Andrei prisacaru takingtheunitteststothedatabase
Codecamp Romania
 
PPTX
Agility and life
Codecamp Romania
 
PPTX
2015 dan ardelean develop for windows 10
Codecamp Romania
 
PDF
The bigrewrite
Codecamp Romania
 
PDF
The case for continuous delivery
Codecamp Romania
 
PPTX
Stefan stolniceanu spritekit, 2 d or not 2d
Codecamp Romania
 
PPTX
Sizing epics tales from an agile kingdom
Codecamp Romania
 
PPTX
Scale net apps in aws
Codecamp Romania
 
PPTX
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...
Codecamp Romania
 
PDF
Material design screen transitions in android
Codecamp Romania
 
PDF
Kickstart your own freelancing career
Codecamp Romania
 
PDF
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkit
Codecamp Romania
 
PDF
Ecma6 in the wild
Codecamp Romania
 
PPTX
Diana antohi me against myself or how to fail and move forward
Codecamp Romania
 
PDF
Codecamp2015 pimp yourpipeline-saade-jens-1.1
Codecamp Romania
 
Cezar chitac the edge of experience
Codecamp Romania
 
Cloud powered search
Codecamp Romania
 
Business analysis techniques exercise your 6-pack
Codecamp Romania
 
Bpm company code camp - configuration or coding with pega
Codecamp Romania
 
Andrei prisacaru takingtheunitteststothedatabase
Codecamp Romania
 
Agility and life
Codecamp Romania
 
2015 dan ardelean develop for windows 10
Codecamp Romania
 
The bigrewrite
Codecamp Romania
 
The case for continuous delivery
Codecamp Romania
 
Stefan stolniceanu spritekit, 2 d or not 2d
Codecamp Romania
 
Sizing epics tales from an agile kingdom
Codecamp Romania
 
Scale net apps in aws
Codecamp Romania
 
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...
Codecamp Romania
 
Material design screen transitions in android
Codecamp Romania
 
Kickstart your own freelancing career
Codecamp Romania
 
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkit
Codecamp Romania
 
Ecma6 in the wild
Codecamp Romania
 
Diana antohi me against myself or how to fail and move forward
Codecamp Romania
 
Codecamp2015 pimp yourpipeline-saade-jens-1.1
Codecamp Romania
 
Ad

Recently uploaded (20)

PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Ad

Parallel & async processing using tpl dataflow

Editor's Notes

  • #4: When discussing about how to use Dataflow we’ll touch the following points of interest: - programming model (what are the entities exposed by Dataflow?) - configuring the behavior of the entities (parallelism, completion, error handling) - although Dataflow removes the need for dealing with concurrent scenarios there are cases when concurrency is inevitable and developers must properly deal with concurrency pitfalls - whenever the functionality of built-in blocks isn’t enough, Dataflow offers the possibility to create custom blocks
  • #5: .NET Framework 4.0 comes with three APIs for Parallel Programming: Tasks (lower level), PLINQ and Parallel (upper level). The Dataflow library is a natural extension of the TPL library that allows developers to create data-processing pipelines in their applications. The Dataflow library provides a framework for creating blocks that perform a specific function asynchronously. These blocks can be composed together to form a pipeline where data flows into one end of the pipeline and some result or results come out from the other end. This is great when data can be processed at different rates or when parallel processing can efficiently spread work out across multiple CPU cores.
  • #6: Dataflow is a paradigm shift but when the developers overcome the discomfort of the paradigm shift they will benefit from the high expressivity of the code.