Download - Tpl DataFlow

Transcript
Page 1: Tpl DataFlow

Dmitri [email protected]

Page 2: Tpl DataFlow

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

We can get a memory leak

Weak event pattern

Page 3: Tpl DataFlow

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

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

Page 4: Tpl DataFlow

Declarative subscriptionsPub/sub mechanism

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

Page 5: Tpl DataFlow

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

A library approach

Page 6: Tpl DataFlow

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

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

Page 7: Tpl DataFlow

A directed graph of dataMessage passingBufferingParallel executionDependency management

Page 8: Tpl DataFlow

Pipeline

Network

read process process write

process

read

process

collate writeprepare

Page 9: Tpl DataFlow

OutputPropagateInput

Read stock market data

Calculate indices

Render to screen

Save to DB

Filter Save to DB

Page 10: Tpl DataFlow

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

Page 11: Tpl DataFlow

TransformBlockTransforms dataAlso: TransformManyBlock

ActionBlockProcesses the data

Page 12: Tpl DataFlow

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

Page 13: Tpl DataFlow

Basic block processing

Page 14: Tpl DataFlow

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>,…>

Page 15: Tpl DataFlow

Provides a data storage bufferCan be used synchronously

block.Post()block.Receive()

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

Page 16: Tpl DataFlow

Grouping Blocks

Page 17: Tpl DataFlow

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

Page 18: Tpl DataFlow

Questions?

Page 19: Tpl DataFlow

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


Top Related