tpl dataflow

Post on 24-May-2015

498 Views

Category:

Technology

7 Downloads

Preview:

Click to see full reader

DESCRIPTION

Slides from my talk on TPL DataFlow given at the 33rd meeting of the Spbalt.net user group.

TRANSCRIPT

Dmitri Nesterukdmitrinesteruk@gmail.com

A publishes an eventB subscribes to the eventIf lifetime of B < lifetime of A

We can get a memory leak

Weak event pattern

Library for composing async/event-based programsEvent subscription wrapped as IDisposable

Lets you manually unsubscribeUnsubscription automatic when source runs out of data to supply

Declarative subscriptionsPub/sub mechanism

Objects not aware of each otherTypically built on top of a DI containerEach component references the broker

ErlangF# MailboxProcessorAxum (dead)Task Parallel Library (TPL) DataFlow

A library approach

Fine-grainedData-level (SIMD) – not in .NETAutoparallelization

Coarse-grainedUsing threadsWeird synchronization primitives (e.g. Pulse&Wait)TPL DataFlow

A directed graph of dataMessage passingBufferingParallel executionDependency management

Pipeline

Network

read process process write

process

read

process

collate writeprepare

OutputPropagateInput

Read stock market data

Calculate indices

Render to screen

Save to DB

Filter Save to DB

ISourceBlock<T>Source of data; read

ITargetBlock<T>Where you write the data to

IPropagatorBlock<TIn,TOut>Propagator; performs data processing/filtering

As with Rx, ready-made implementations provided

TransformBlockTransforms dataAlso: TransformManyBlock

ActionBlockProcesses the data

Post()Sends a piece of data to the block for processing

LinkTo ()Links a block with the next block in the graphTakes an optional predicateReturns an Idisposable

CancelationTokenSource if you change your mind

Basic block processing

BatchBlock<T>Combines sets of blocks into an array

JoinBlock<2> and <3>Collects 2 or 3 inputs into a Tuple<2/3>

BatchJoinBlockMerger of the aboveCollects Tuple<IList<T>,…>

Provides a data storage bufferCan be used synchronously

block.Post()block.Receive()

or asynchronouslyawait block.SendAsync()Await block.ReceiveAsync()

Grouping Blocks

Not a competitor to Rx or TPL itselfCourse-grained parallelization/sequencing mechanism‘Cheap’ multithreading

Questions?

Конференция по .NET технологиям4 апреля 2014, ПетроКонгрессhttp://dotnext.ruПредлагайте доклады

top related