Post on 26-Dec-2015
transcript
Better concurrency with a .NET language for isolation and asynchrony
Niklas GustafssonParallel Computing PlatformMicrosoft Corporation
Niklas.Gustafsson@microsoft.com© 2009 Microsoft Corporation 1
Take-aways
• Concepts– Domains and agents– Channels and protocols– Schema– Dataflow networks
• Examples
© 2009 Microsoft Corporation
Layers of a Concurrent Program
• Asynchronous Agents– Isolation,
asynchrony• Concurrent
Collections– Parallelism,
decomposition• Interacting
Infrastructure– Consistency
Interacting Infrastructure
Asynchronous Agents
Concurrent Collections
© 2009 Microsoft Corporation
Maestro Value Propositions
• Reduce complexity
• Provide a declarative model for serializing access to state
• Leverage latency
• Components default to concurrency
• Provide an application model that is inherently concurrent and responsive
© 2009 Microsoft Corporation
Incubation Objectives
• Is language the better way to go?• Does our model reduce complexity?• Is it feasible and productive to incrementally adopt
Maestro for legacy apps?• Are we building it right?• Syntax and semantics• Missing concepts• Conceptual consistency and composition• Productivity• Platform fit
© 2009 Microsoft Corporation
Maestro from 50,000 Feet
• Imperative• Actor-oriented• Special-purpose• Object-aware• Concurrent by default
© 2009 Microsoft Corporation
• Ada
• Erlang
• SR (U of Arizona)
• Web-based Application Patterns
© 2009 Microsoft Corporation
Maestro Inspiration
Is a parallel system that:Runs on hundreds of millions of coresIs known to scaleIs built by tens of thousands of programmers of
average skill working in thousands of organizationsIs remarkably robust
Maybe there are some things we could learn from how it's programmed?
© 2009 Microsoft Corporation
The Web
Programming model aspects of relevance to manycore:
Loosely coupled
Strictly isolated components
Globally concurrent, locally sequential
Message-passing with simple protocols
Partial failure is expected and common
© 2009 Microsoft Corporation
Web Programming
Sources Of Concurrency
• Asynchronous Agents– An agent has a separate “thread” of control
• Dataflow networks– Multiple nodes “light up” concurrently
© 2009 Microsoft Corporation
Maestro: Core ConceptsDomain Agent
Channel
SchemaPattern
© 2009 Microsoft Corporation
Maestro: Application Structure
Agent:ReaderAgent:Reader
Shared StateShared State
Agent:ReaderAgent:ReaderReader
AgentsReader Agents
WriterAgentWriterAgent
WriterAgentWriterAgent
Domain Domain
Shared StateShared State
Reader Agent
Reader Agent
WriterAgentWriterAgent
WriterAgentWriterAgent
WriterAgentWriterAgent
SchemaSchema
SchemaSchema
Channel w/ protocolChannel w/ protocol
© 2009 Microsoft Corporation
Domain
• Passive construct• Scope of global state• Isolation boundary
domain A{ int j; int func( int k ) { } agent X : Channel1 { } agent Y : Channel2 { }}
domain B{ double m; string func( ) { } agent Z : Channel1 { }}
© 2009 Microsoft Corporation
Agent
• Thread of control• Communicates with
other agents:– Intra-domain– Inter-domain
• Inheritance model• Reader/Writer
declaration
domain A{ int j; int func( int k ) { } writer agent X : Channel1 { } reader agent Y : Channel2 { }}
domain B{ double m; string func( ) { } agent Z : Channel1 { }}
© 2009 Microsoft Corporation
Channel
• Agent proxy• Duplex message-
passing via ports• Enforces value passing
semantics• Bi-lateral channels only,
not a general "open mailbox" concept
channel ChAddition{ input int Add; output int Sum;}
© 2009 Microsoft Corporation
Duality Of Ports
© 2009 Microsoft Corporation
Num1
Channel
Num2
Sum
Num1
Num2
Sum
Agent Implside
Usingside
Each port is both a source and a target, depending on which side of the channel you are using it from, the channel perspective.
Pattern
• Enforces protocol rules• Special states: start
and end• For channels and
networks
channel ChAddition{ input int Add; output int Sum;
Start: { Add -> S1; } S1: { Sum -> End; }}
© 2009 Microsoft Corporation
Schema
• Fields• Functions• Constants• Rules• Serializable• Strong name identity
schema A { required String Name; optional Int32 Age = 0;
rules { require String.IsNullOrEmpty(Name); require Age >= 0; } }
schema B { optional String Name; } B b = ...;A a = b; A a = {Name = “John”, Age = 39};
© 2009 Microsoft Corporation
Dataflow Networks
• Think of data flowing through network– Not objects performing actions!
• Get data, do something with it, pass on to next stage(s)
© 2009 Microsoft Corporation
Network Declarations
• Encapsulates DF layout• Exposes ports• Implementation details
hidden in private methods and fields
network N1{
input string RequestByKey; input int RequestBySize; output ResultRecord Result;
public N1() { … }
layout { RequestByKey ==> Search ==> Result; RequestBySize ==> szTbl.Find ==> Result; }
private Map<int,ResultRecord> szTbl;}
© 2009 Microsoft Corporation
Dataflow Examples
• Compiler:– Characters flow through lexer turning into tokens;– Tokens go through grammar turning into AST;– AST goes through several passes
• Spreadsheet:– Change in a cell triggers reevaluation of
dependent cells;– Independent cells can change concurrently
© 2009 Microsoft Corporation
Example: Image Processor
© 2009 Microsoft Corporation
• Read JPG, Sharpen, Reduce “red eye” effect, Shrink, Save as 85% quality JPG
• Simple pipeline
Network n1 = Read ==> Sharpen ==> RedEye ==> Shrink ==> Save;
Example: Image Processor (2)
© 2009 Microsoft Corporation
• Simple branching
Save
Network n1 = (Read ==> Sharpen ==> RedEye);n1 -<< { Save, Shrink ==> Save};
Example: Image Processor (3)
© 2009 Microsoft Corporation
• Simple branching
Network n1 = (Sharpen ==> RedEye ==> Shrink);Network n2 = (Sharpen ==> RedEye ==> Shrink); // or: n1.Clone();Network n3 = (Sharpen ==> RedEye ==> Shrink); // or: n1.Clone();
Read -<: { n1, n2, n3 } >>- Save;
Sharpen Red Eye Shrink
Sharpen Red Eye Shrink
Concurrency in Network
• Same model: one writer or multiple readers– Reader/writer of what?– Notation: methods write, true functions read
© 2009 Microsoft Corporation
Domain
ReaderAgent1
method1
method2
function1
function2
m1m2f1f2
WriterAgent2
m1m2f1f2
No AccessAgent3
m1m2f1f2
© 2009 Microsoft Corporation
Example: Backup Utility
Example: Backup Utility
GUIController
Profiles
Backup
FolderMonitor
ConfigurationLog
Backup Sched
© 2009 Microsoft Corporation
We're planning a early-access public release through Microsoft DevLabs in the spring.
Download itPlay with itBuild something with itTry to break itTell us what you thinkSpread the word
© 2009 Microsoft Corporation
How to join the band…
© 2009 Microsoft Corporation
Thank You
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market
conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.