44
The Concurrency And Coordination Runtime And Decentralized Software Services Toolkit George Chrysanthakopoulos Software Architect Microsoft Corporation

George Chrysanthakopoulos Software Architect Microsoft Corporation

Embed Size (px)

Citation preview

Page 1: George Chrysanthakopoulos Software Architect Microsoft Corporation

The Concurrency And Coordination Runtime And Decentralized Software Services Toolkit

George ChrysanthakopoulosSoftware ArchitectMicrosoft Corporation

Page 2: George Chrysanthakopoulos Software Architect Microsoft Corporation

Announcing CCR And DSS Toolkit 2008

Enables developers to more easily create loosely-coupled concurrent and distributed applications

Allows early adopters to use the technologies today for building commercial and non-commercial applications

Provides early adopters access to select technologies today; transitioning to Microsoft’s .NET Framework in future

Page 3: George Chrysanthakopoulos Software Architect Microsoft Corporation

Robots are complex and heavily depend on coordination between software components

The application (robot solving a problem) is a composition of hardware and software, developed by different people

Performance, determinism are critical Concurrency, isolation

Re-use enables progress

CCR/DSS Initially applied in robotics

Page 4: George Chrysanthakopoulos Software Architect Microsoft Corporation

CCR/DSS Toolkit At A Glance

Runtime• Coordination and

Concurrency runtime (CCR)

• Decentralized Software Services (DSS)

Authoring Tools• Visual

Programming Language

• Visual Configuration and Deployment

• Visual Studio templates

Services• Samples and

tutorials

• Infrastructure services

Page 5: George Chrysanthakopoulos Software Architect Microsoft Corporation

CCR/DSS Enterprise CustomersBeyond robotics!

Event processing for security systems

Mail sorting systemASP.NET page handling, IO coordination

Page 6: George Chrysanthakopoulos Software Architect Microsoft Corporation

Concurrency And Coordination Runtime

(CCR)

Page 7: George Chrysanthakopoulos Software Architect Microsoft Corporation

Why CCR?

Concurrency Process many tasks (load-balance across cores) Scalability, Responsiveness Exploit latency

Coordination Exercise control without blocking threads Orchestrate asynchronous operations New mechanism to handle failure for

concurrent, asynchronous code Runtime

Advanced scheduler with fairness, throttling Extensible primitives

Page 8: George Chrysanthakopoulos Software Architect Microsoft Corporation

Siemens Infrastructure Logistics Inc.

customer

Page 9: George Chrysanthakopoulos Software Architect Microsoft Corporation

Siemens postal automation handles majority of worldwide mail volume CCR is now basis of next generation

blackboard system AI agents use OCR and database lookup

to determine mail source/destination Publication/subscription systems that

requires high throughput, isolation between components

New version is scalable, readable, extensible

Quick adoption – Took few days, one dev, to get CCR based solution up and running

Customer Use CaseSiemens Automation

Page 10: George Chrysanthakopoulos Software Architect Microsoft Corporation

“We deal in milliseconds and microseconds, and there are not very many commercial products that we can take off the shelf and integrate into our product that can meet our demanding performance criteria…”

“We dropped the CCR code into our application and within a few hours we were able to establish the basic mechanics and flow for our AI agents to work with the Blackboard Framework”

Hamid Salemizadeh, Director of Engineering, Reading & Coding, Siemens Infrastructure Logistics Inc.

David Hudspeth, Software Engineer, Siemens Infrastructure Logistics Inc.

Customer Use CaseSiemens case study quotes

Page 11: George Chrysanthakopoulos Software Architect Microsoft Corporation

Tyco Software House

customer

Page 12: George Chrysanthakopoulos Software Architect Microsoft Corporation

Tyco event management system used from small stores to the White House Next generation now uses CCR at its core

Fast – CCR solution uses only 1 thread per core and is twice as fast

Responsive – Multiple dispatcher queues and fair scheduling prevent starvation of low frequency events

Robust – Causalities simplify failure handling, increase robustness

Quick adoption: Within a week CCR was integrated

Customer Use CaseTyco

Page 13: George Chrysanthakopoulos Software Architect Microsoft Corporation

“With CCR, we see linear scaling. If you double the number of processors, you will see a doubling in performance. That is impressive”

“I came back from the Microsoft conference, and two days later I had removed our thread pool code and we were running with CCR. You can’t beat that”

Stephen Tarmey, Architect, Tyco International’s Software House

Customer Use CaseTyco case study quotes

Page 14: George Chrysanthakopoulos Software Architect Microsoft Corporation

Asynchronous in-process message passing No explicit threads, locks, semaphores!

Task scheduled based on message availability Data-dependency scheduler Models concurrency

Coordination primitives (join, choice, …) Composition of data-driven components

Iterative tasks Express sequential control flow of asynch. tasks

CCR Programming Model

Page 15: George Chrysanthakopoulos Software Architect Microsoft Corporation

DispatcherPort

DispatcherQueues

ThreadsArbiter

HandlerArbiter is attached to port

Arbiter is activated on queue

Dispatcher schedules items from its queues round-robin to run in its threadsPost places a message

on the port

Arbiter checks whether it can consume the message

Creates work item frommessage and handler

Enqueue work item

Thread calls handler with message as arg

Scheduler picks next work item to execute

Page 16: George Chrysanthakopoulos Software Architect Microsoft Corporation

HandlerHandler

DispatcherPort

DispatcherQueues

ThreadsArbiter

Handler

There can be many of everything

Page 17: George Chrysanthakopoulos Software Architect Microsoft Corporation

CCR Coordination PrimitivesExposed via Arbiter methods

Single-Port Primitives

Code-Scheduling(non port-specific)

Multi-Port Primitives

Multi-Port Receiver

Choice (Logical OR)

Join (Logical AND)

Multi-Item Receiver

Single Item ReceiverFromHandler

FromIterator Handler

Interleave(Reader/Writer)

Page 18: George Chrysanthakopoulos Software Architect Microsoft Corporation

Hello, World!

var dispatcher = new Dispatcher(0,”default”);var queue = new DispatcherQueue(dispatcher);var port = new Port<string>(); port.Post("Hello, World!"); Arbiter.Activate(queue, port.Receive(message => Console.WriteLine(message) ));

Port: Building block for sending and receiving messages

Post: Queues a message

Task: Delegate that handles the message (message is consumed)

Receive coordination primitive

Dispatcher uses fixed number of threads, schedules from queues in round-robin

Port on which to receive the message

Page 19: George Chrysanthakopoulos Software Architect Microsoft Corporation

Hello, World!Iterator version

void Start(){ var queue = new DispatcherQueue(); var port = new Port<string>(); port.Post("Hello"); port.Post(“World”); Arbiter.Activate(queue, new IterativeTask(() => Hello(port) ) );}IEnumerator<ITask> Hello(Port<string> port){ for(var i=0; i<5; i++) { yield return port.Receive(); var message = (string)port; Console.WriteLine(message); }

Schedule iterative task

Lambda captures arguments for iterator

Yield execution until receive is satisfied

Item retrieved after yield

Loops around asynchronous operations are easy

Page 20: George Chrysanthakopoulos Software Architect Microsoft Corporation

IEnumerator<ITask> CcrReadFileAsync(string file){ var result = new Port<IAsyncResult>(); using (var fs = new FileStream(file,…,FileOptions.Asynchronous)) { var buf = new byte[fs.Length]; fs.BeginRead(buf, 0, buf.Length, result.Post, null); yield return result.Receive(); var ar = (IAsyncResult)resultPort.Test(); try { fs.EndRead(ar); ProcessData(buf); } catch { // handle exception } }}

CCR InteropAsynchronous Pattern (Begin/End)

Instead of passing a delegate, stream will post AR to port

Retrieve AR result from port

Complete operation

Page 21: George Chrysanthakopoulos Software Architect Microsoft Corporation

CCR InteropUsing adapters for common APIs

static IEnumerator<ITask> CopyStream(Stream source, Stream dest){ var buffer = new byte[4096]; int read = 0; do { PortSet<int,Exception> readResult = StreamAdapter.Read( source, buffer, 0, buffer.Length); yield return readResult.Choice(); var exception = (Exception)readResult; if (exception != null) yield break; read = (int)readResult; var writeResult = StreamAdapter.Write(buffer,0,read); yield return writeResult.Choice(); } while (…)}

CCR Adapter for Stream class

Yield to result outcomes

Retrieve success outcome (bytes read)

Proceed to asynchronous write

Page 22: George Chrysanthakopoulos Software Architect Microsoft Corporation

CCR Concurrent Processing

demo

Page 23: George Chrysanthakopoulos Software Architect Microsoft Corporation

Decentralized Software Services

(DSS)

Page 24: George Chrysanthakopoulos Software Architect Microsoft Corporation

Robust Deep isolation (data and execution) Contain and manage failure Uniform concurrency model

Composable Protocol and runtime support to create, manage,

deploy, data driven applications Runtime and tool support for service bindings Publication/subscription integrated with structured

state manipulation Observable

Service is a living document addressable through URIs Consistent mechanism for configuring, managing and

controlling access

Why DSS?

Page 25: George Chrysanthakopoulos Software Architect Microsoft Corporation

DSSP Protocol

Microsoft Open Specification Promise

DSSP

HTTP

Page 26: George Chrysanthakopoulos Software Architect Microsoft Corporation

Service State – A Live Document<DriveState   <Connected>true</Connected>  <DistanceBetweenWheels>0.112</DistanceBetweenWheels>  <LeftWheel> …  </LeftWheel>  <RightWheel> …  </RightWheel>  <PollingFrequencyMs>80</PollingFrequencyMs>  <TimeStamp>2007-10-10T13:07:45.5195866-07:00</TimeStamp></DriveState>

Flexible UI

Service Orchestration

Page 27: George Chrysanthakopoulos Software Architect Microsoft Corporation

Service Properties Identity (URI) Structured State Composition through

partnering Uniform Behavior

Deep isolation in execution and data

State retrieval and manipulation

Service creation and Termination

Notifications are coupled to state changes

Service As A Unit Of Composition

Page 28: George Chrysanthakopoulos Software Architect Microsoft Corporation

Six Steps To A DSS ServiceDefine Data Types•DATA AND MESSAGE CONTRACTS

Define Service Types•MESSAGE-OPERATIONS•PARTNERSHIPS•POLICIES

Implement Service•MESSAGE HANDLERS•STATE AND PUB-SUB•STATE NOTIFICATIONS

Build Service•VPL TOOL•PROXY GENERATION

Compose Application•DECLARE•DRAW•CODE

Deploy And Run Application•VPL TOOLS•DSS-HOSTED•SELF-HOSTED

Page 29: George Chrysanthakopoulos Software Architect Microsoft Corporation

Define Data TypesExample state and operation types

[DataContract]class State{ [DataMember] public List<Record> {get; set;}}[DataContract]class Record{ [DataMember] public string Name {get; set;} [DataMember] public int Age{get; set;}}// operationclass Query : Query<Record,Record>{}// operation portclass OperationsPort : PortSet<Query,Get,Update> {}

Page 30: George Chrysanthakopoulos Software Architect Microsoft Corporation

Service ImplementationDeclare partnerships, operation port

[Contract(Contract.Identifier)]class RecordKeeperService : DsspServiceBase{ [Partner(“PeopleLookup”, Policy = PartnerCreationPolicy.UseExistingOrCreate, Optional = false)] peopleLookup.OperationsPort _peopleLookupPort = peopleLookup.OperationsPort();

[ServicePort(“/recordkeeper”,AllowMultipleInstances = true] OperationsPort _mainPort;

protected override void Start() { base.Start(); }}

Declarative, dynamic composition, annotations picked up by visual editor

Attach handlers to operation port, publish instance URI in service directory

Page 31: George Chrysanthakopoulos Software Architect Microsoft Corporation

Implement ServiceTypical service handlers

[ServiceHandler(ServiceHandlerBehavior.Concurrent)] public IEnumerator<ITask> QueryHandler(Query queryOp) { var response = FindItem(queryOp.Body); queryOp.ResponsePort.Post(response); yield break; }

[ServiceHandler(ServiceHandlerBehavior.Exclusive)]public IEnumerator<ITask> UpdateHandler(Update updateOp) { QueryAge queryAgeOp; yield return _peopleLookupPort.Query(out queryAgeOp); int age = (int) queryAgeOp.ResponsePort; UpdateRecord(age, updateOp.Body.Name); updateOp.ResponsePort.Post(new UpdateResponse()); }

CCR Interleave is iterator-aware, guaranteeing atomicity across asynchronous steps

Page 32: George Chrysanthakopoulos Software Architect Microsoft Corporation

Dealing With Partial FailureCausalities

Create causality at root of execution graph

Failure occurs on one of the side branchesDeal with error as

message at origin of execution

Page 33: George Chrysanthakopoulos Software Architect Microsoft Corporation

DSS/CCRLogSync Sample

demo

Page 34: George Chrysanthakopoulos Software Architect Microsoft Corporation

Log Sync’ing Demo

Create 1000 services and get their state

Page 35: George Chrysanthakopoulos Software Architect Microsoft Corporation

Visual Programming LanguageOrchestrating DSS services with dataflow Use any DSS service

Connect services Notifications Request/Response

Control and logic Data transformation Control dataflow

Available DSS services

Request

Notification

Response

Service instance

Page 36: George Chrysanthakopoulos Software Architect Microsoft Corporation

DSS Manifest Editor IBuilding applications from components

Choose services to instantiate

Partner services using design time declarations Resolve generic services Local or remote

Set initial configuration Edit initial service

state document Create deployment

Page 37: George Chrysanthakopoulos Software Architect Microsoft Corporation

DSS Manifest Editor IIDistributed applications

Multiple execution nodes A “node”

is an OS process Several nodes

per machine or across machines

Partner services across domains

Create deployment Automatic distributed

startup for testing

Page 38: George Chrysanthakopoulos Software Architect Microsoft Corporation

DSS/CCRVision Processing

demo

Page 39: George Chrysanthakopoulos Software Architect Microsoft Corporation

New product addressing distributed, concurrent applications

Enterprise customers are using it now Lightweight concurrency runtime that can

be dropped in existing code Lightweight, observable service framework

Summary

Page 40: George Chrysanthakopoulos Software Architect Microsoft Corporation

http://www.microsoft.com/ccrdss Download toolkit Documentation (tutorials, videos, user guide) Channel9 Videos Case studies Community Forum

Learn more

Page 41: George Chrysanthakopoulos Software Architect Microsoft Corporation

Evals & Recordings

Please fill

out your

evaluation for

this session at:

This session will be available as a recording at:

www.microsoftpdc.com

Page 42: George Chrysanthakopoulos Software Architect Microsoft Corporation

Please use the microphones provided

Q&A

Page 43: George Chrysanthakopoulos Software Architect Microsoft Corporation

© 2008 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.

Page 44: George Chrysanthakopoulos Software Architect Microsoft Corporation