Slide 1

Slide 1 text

Reactive Async: Expressive Deterministic Concurrency Philipp Haller1, Simon Geries1,
 Michael Eichberg2, Guido Salvaneschi2 1 KTH Royal Institute of Technology, Sweden 2 TU Darmstadt, Germany

Slide 2

Slide 2 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Have we solved concurrent programming, yet? 2

Slide 3

Slide 3 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Have we solved concurrent programming, yet? The problem with concurrency: 2

Slide 4

Slide 4 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Have we solved concurrent programming, yet? The problem with concurrency: – It’s difficult! 2

Slide 5

Slide 5 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Have we solved concurrent programming, yet? The problem with concurrency: – It’s difficult! – Multiple hazards: 2

Slide 6

Slide 6 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Have we solved concurrent programming, yet? The problem with concurrency: – It’s difficult! – Multiple hazards: • Race conditions 2

Slide 7

Slide 7 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Have we solved concurrent programming, yet? The problem with concurrency: – It’s difficult! – Multiple hazards: • Race conditions • Deadlocks 2

Slide 8

Slide 8 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Have we solved concurrent programming, yet? The problem with concurrency: – It’s difficult! – Multiple hazards: • Race conditions • Deadlocks • Livelocks 2

Slide 9

Slide 9 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Have we solved concurrent programming, yet? The problem with concurrency: – It’s difficult! – Multiple hazards: • Race conditions • Deadlocks • Livelocks • Violation of fairness 2

Slide 10

Slide 10 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Non-Determinism 3

Slide 11

Slide 11 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Non-Determinism • At the root of several hazards 3

Slide 12

Slide 12 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Non-Determinism • At the root of several hazards • Example 1: 3 @volatile var x = 0 def m(): Unit = { Future { x = 1 } Future { x = 2 } .. // does not access x }

Slide 13

Slide 13 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Non-Determinism • At the root of several hazards • Example 1: 3 @volatile var x = 0 def m(): Unit = { Future { x = 1 } Future { x = 2 } .. // does not access x } What’s the value of x when an invocation of m returns?

Slide 14

Slide 14 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reordering not always a problem! • Example 2: 4

Slide 15

Slide 15 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reordering not always a problem! • Example 2: 4 import scala.collection.concurrent.TrieMap val set = new TrieMap[Int, Int] Future { set.put(1, 0) } set.put(2, 0)

Slide 16

Slide 16 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reordering not always a problem! • Example 2: 4 import scala.collection.concurrent.TrieMap val set = new TrieMap[Int, Int] Future { set.put(1, 0) } set.put(2, 0) Eventually, set contains both 1 and 2, always

Slide 17

Slide 17 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reordering not always a problem! • Example 2: 4 import scala.collection.concurrent.TrieMap val set = new TrieMap[Int, Int] Future { set.put(1, 0) } set.put(2, 0) Eventually, set contains both 1 and 2, always Bottom line: it depends on the datatype

Slide 18

Slide 18 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller … and its operations! • Example 3: 5

Slide 19

Slide 19 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller … and its operations! • Example 3: 5 val set = new TrieMap[Int, Int] Future { set.put(1, 0) } Future { if (set.contains(1)) { .. } } set.put(2, 0)

Slide 20

Slide 20 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller … and its operations! • Example 3: 5 val set = new TrieMap[Int, Int] Future { set.put(1, 0) } Future { if (set.contains(1)) { .. } } set.put(2, 0) Result depends on schedule!

Slide 21

Slide 21 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Important Questions 6

Slide 22

Slide 22 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Important Questions Q1:
 How do we know we have written a deterministic concurrent program? 6

Slide 23

Slide 23 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Important Questions Q1:
 How do we know we have written a deterministic concurrent program? – What about Heisenbugs? 6

Slide 24

Slide 24 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Important Questions Q1:
 How do we know we have written a deterministic concurrent program? – What about Heisenbugs? • No race in 1’000’000 runs, race in run 1’000’001 6

Slide 25

Slide 25 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Important Questions Q1:
 How do we know we have written a deterministic concurrent program? – What about Heisenbugs? • No race in 1’000’000 runs, race in run 1’000’001 6 Goal: simple criteria that guarantee determinism

Slide 26

Slide 26 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Important Questions 7

Slide 27

Slide 27 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Important Questions Q2:
 How do we ensure expressivity while providing determinism? 7

Slide 28

Slide 28 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Important Questions Q2:
 How do we ensure expressivity while providing determinism? – Draconian restrictions undesired! 7

Slide 29

Slide 29 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Important Questions Q2:
 How do we ensure expressivity while providing determinism? – Draconian restrictions undesired! 7 Goal: reconcile determinism and expressivity

Slide 30

Slide 30 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Approach 8

Slide 31

Slide 31 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Approach • Extend a future-style programming model with: 8

Slide 32

Slide 32 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Approach • Extend a future-style programming model with: – Lattice-based datatypes 8

Slide 33

Slide 33 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Approach • Extend a future-style programming model with: – Lattice-based datatypes – Quiescence 8

Slide 34

Slide 34 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Approach • Extend a future-style programming model with: – Lattice-based datatypes – Quiescence 8 Crucial for determinism!

Slide 35

Slide 35 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Approach • Extend a future-style programming model with: – Lattice-based datatypes – Quiescence – Resolution of cyclic dependencies 8 Crucial for determinism!

Slide 36

Slide 36 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Approach • Extend a future-style programming model with: – Lattice-based datatypes – Quiescence – Resolution of cyclic dependencies 8 Crucial for determinism! Increases expressivity!

Slide 37

Slide 37 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Approach • Extend a future-style programming model with: – Lattice-based datatypes – Quiescence – Resolution of cyclic dependencies • Evaluation of expressivity and performance – Case study: static analysis of JVM bytecode 8 Crucial for determinism! Increases expressivity!

Slide 38

Slide 38 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Programming Model 9

Slide 39

Slide 39 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Programming Model Programming model based on two core abstractions:
 cells and cell completers 9

Slide 40

Slide 40 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Programming Model Programming model based on two core abstractions:
 cells and cell completers – Cell = shared “variable” 9

Slide 41

Slide 41 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Programming Model Programming model based on two core abstractions:
 cells and cell completers – Cell = shared “variable” 9 Concurrently read and written

Slide 42

Slide 42 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Programming Model Programming model based on two core abstractions:
 cells and cell completers – Cell = shared “variable” – Cell[K,V]: read-only interface; read values of type V (akin to Future[V]) 9 Concurrently read and written

Slide 43

Slide 43 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Programming Model Programming model based on two core abstractions:
 cells and cell completers – Cell = shared “variable” – Cell[K,V]: read-only interface; read values of type V (akin to Future[V]) – CellCompleter[K,V] : write values of type V to its associated cell (akin to Promise[V]) 9 Concurrently read and written

Slide 44

Slide 44 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Programming Model Programming model based on two core abstractions:
 cells and cell completers – Cell = shared “variable” – Cell[K,V]: read-only interface; read values of type V (akin to Future[V]) – CellCompleter[K,V] : write values of type V to its associated cell (akin to Promise[V]) – V must have an instance of a lattice type class 9 Concurrently read and written

Slide 45

Slide 45 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Programming Model Programming model based on two core abstractions:
 cells and cell completers – Cell = shared “variable” – Cell[K,V]: read-only interface; read values of type V (akin to Future[V]) – CellCompleter[K,V] : write values of type V to its associated cell (akin to Promise[V]) – V must have an instance of a lattice type class 9 Monotonic updates Concurrently read and written

Slide 46

Slide 46 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Example 10

Slide 47

Slide 47 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Example • Given a social graph 10

Slide 48

Slide 48 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Example • Given a social graph – vertex = user 10

Slide 49

Slide 49 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Example • Given a social graph – vertex = user • Traverse graph and collect IDs of “interesting” users 10

Slide 50

Slide 50 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Example • Given a social graph – vertex = user • Traverse graph and collect IDs of “interesting” users • Graph large => concurrent traversal 10

Slide 51

Slide 51 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Solution 11

Slide 52

Slide 52 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Solution • Collect IDs of interesting users in a cell 11

Slide 53

Slide 53 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Solution • Collect IDs of interesting users in a cell • Cell contains set of integers 11

Slide 54

Slide 54 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Solution • Collect IDs of interesting users in a cell • Cell contains set of integers 11 OK: subsets of the set of all integers form a lattice

Slide 55

Slide 55 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Cell with User IDs (code simplified) 12

Slide 56

Slide 56 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Cell with User IDs (code simplified) 12 val userIDs = CellCompleter[Set[Int]]

Slide 57

Slide 57 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Cell with User IDs (code simplified) 12 implicit object IntSetLattice extends Lattice[Set[Int]] { val empty = Set() def join(left: Set[Int], right: Set[Int]) = left ++ right } val userIDs = CellCompleter[Set[Int]]

Slide 58

Slide 58 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Cell with User IDs (code simplified) 12 implicit object IntSetLattice extends Lattice[Set[Int]] { val empty = Set() def join(left: Set[Int], right: Set[Int]) = left ++ right } val userIDs = CellCompleter[Set[Int]] Bounded
 join-semilattice

Slide 59

Slide 59 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Cell with User IDs (code simplified) 12 implicit object IntSetLattice extends Lattice[Set[Int]] { val empty = Set() def join(left: Set[Int], right: Set[Int]) = left ++ right } // add a user ID userIDs.putNext(Set(theUserID)) val userIDs = CellCompleter[Set[Int]] Bounded
 join-semilattice

Slide 60

Slide 60 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reading Results 13

Slide 61

Slide 61 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reading Results • Problem: when reading a cell’s value, how do we know this value is not going to change any more? 13

Slide 62

Slide 62 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reading Results • Problem: when reading a cell’s value, how do we know this value is not going to change any more? – There may still be ongoing concurrent activities 13

Slide 63

Slide 63 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reading Results • Problem: when reading a cell’s value, how do we know this value is not going to change any more? – There may still be ongoing concurrent activities – Manual synchronization (e.g., latches) error-prone 13

Slide 64

Slide 64 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reading Results • Problem: when reading a cell’s value, how do we know this value is not going to change any more? – There may still be ongoing concurrent activities – Manual synchronization (e.g., latches) error-prone • Solution: 13

Slide 65

Slide 65 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reading Results • Problem: when reading a cell’s value, how do we know this value is not going to change any more? – There may still be ongoing concurrent activities – Manual synchronization (e.g., latches) error-prone • Solution: 13 Koyaanisqatsi

Slide 66

Slide 66 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reading Results • Problem: when reading a cell’s value, how do we know this value is not going to change any more? – There may still be ongoing concurrent activities – Manual synchronization (e.g., latches) error-prone • Solution: 13 Koyaanisqatsi

Slide 67

Slide 67 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reading Results • Problem: when reading a cell’s value, how do we know this value is not going to change any more? – There may still be ongoing concurrent activities – Manual synchronization (e.g., latches) error-prone • Solution: 13 Quiescence

Slide 68

Slide 68 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Quiescence 14

Slide 69

Slide 69 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Quiescence • Intuitively: situation when values of cells are guaranteed not to change any more 14

Slide 70

Slide 70 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Quiescence • Intuitively: situation when values of cells are guaranteed not to change any more • Technically: 14

Slide 71

Slide 71 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Quiescence • Intuitively: situation when values of cells are guaranteed not to change any more • Technically: – No concurrent activities ongoing or scheduled which could change values of cells 14

Slide 72

Slide 72 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Quiescence • Intuitively: situation when values of cells are guaranteed not to change any more • Technically: – No concurrent activities ongoing or scheduled which could change values of cells – Detected by the underlying thread pool 14

Slide 73

Slide 73 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Revisiting the Example 15

Slide 74

Slide 74 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Revisiting the Example 15 val pool = new HandlerPool val userIDs = CellCompleter[Set[Int]](pool)

Slide 75

Slide 75 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Revisiting the Example 15 // add a user ID userIDs.putNext(Set(theUserID)) .. val pool = new HandlerPool val userIDs = CellCompleter[Set[Int]](pool)

Slide 76

Slide 76 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Revisiting the Example 15 // add a user ID userIDs.putNext(Set(theUserID)) .. val pool = new HandlerPool val userIDs = CellCompleter[Set[Int]](pool) // register handler // upon quiescence: read result value of cell pool.onQuiescent(userIDs.cell) { collectedIDs => .. }

Slide 77

Slide 77 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Revisiting the Example 15 // add a user ID userIDs.putNext(Set(theUserID)) .. val pool = new HandlerPool val userIDs = CellCompleter[Set[Int]](pool) // register handler // upon quiescence: read result value of cell pool.onQuiescent(userIDs.cell) { collectedIDs => .. } Safe to read from cell when pool quiescent!

Slide 78

Slide 78 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Handler Pools 16

Slide 79

Slide 79 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Handler Pools Execution context with extensions: 16

Slide 80

Slide 80 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Handler Pools Execution context with extensions: – Event-driven quiescence API 16

Slide 81

Slide 81 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Handler Pools Execution context with extensions: – Event-driven quiescence API – Resolution of dependencies between cells 16

Slide 82

Slide 82 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Handler Pools Execution context with extensions: – Event-driven quiescence API – Resolution of dependencies between cells 16 Dependency resolution?

Slide 83

Slide 83 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Expressing Concurrent Dataflow 17

Slide 84

Slide 84 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Expressing Concurrent Dataflow • Cells provide non-blocking interface 17

Slide 85

Slide 85 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Expressing Concurrent Dataflow • Cells provide non-blocking interface – Low level: callbacks 17

Slide 86

Slide 86 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Expressing Concurrent Dataflow • Cells provide non-blocking interface – Low level: callbacks – High level: combinators 17

Slide 87

Slide 87 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Expressing Concurrent Dataflow • Cells provide non-blocking interface – Low level: callbacks – High level: combinators 17 Like futures

Slide 88

Slide 88 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Expressing Concurrent Dataflow • Cells provide non-blocking interface – Low level: callbacks – High level: combinators • Important purpose: express concurrent dataflow 17 Like futures

Slide 89

Slide 89 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Expressing Concurrent Dataflow • Cells provide non-blocking interface – Low level: callbacks – High level: combinators • Important purpose: express concurrent dataflow 17 Like futures fut.map(fun).filter(pred)

Slide 90

Slide 90 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Expressing Concurrent Dataflow • Cells provide non-blocking interface – Low level: callbacks – High level: combinators • Important purpose: express concurrent dataflow 17 Like futures fut.map(fun).filter(pred) Futures

Slide 91

Slide 91 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Expressing Concurrent Dataflow • Cells provide non-blocking interface – Low level: callbacks – High level: combinators • Important purpose: express concurrent dataflow 17 Like futures fut fun fut’ pred fut’’ fut.map(fun).filter(pred) Futures

Slide 92

Slide 92 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Expressing Concurrent Dataflow • Cells provide non-blocking interface – Low level: callbacks – High level: combinators • Important purpose: express concurrent dataflow • Problem: 17 Like futures fut fun fut’ pred fut’’ fut.map(fun).filter(pred) Futures

Slide 93

Slide 93 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Expressing Concurrent Dataflow • Cells provide non-blocking interface – Low level: callbacks – High level: combinators • Important purpose: express concurrent dataflow • Problem: 17 What if the dataflow graph is cyclic? Like futures fut fun fut’ pred fut’’ fut.map(fun).filter(pred) Futures

Slide 94

Slide 94 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Dataflow Graphs 18

Slide 95

Slide 95 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Dataflow Graphs Example: • Static analysis of JVM bytecode 18

Slide 96

Slide 96 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Dataflow Graphs Example: • Static analysis of JVM bytecode • Task:
 Determine purity of methods 18

Slide 97

Slide 97 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Dataflow Graphs Example: • Static analysis of JVM bytecode • Task:
 Determine purity of methods • Rules: 18

Slide 98

Slide 98 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Dataflow Graphs Example: • Static analysis of JVM bytecode • Task:
 Determine purity of methods • Rules: – A method is impure if it accesses a non-final field 18

Slide 99

Slide 99 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Dataflow Graphs Example: • Static analysis of JVM bytecode • Task:
 Determine purity of methods • Rules: – A method is impure if it accesses a non-final field – A method is impure if it calls an impure method 18

Slide 100

Slide 100 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Dataflow Graphs Example: • Static analysis of JVM bytecode • Task:
 Determine purity of methods • Rules: – A method is impure if it accesses a non-final field – A method is impure if it calls an impure method – … 18

Slide 101

Slide 101 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Dataflow Graphs Example: • Static analysis of JVM bytecode • Task:
 Determine purity of methods • Rules: – A method is impure if it accesses a non-final field – A method is impure if it calls an impure method – … 18 A

Slide 102

Slide 102 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Dataflow Graphs Example: • Static analysis of JVM bytecode • Task:
 Determine purity of methods • Rules: – A method is impure if it accesses a non-final field – A method is impure if it calls an impure method – … 18 A B

Slide 103

Slide 103 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Dataflow Graphs Example: • Static analysis of JVM bytecode • Task:
 Determine purity of methods • Rules: – A method is impure if it accesses a non-final field – A method is impure if it calls an impure method – … 18 A B “calls”

Slide 104

Slide 104 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Dataflow Graphs Example: • Static analysis of JVM bytecode • Task:
 Determine purity of methods • Rules: – A method is impure if it accesses a non-final field – A method is impure if it calls an impure method – … 18 A B C “calls”

Slide 105

Slide 105 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Dataflow Graphs Example: • Static analysis of JVM bytecode • Task:
 Determine purity of methods • Rules: – A method is impure if it accesses a non-final field – A method is impure if it calls an impure method – … 18 A B C “calls”

Slide 106

Slide 106 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Cycle Resolution 19

Slide 107

Slide 107 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Cycle Resolution • What if upon quiescence cells are empty and there is a dependency cycle? 19

Slide 108

Slide 108 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Cycle Resolution • What if upon quiescence cells are empty and there is a dependency cycle? 19 A B C

Slide 109

Slide 109 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Cycle Resolution • What if upon quiescence cells are empty and there is a dependency cycle? • Idea:
 Pluggable resolution policies 19 A B C

Slide 110

Slide 110 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Cycle Resolution • What if upon quiescence cells are empty and there is a dependency cycle? • Idea:
 Pluggable resolution policies • Example:
 Purity analysis should resolve all cells
 in cycle to “pure”, since could not show impurity 19 A B C

Slide 111

Slide 111 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Specifying Resolution Policies 20

Slide 112

Slide 112 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Specifying Resolution Policies • Role of the first type parameter of Cell[K,V] 20

Slide 113

Slide 113 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Specifying Resolution Policies • Role of the first type parameter of Cell[K,V] • Example: 20

Slide 114

Slide 114 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Specifying Resolution Policies • Role of the first type parameter of Cell[K,V] • Example: 20 object PurityKey extends Key[Purity] { def resolve[K <: Key[Purity]](cells: Seq[Cell[K, Purity]]) = cells.map(cell => (cell, Pure)) .. }

Slide 115

Slide 115 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Specifying Resolution Policies • Role of the first type parameter of Cell[K,V] • Example: 20 object PurityKey extends Key[Purity] { def resolve[K <: Key[Purity]](cells: Seq[Cell[K, Purity]]) = cells.map(cell => (cell, Pure)) .. } resolve all cells to Pure

Slide 116

Slide 116 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Specifying Resolution Policies • Role of the first type parameter of Cell[K,V] • Example: 20 object PurityKey extends Key[Purity] { def resolve[K <: Key[Purity]](cells: Seq[Cell[K, Purity]]) = cells.map(cell => (cell, Pure)) .. } closed strongly- connected component

Slide 117

Slide 117 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Purity Analysis: Set-up 21

Slide 118

Slide 118 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Purity Analysis: Set-up 21 for { classFile <- project.allProjectClassFiles method <- classFile.methods } { val methodCompleter = CellCompleter(pool, PurityKey) pool.execute { analyze(project, methodCompleter, classFile, method) } } val analysisDoneFuture = pool.quiescentResolveCells()

Slide 119

Slide 119 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Evaluation 22

Slide 120

Slide 120 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Evaluation • Static analysis of JVM bytecode using the OPAL framework (OPen extensible Analysis Library) 22

Slide 121

Slide 121 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Evaluation • Static analysis of JVM bytecode using the OPAL framework (OPen extensible Analysis Library) – New Scala-based, extensible bytecode toolkit 22

Slide 122

Slide 122 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Evaluation • Static analysis of JVM bytecode using the OPAL framework (OPen extensible Analysis Library) – New Scala-based, extensible bytecode toolkit – Fully concurrent 22

Slide 123

Slide 123 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Evaluation • Static analysis of JVM bytecode using the OPAL framework (OPen extensible Analysis Library) – New Scala-based, extensible bytecode toolkit – Fully concurrent 22 http://www.opal-project.de

Slide 124

Slide 124 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Evaluation • Static analysis of JVM bytecode using the OPAL framework (OPen extensible Analysis Library) – New Scala-based, extensible bytecode toolkit – Fully concurrent • Rewrote purity analysis and immutability analysis 22 http://www.opal-project.de

Slide 125

Slide 125 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Evaluation • Static analysis of JVM bytecode using the OPAL framework (OPen extensible Analysis Library) – New Scala-based, extensible bytecode toolkit – Fully concurrent • Rewrote purity analysis and immutability analysis • Ran analysis on JDK 8 update 45 (rt.jar) 22 http://www.opal-project.de

Slide 126

Slide 126 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Evaluation • Static analysis of JVM bytecode using the OPAL framework (OPen extensible Analysis Library) – New Scala-based, extensible bytecode toolkit – Fully concurrent • Rewrote purity analysis and immutability analysis • Ran analysis on JDK 8 update 45 (rt.jar) – 18’591 class files, 163’268 methods, 77’128 fields 22 http://www.opal-project.de

Slide 127

Slide 127 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Results: Immutability Analysis • RA about 10x faster than FPCF • RA = 294 LOC, FPCF = 424 LOC (1.44x) 23 FPCF (secs.) 1.0 1.5 2.0 2.5 Reactive-Async (secs.) 0.1 0.2 0.3 1 Thread 2 Threads 4 Threads 8 Threads 16 Threads 2.15 2.20 2.25 2.30 2.35 1.15 1.20 1.25 1.30 1.35 0.290 0.295 0.300 0.105 0.110 0.115

Slide 128

Slide 128 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Results: Immutability Analysis • RA about 10x faster than FPCF • RA = 294 LOC, FPCF = 424 LOC (1.44x) 23 FPCF (secs.) 1.0 1.5 2.0 2.5 Reactive-Async (secs.) 0.1 0.2 0.3 1 Thread 2 Threads 4 Threads 8 Threads 16 Threads 2.15 2.20 2.25 2.30 2.35 1.15 1.20 1.25 1.30 1.35 0.290 0.295 0.300 0.105 0.110 0.115 box plot: whiskers = min/max
 top/bottom of box = 
 1st and 3rd quartile band in box: median

Slide 129

Slide 129 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Results: Immutability Analysis • RA about 10x faster than FPCF • RA = 294 LOC, FPCF = 424 LOC (1.44x) 23 FPCF (secs.) 1.0 1.5 2.0 2.5 Reactive-Async (secs.) 0.1 0.2 0.3 1 Thread 2 Threads 4 Threads 8 Threads 16 Threads 2.15 2.20 2.25 2.30 2.35 1.15 1.20 1.25 1.30 1.35 0.290 0.295 0.300 0.105 0.110 0.115 box plot: whiskers = min/max
 top/bottom of box = 
 1st and 3rd quartile band in box: median FPCF = OPAL’s fixed point computation framework

Slide 130

Slide 130 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Results: Purity Analysis • Best configs. (FPCF: 4 thr, RA: 16 thr): RA 1.75x faster • RA = 113 LOC, FPCF = 166 LOC (1.47x) 24 FPCF (secs.) 0.15 0.20 0.25 0.30 0.35 Reactive-Async (secs.) 0.1 0.2 0.3 0.4 0.5 1 Thread 2 Threads 4 Threads 8 Threads 16 Threads 0.43 0.44 0.45 0.09 0.10 0.11 0.335 0.340 0.345 0.165 0.170 0.175 0.180 0.185 0.18 0.19 0.20

Slide 131

Slide 131 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Benchmarks: Monte Carlo Simulation • Compute Net Present Value • 14-16 threads: Scala futures 23-36% faster than RA 25 Sequential Reactive Async Scala Futures 2.11.7 Runtime (ms) 0 1000 2000 3000 4000 5000 6000 Number of Threads 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 400 500 600 700 14 15 16

Slide 132

Slide 132 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Benchmarks: Parallel Sum • Parallel sum of large collection of random ints • Performance competitive with Scala’s futures 26 Sequential Reactive Async Scala Futures 2.11.7 Runtime (ms) 0 50 100 150 200 250 300 Number of Threads 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Slide 133

Slide 133 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Related Work • Deterministic-by-construction programming models – KPNs, concurrent revisions, FlowPools, LVars, etc. • Static vs. dynamic enforcement of determinism • Reactive programming models – Dynamic dependencies, determinism • See paper for discussion 27

Slide 134

Slide 134 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reactive Async: Conclusion • New concurrent programming model – Lattices and quiescence for determinism – Resolution of cyclic dependencies • Promising experimental results • Future work: – Optimization – Determinism as a statically-checked effect 28

Slide 135

Slide 135 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reactive Async: Conclusion • New concurrent programming model – Lattices and quiescence for determinism – Resolution of cyclic dependencies • Promising experimental results • Future work: – Optimization – Determinism as a statically-checked effect 28 https://github.com/phaller/reactive-async

Slide 136

Slide 136 text

Reactive Async: Expressive Deterministic Concurrency — Philipp Haller Reactive Async: Conclusion • New concurrent programming model – Lattices and quiescence for determinism – Resolution of cyclic dependencies • Promising experimental results • Future work: – Optimization – Determinism as a statically-checked effect 28 https://github.com/phaller/reactive-async Thank you!