concurrent programming with revisions and isolation types
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 PresentationTRANSCRIPT
Concurrent Programming With Revisions and Isolation Types
Presented by: Ran Breuer
Sebastian BurckhardtMicrosoft Research
Alexandro BaldassinUniversity of Campinas, Brazil
Daan LeijenMicrosoft Research
Outline Introduction
Main Ideas and Assumptions Revisions and Isolation Types Comparison to the classic locking scheme Case Study – Space Ward 3D Performance Evaluation Implemetation
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?
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;
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
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”
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
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
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);
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()
Revision Diagrams – Original look
Concurrent Revisions Revision Diagram
Fork()
Join()
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
Nested Revisions - restrictions
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
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
Types of Isolation (Types) - Versioned
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>
Types of Isolation (Types) - Cumulative
Complex structures with isolation types
Isolation typed fields might not preserve objects behavior…
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
Comparison to current methods – Transactions
Case StudySpace Wars 3DGame designed to teach DirectX Programming in C#
Drag picture to placeholder or click icon to add
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:
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
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
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)
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
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!
Performance Evaluation
Testing environment:Intel Xeon W3520 (quad-core) 2.66Ghz, 6GB of DDR3,
NVIDIA Quadro FX580 512MB, Windows 7 Enterprise 64-bit
Performance Evaluation
• Autosave now totally undetected and unnoticeable • Overall speedup x3.03 than sequential run
Almost entirely depends on graphics card
Performance Evaluation - Overhead
How much did all the copying and indirection cost?
Collision detection accounts for 82% of frame runtime
Performance Evaluation - Overhead
If revision writes to a versioned object then revisioning subsystem needs to clone object to enforce isolation.
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)
Implementation
Revisions - Implementation
o C# Library
o Revisiono Segmento Versionedo Cumulative
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.
Revisions - Implementation
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
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
Questions?
Thank you