concurrent programming with revisions and isolation types

41
Concurrent Programming With Revisions and Isolation Types Presented by: Ran Breuer Sebastian Burckhardt Microsoft Research Alexandro Baldassin University of Campinas, Brazil Daan Leijen Microsoft Research

Upload: callie

Post on 23-Feb-2016

49 views

Category:

Documents


1 download

DESCRIPTION

Concurrent Programming With Revisions and Isolation Types. Presented by: Ran Breuer. Outline. Introduction Main Ideas and Assumptions Revisions and Isolation Types Comparison to the classic locking scheme Case Study – Space Ward 3D Performance Evaluation Implemetation. int x = 0; - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Concurrent Programming With Revisions and Isolation Types

Concurrent Programming With Revisions and Isolation Types

Presented by: Ran Breuer

Sebastian BurckhardtMicrosoft Research

Alexandro BaldassinUniversity of Campinas, Brazil

Daan LeijenMicrosoft Research

Page 2: Concurrent Programming With Revisions and Isolation Types

Outline Introduction

Main Ideas and Assumptions Revisions and Isolation Types Comparison to the classic locking scheme Case Study – Space Ward 3D Performance Evaluation Implemetation

Page 3: Concurrent Programming With Revisions and Isolation Types

Puzzle Time..What will be printed in line 8?a) 1 , 1b) 1 , 0c) 0 , 1

1 int x = 0;

2 int y = 0;

3 Task t = fork {

4 if (x==0) y++;

5 }

6 if (y==0) x++;

7 join t;

8 Print x , y;

And the winner is:d) All of the above?

Page 4: Concurrent Programming With Revisions and Isolation Types

Let’s use a diagram…int x = 0int y = 0

if (y==0) x++; if (x==0) y++;

assert( (x==0 && y==1) || (x==1 && y==0) || (x==1 && y==1));

1 int x = 0;

2 int y = 0;

3 Task t = fork {

4 if (x==0) y++;

5 }

6 if (y==0) x++;

7 join t;

8 Print x , y;

Page 5: Concurrent Programming With Revisions and Isolation Types

IntroductionSequential Consistency – For every concurrent execution exists a sequential execution that

Contains the same operations Is legal (obeys the sequential specification) Preserves the order of operations by the same process

Linearizability- For every concurrent execution exists a sequential execution

that Contains the same operations Is legal (obeys the specification of the ADTs) Preserves the real-time order of non-overlapping operations

Page 6: Concurrent Programming With Revisions and Isolation Types

Introduction We want to use concurrent programs and tools

deterministically Locking schemes introduce bugs Need to ensure consistency of shared data and

variables Programmers control outcome and run, don’t

leave anything to “chance”

Page 7: Concurrent Programming With Revisions and Isolation Types

Key Concepts in Design Declarative Data Sharing

The programmer uses special isolation types to declare what data can be shared between tasks.

Automatic Isolation Forked asynchronous tasks (Revisions) operate in

isolation. Each Revision operates on a single copy of the entire

shared data. => Guaranteed consistency and stability. Deterministic Conflict Resolution

All conflicts resolved by definition of isolation type involved in conflict

Page 8: Concurrent Programming With Revisions and Isolation Types

Introducing: Revisions Basic unit of concurrency Revisions function like tasks, forked and joined

Called “Revisions” to suit source control systems Main thread considered a Revision as well Joining of all forked revisions is done explicitly by

the programmer

Page 9: Concurrent Programming With Revisions and Isolation Types

Reading Revisions Traditional Tasks Concurrent Revisions

int x = 0;Task t = fork { x = 1;}assert(x==0 || x==1);join t;assert(x==1);

Versioned<int> x = 0;Revision r = rfork { x = 1;}assert(x==0);join r;assert(x==1);

Page 10: Concurrent Programming With Revisions and Isolation Types

Reading Revisions – Revision Diagrams

Concurrent Revisions Revision Diagram

if (y==0) x++;

Versioned<int> x = 0

Versioned<int> y = 0

if (x==0) y++;

assert(x==1 && y==1);

Versioned<int> x = 0;Versioned<int> y = 0;

Revision r = rfork { if (x==0) y++;}if (y==0) x++;

rjoin r;

Fork()

Join()

Page 11: Concurrent Programming With Revisions and Isolation Types

Revision Diagrams – Original look

Concurrent Revisions Revision Diagram

Fork()

Join()

Page 12: Concurrent Programming With Revisions and Isolation Types

Nested Revisions Simplifies modular reasoning

about program execution Typically revisions fork its

own inner revision and then join it. Classic nesting of tasks.

Revisions lifetime is not restricted to lexical scope it is possible that inner (more

nested) revision „survives” outer revision.

Supports ‘fork-join’ pattern

Page 13: Concurrent Programming With Revisions and Isolation Types

Nested Revisions - restrictions

Page 14: Concurrent Programming With Revisions and Isolation Types

Isolation Types When joining revision, we wish to merge the

copies of the shared data back together deterministically

To decide how this merge should be done, we need to know what this data represents Let’s ask the programmer!

The programmer explicitly supplies this information by choosing an appropriate type for the data

Page 15: Concurrent Programming With Revisions and Isolation Types

Types of Isolation (Types)Versioned

Value is changed\merged according to the most recent write

Upon join, we check if value was changed in original revision since fork()

For a basic type T we write Versioned<T> Good for most data and variables

When few writes but many reads When there is a clear relative priority between revisions

Page 16: Concurrent Programming With Revisions and Isolation Types

Types of Isolation (Types) - Versioned

Page 17: Concurrent Programming With Revisions and Isolation Types

Types of Isolation (Types)Cumulative

Combined effect of modifications is determined by a Merge function f

Merge function Takes 3 parameters:

Original – value at time of fork() Master – current value in joining revision Revised – current value in joined revision

We write these types as Cumulative<T,f>

Page 18: Concurrent Programming With Revisions and Isolation Types

Types of Isolation (Types) - Cumulative

Page 19: Concurrent Programming With Revisions and Isolation Types

Complex structures with isolation types

Isolation typed fields might not preserve objects behavior…

Page 20: Concurrent Programming With Revisions and Isolation Types

Comparison to current methods – Locking Schemes Traditional locking scheme

Requires programmers to think about placement of critical sections

Complicates code readability and maintenance Reduces concurrency by pausing tasks

Eg. animating and rendering game objects in separate tasks

Presented solution Isolation of the read-only tasks and single writer task

(so-called double-buffering) Might be not the most space-efficient solution

Page 21: Concurrent Programming With Revisions and Isolation Types

Comparison to current methods – Transactions

Page 22: Concurrent Programming With Revisions and Isolation Types

Case StudySpace Wars 3DGame designed to teach DirectX Programming in C#

Drag picture to placeholder or click icon to add

Page 23: Concurrent Programming With Revisions and Isolation Types

Space Wars 3D – Sequential Version

Shared State

Parallel Collision DetectionParallel Collision DetectionParallel Collision Detection

Graphics Card

Network Connection

Play Sounds

Render Screen

Process InputsAutosave

Send

Receive

DiskKeyboard

SimulatePhysics

Sequential Game Loop:

Page 24: Concurrent Programming With Revisions and Isolation Types

Parallelizing the Game Loop - design

• Declared isolation types: • VersionedValue<T> - mainly simple types • VersionedObject<T> - asteroids, positions,

particle effects • CumulativeValue<T> - message buffer • CumulativeList<T> - lists of asteroids

• CollisionsCheck could be executed in parallel. Optimizing

• RenderFrameToScreen cannot be parallelized • but it can be executed in parallel with other tasks

• Updates from the network have higher priority than updates done • by UpdateWorld or CollisionsCheck

• Deterministic Record and Replay • Used in performance evaluation

Page 25: Concurrent Programming With Revisions and Isolation Types

Parallelizing the Game Loop

Shared State

Parallel Collision DetectionParallel Collision Detection

Parallel Collision Detection

Graphics Card

Network Connection

Play Sounds

Render Screen

Process Inputs

Autosave

Send

Receive

Disk

Keyboard

SimulatePhysics

Page 26: Concurrent Programming With Revisions and Isolation Types

Parallelizing the Game Loop

Coll.

Det

. 1 Co

ll. D

et.

2 Coll.

Det

. 3 Co

ll. D

et.

4 Rend

er

Phys

ics

netw

ork

auto

save

(lo

ng

runn

ing)

Page 27: Concurrent Programming With Revisions and Isolation Types

Parallelizing the Game Loop - explained

Coll.

Det

. 1 Co

ll. D

et.

2 Coll.

Det

. 3 Co

ll. D

et.

4 Rend

er

Phys

ics

netw

ork

auto

save

(lo

ng

runn

ing)

• The Physics revision updates objects location while Render revision reads locations, minor changes don’t affect most computations

Page 28: Concurrent Programming With Revisions and Isolation Types

Parallelizing the Game Loop - explained

Coll.

Det

. 1 Co

ll. D

et.

2 Coll.

Det

. 3 Co

ll. D

et.

4 Rend

er

Phys

ics

netw

ork

auto

save

(lo

ng

runn

ing)

Physics task updates position of all game objects

Network task updates position of some objects

Network updates have priority over physics updates

Order of joins establishes precedence!

Page 29: Concurrent Programming With Revisions and Isolation Types

Performance Evaluation

Testing environment:Intel Xeon W3520 (quad-core) 2.66Ghz, 6GB of DDR3,

NVIDIA Quadro FX580 512MB, Windows 7 Enterprise 64-bit

Page 30: Concurrent Programming With Revisions and Isolation Types

Performance Evaluation

• Autosave now totally undetected and unnoticeable • Overall speedup x3.03 than sequential run

Almost entirely depends on graphics card

Page 31: Concurrent Programming With Revisions and Isolation Types

Performance Evaluation - Overhead

How much did all the copying and indirection cost?

Collision detection accounts for 82% of frame runtime

Page 32: Concurrent Programming With Revisions and Isolation Types

Performance Evaluation - Overhead

If revision writes to a versioned object then revisioning subsystem needs to clone object to enforce isolation.

Page 33: Concurrent Programming With Revisions and Isolation Types

Performance Evaluation - Speed• Average speedup of 2.6x on quad-core processor• Up to 3.03x speedup for 1500 asteroids• Render task takes 95.5% of the frame time

(collisions check speedup)

Page 34: Concurrent Programming With Revisions and Isolation Types

Implementation

Page 35: Concurrent Programming With Revisions and Isolation Types

Revisions - Implementation

o C# Library

o Revisiono Segmento Versionedo Cumulative

Page 36: Concurrent Programming With Revisions and Isolation Types

Revisions - ImplementationRevisions Stores current segment that

points to the segment created for that revision after last fork

Root segment is the segment right above fork

Segments Tree structure Stores versioned data Ancestors of the current segment

can be removed after join if there is no other revisions that uses them.

Page 37: Concurrent Programming With Revisions and Isolation Types

Revisions - Implementation

Page 38: Concurrent Programming With Revisions and Isolation Types

Revisions - ImplementationFork

Creates new current segments for both revisions

Assigns new revision with the new thread

Join Creates one new segment Merges versioned objects

from both revisions Releases unused ancestors

of the current segment of the joined revision

Page 39: Concurrent Programming With Revisions and Isolation Types

Summary Programming model based on revisions and isolation

types. Efficient mechanism for executing different tasks

within interactive applications. Allows programming deterministic concurrent

programs Depend on programmer to declare proper use of data

Page 40: Concurrent Programming With Revisions and Isolation Types

Questions?

Page 41: Concurrent Programming With Revisions and Isolation Types

Thank you