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
![Page 1: Concurrent Programming With Revisions and Isolation Types](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/1.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/2.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/3.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/4.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/5.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/6.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/7.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/8.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/9.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/10.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/11.jpg)
Revision Diagrams – Original look
Concurrent Revisions Revision Diagram
Fork()
Join()
![Page 12: Concurrent Programming With Revisions and Isolation Types](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/12.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/13.jpg)
Nested Revisions - restrictions
![Page 14: Concurrent Programming With Revisions and Isolation Types](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/14.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/15.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/16.jpg)
Types of Isolation (Types) - Versioned
![Page 17: Concurrent Programming With Revisions and Isolation Types](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/17.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/18.jpg)
Types of Isolation (Types) - Cumulative
![Page 19: Concurrent Programming With Revisions and Isolation Types](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/19.jpg)
Complex structures with isolation types
Isolation typed fields might not preserve objects behavior…
![Page 20: Concurrent Programming With Revisions and Isolation Types](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/20.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/21.jpg)
Comparison to current methods – Transactions
![Page 22: Concurrent Programming With Revisions and Isolation Types](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/22.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/23.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/24.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/25.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/26.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/27.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/28.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/29.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/30.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/31.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/32.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/33.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/34.jpg)
Implementation
![Page 35: Concurrent Programming With Revisions and Isolation Types](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/35.jpg)
Revisions - Implementation
o C# Library
o Revisiono Segmento Versionedo Cumulative
![Page 36: Concurrent Programming With Revisions and Isolation Types](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/36.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/37.jpg)
Revisions - Implementation
![Page 38: Concurrent Programming With Revisions and Isolation Types](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/38.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/39.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/40.jpg)
Questions?
![Page 41: Concurrent Programming With Revisions and Isolation Types](https://reader035.vdocuments.mx/reader035/viewer/2022062410/568164d9550346895dd725d8/html5/thumbnails/41.jpg)
Thank you