IntroductionHow do you make your synchronous sequential code scalable to multi core processors? By making it asynchronous. Microsoft´s Concurrency Coordination Runtime (CCR) is a great technology to help you with that.
However, when translating sync seq code to async code infrastructure can get in your way. Instead of
you can end up writing:
var serviceQueue = new Port<Request>(); Arbiter.Activate( new DispatcherQueue(), Arbiter.Receive( true, serviceQueue, ProcessRequest ) );
That´s not really intuitive. And then think of chaining together a couple of steps to a process. Maybe your sync seq code has a call stack like this:
A() ... //A1 B() C() ...//B1 D() ...//A2 E()
How do you translate that? Even CCR iterator support does not make it much easier. Also it keeps your code in the "synchronous thinking realm". That´s good on one hand - but on the other hand kind of grounds you in the current programming paradigm.
The CCR Flows approach thus is different. It departs from sync notation altogether. Instead of mapping a sync seq call stack like above to the async world, CCR Flows suggest to switch to flow based programming. Don´t think in call stacks anymore. Instead define how information/data flows through processing stages. Using good old Unix pipes (or Powershell notation) such a flow could look like this:
A1 | C | B1 | D | A2 | E
That´s a straightforward translation of a sync seq process into an async flow - or an asynchronous sequential process. You don´t need to give up sequential thinking. But with CCR Flows you couple sequential processing stages asynchronously and thus very scalable. The above example could roughly look like this:
var flow = Flow<...> .Do<...>(A1) .Do<...>(C) .Do<...>(B1) .Do<...>(D) .Do<...>(A2) .Do<...>(E);
You create a flow like this and then run it for a number of input values.
What happens is they all get executed in an interleaved way - but each still sequentially. After each stage - e.g. A1, D, E - the CCR gets the chance to assign processor resources to another flow instance or flow stage. That way they all move forward and use available CPU power.
How to start?Check out the sources from the version control repository and have a look at the sample project.
Or browse the documentation starting with a SingleFlow.
Table of contents
- How to build simple single path flows from asynchronous stages: SingleFlow
- How to run stages in parallel within a single simple flow: ScatteredProcessing
- How to fork a single flow into parallel flows: ParallelFlows
- How to join parallel flow back into a single flow: JoiningFlows
- How to keep state across messages process by a stage: StatefulStages
- How to do scalable 1:n transformations of input values: OutputIteratorStages
LiteratureIf you want to "get into the mood" of flow-based programming (FBP) you should have look at this: http://jpaulmorrison.com/fbp/. There´s a whole book on the subject online. CCR Flows do not exactly implement FBP as it is described there, though. But never mind. They capture the spirit of FBP, I´d say.
Not affiliated with Microsoft and CodePlex
To remove your project or any question, please contact us: [email protected]