Download presentation
Presentation is loading. Please wait.
1
Elegantní dataflow pomocí TPL
TPL Dataflow Is The Best Library You're Not Using
2
© 2018 SolarWinds Worldwide, LLC. All rights reserved.
Motivation lightweight actor library on top of TPL messages passed from a producer to a consumer consists of built-in blocks used for composing your dataflow you don’t have to care about synchronization no lock, Manual/AutoResetEvent etc single responsibility reusability – blocks might appear in multiple dataflows parallel out of the box TPL = API v Threading/Threading.Tasks namespace Paralelismus, threading thread pool, cancellation support, async/await Klasický scénář – zpracováváte příchozí data, něco s nimi uděláte a pak je třeba pošlete dál. Task, ContinueWith atd. Co když ale musíte mít omezení na počet souběžně běžících tasků? © 2018 SolarWinds Worldwide, LLC. All rights reserved.
3
© 2018 SolarWinds Worldwide, LLC. All rights reserved.
How to get started nuget System.Threading.Tasks.Dataflow DO NOT USE Microsoft.Tpl.Dataflow nuget GitHub: dotnet/corefx/tree/master/src/System.Threading.Tasks.Dataflow used to be part of .NET Framework till 4.5 funny issue - build vs runtime © 2018 SolarWinds Worldwide, LLC. All rights reserved.
4
© 2018 SolarWinds Worldwide, LLC. All rights reserved.
Contents 9 default data blocks execution – ActionBlock, TransformBlock, TransformManyBlock buffering – BufferBlock, BroadcastBlock, WriteOnceBlock grouping – BatchBlock, JoinBlock, BatchedJoinBlock SolarWinds ExpiringBatchBlock – BatchBlock + Timer © 2018 SolarWinds Worldwide, LLC. All rights reserved.
5
Creating a dataflow – i.e. linking blocks together
ISourceBlock<T>.LinkTo(ITargetBlock<T>) source.LinkTo(target, options, criteria) options append (default: true) whether a new link is appended or set as first propagation (default: false) criteria disposable disposable - compare with unsubscribing from .NET events © 2018 SolarWinds Worldwide, LLC. All rights reserved.
6
© 2018 SolarWinds Worldwide, LLC. All rights reserved.
Block options MaxDegreeOfParallelism (default: 1) EnsureOrdered (default: true) BoundedCapacity (default: max) max number of messages that a block might hold if reached, block rejects messages © 2018 SolarWinds Worldwide, LLC. All rights reserved.
7
© 2018 SolarWinds Worldwide, LLC. All rights reserved.
DEMO source: © 2018 SolarWinds Worldwide, LLC. All rights reserved.
8
Additional topics to cover
completion cancellation support encapsulation task schedulers Completion - manual or by exception © 2018 SolarWinds Worldwide, LLC. All rights reserved.
9
© 2018 SolarWinds Worldwide, LLC. All rights reserved.
Recommendations use read-only or immutable types for data being passed around nuget System.Collections.Immutable handle exceptions properly use Rx for async errors - use functional Either<TResult, TException> consider Akka.net in cross-computer scenarios © 2018 SolarWinds Worldwide, LLC. All rights reserved.
10
Required last page sample
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.