Concurrency: The Good, The Bad and The Ugly

26,487 views

Published on

Scala Days 2013, New York

Published in: Technology

Concurrency: The Good, The Bad and The Ugly

  1. Concurrencythe Good, the Bad and the UglyDr. Roland KuhnAkka Tech LeadLgd. Viktor KlangDirector of Engineering
  2. Concurrencywat?
  3. Characteristics
  4. CompartmentalizationCharacteristics
  5. CompartmentalizationCoordinationCharacteristics
  6. CompartmentalizationCoordinationExecutionCharacteristics
  7. CompartmentalizationExecutionCoordinationCharacteristics
  8. Characteristics
  9. CharacteristicsGoodUglyBad
  10. CharacteristicsGoodUglyBad ☓
  11. Threads… and locks
  12. The Good
  13. The Good✓Can be mapped onto CPUs
  14. The Good✓Can be mapped onto CPUs✓"To the metal" — no overhead
  15. The Good✓Can be mapped onto CPUs✓"To the metal" — no overhead✓High degree of control
  16. The Good✓Can be mapped onto CPUs✓"To the metal" — no overhead✓High degree of control✓Debugging
  17. The Bad
  18. The Bad☣Heavyweight
  19. The Bad☣Heavyweight☣Scarce
  20. The Bad☣Heavyweight☣Scarce☣Diminishing returns
  21. The Bad☣Heavyweight☣Scarce☣Diminishing returns☣High wake-up latency
  22. The Bad☣Heavyweight☣Scarce☣Diminishing returns☣High wake-up latency☣Barebones / low-level
  23. The Bad☣Heavyweight☣Scarce☣Diminishing returns☣High wake-up latency☣Barebones / low-level☣No means of recovery
  24. The Ugly
  25. The UglyIs it threadsafe?
  26. The UglyIs it threadsafe?— Too coarse locks?
  27. The UglyIs it threadsafe?— Too coarse locks?— The right locks?
  28. The UglyIs it threadsafe?— Too coarse locks?— The right locks?— The right locking order?
  29. The UglyIs it threadsafe?— Too coarse locks?— The right locks?— The right locking order?Defensive error handling
  30. The UglyIs it threadsafe?— Too coarse locks?— The right locks?— The right locking order?Defensive error handlingDo you understand JSR133?
  31. CompartmentalizationExecutionCoordinationConclusion
  32. CompartmentalizationExecutionCoordinationConclusionThread + Locks
  33. EventLoop… or Executor
  34. The Good
  35. The Good✓Configurable execution
  36. The Good✓Configurable execution✓M:N task to thread ratio
  37. The Good✓Configurable execution✓M:N task to thread ratio✓Less JMM headache
  38. The Bad
  39. The Bad☣How to handle errors?
  40. The Bad☣How to handle errors?☣Dealing with blocking code
  41. The Bad☣How to handle errors?☣Dealing with blocking code☣Closing over mutable state
  42. The Ugly
  43. The UglyCallback Hell
  44. The UglyCallback HellComposing results
  45. The UglyCallback HellComposing resultsLow reusability
  46. The UglyCallback HellComposing resultsLow reusabilityIs it sync or async?
  47. The UglyCallback HellComposing resultsLow reusabilityIs it sync or async?Debugging
  48. CompartmentalizationExecutionCoordinationConclusion
  49. CompartmentalizationExecutionCoordinationConclusionExecutor
  50. STMSoftware Transactional Memory
  51. The Good
  52. The Good✓Typesafe & non-blocking
  53. The Good✓Typesafe & non-blocking✓Transactional
  54. The Good✓Typesafe & non-blocking✓Transactional✓Composable
  55. The Bad
  56. The Bad☣Size to failure ratio
  57. The Bad☣Size to failure ratio☣Retries are costly
  58. The Ugly
  59. The UglyDealing with side-effects
  60. The UglyDealing with side-effectsDealing with failure
  61. The UglyDealing with side-effectsDealing with failureUnpredictable performance
  62. The UglyDealing with side-effectsDealing with failureUnpredictable performanceDebugging
  63. CompartmentalizationExecutionCoordinationConclusion
  64. CompartmentalizationExecutionCoordinationSTMConclusion
  65. Java Future… and ExecutorService
  66. The Good
  67. The Good✓Configurable execution
  68. The Good✓Configurable execution✓Typesafe
  69. The Bad
  70. The Bad☣Blocking composition
  71. The Bad☣Blocking composition☣Guesstimation of deadlock
  72. The Bad☣Blocking composition☣Guesstimation of deadlock☣Futures are one-off
  73. The Ugly
  74. The UglyCancel others Futures?
  75. The UglyCancel others Futures?Non-blocking requires polling
  76. The UglyCancel others Futures?Non-blocking requires pollingDealing with failure
  77. CompartmentalizationExecutionCoordinationConclusion
  78. CompartmentalizationExecutionCoordinationJava FutureConclusion
  79. Scala Future… with ExecutionContext
  80. The Good
  81. The Good✓Typesafe
  82. The Good✓Typesafe✓Non-blocking composition
  83. The Good✓Typesafe✓Non-blocking composition✓Monadic
  84. The Good✓Typesafe✓Non-blocking composition✓Monadic✓Freely sharable
  85. The Good✓Typesafe✓Non-blocking composition✓Monadic✓Freely sharable✓Can recover from failure
  86. The Bad
  87. The Bad☣Defers failures to downstream
  88. The Bad☣Defers failures to downstream☣Closing over mutable state
  89. The Bad☣Defers failures to downstream☣Closing over mutable state☣No ordering of callbacks
  90. The Bad☣Defers failures to downstream☣Closing over mutable state☣No ordering of callbacks☣Futures are one-off
  91. The Ugly
  92. The UglyCallback Hell (use for instead)
  93. The UglyCallback Hell (use for instead)Debugging
  94. CompartmentalizationExecutionCoordinationConclusion
  95. CompartmentalizationExecutionCoordinationConclusionScala Future
  96. Akka Dataflow
  97. The Good
  98. The Good✓Typesafe
  99. The Good✓Typesafe✓Non-blocking composition
  100. The Good✓Typesafe✓Non-blocking composition✓Declarative using direct style
  101. The Good✓Typesafe✓Non-blocking composition✓Declarative using direct style✓Deterministic
  102. The Good✓Typesafe✓Non-blocking composition✓Declarative using direct style✓Deterministic✓Non-local composition
  103. The Bad
  104. The Bad☣CPS plugin error messages
  105. The Bad☣CPS plugin error messages☣Limited applicability
  106. The Bad☣CPS plugin error messages☣Limited applicability— Error handling
  107. The Bad☣CPS plugin error messages☣Limited applicability— Error handling☣Debugging
  108. The Bad☣CPS plugin error messages☣Limited applicability— Error handling☣Debugging☣Futures are one-off
  109. The Ugly
  110. The UglyCPS plugin error messages!!
  111. CompartmentalizationExecutionCoordinationConclusion
  112. CompartmentalizationExecutionCoordinationConclusionDataflow
  113. Scala Async
  114. The Good
  115. The Good✓Typesafe
  116. The Good✓Typesafe✓Non-blocking composition
  117. The Good✓Typesafe✓Non-blocking composition✓Declarative using direct style
  118. The Bad
  119. The Bad☣Limited applicability
  120. The Bad☣Limited applicability☣Debugging
  121. The Bad☣Limited applicability☣Debugging☣Futures are one-off
  122. The Ugly
  123. The UglyError handling
  124. CompartmentalizationExecutionCoordinationConclusion
  125. CompartmentalizationExecutionCoordinationConclusionAsync
  126. Threads… and Queues
  127. The Good
  128. The Good✓Typesafe
  129. The Good✓Typesafe✓Blocking or Non-blocking
  130. The Good✓Typesafe✓Blocking or Non-blocking✓Back pressure possible
  131. The Bad
  132. The Bad☣Heavyweight
  133. The Bad☣Heavyweight☣Scarce
  134. The Bad☣Heavyweight☣Scarce☣Diminishing returns
  135. The Bad☣Heavyweight☣Scarce☣Diminishing returns☣High wake-up latency
  136. The Bad☣Heavyweight☣Scarce☣Diminishing returns☣High wake-up latency☣Not really high-level
  137. The Bad☣Heavyweight☣Scarce☣Diminishing returns☣High wake-up latency☣Not really high-level☣No means of recovery
  138. The Ugly
  139. The UglyPropagating failure
  140. The UglyPropagating failureUnidirectional
  141. CompartmentalizationExecutionCoordinationConclusion
  142. CompartmentalizationExecutionCoordinationConclusionThread + Queue
  143. Actors
  144. The Good
  145. The Good✓Encapsulation
  146. The Good✓Encapsulation✓Supervision
  147. The Good✓Encapsulation✓Supervision✓Configurable execution
  148. The Good✓Encapsulation✓Supervision✓Configurable execution✓Location transparency
  149. The Good✓Encapsulation✓Supervision✓Configurable execution✓Location transparency✓Models real-world
  150. The Good✓Encapsulation✓Supervision✓Configurable execution✓Location transparency✓Models real-world✓Require less guarantees
  151. The Bad
  152. The Bad☣Untyped
  153. The Bad☣Untyped☣Explicit lifecycle management
  154. The Bad☣Untyped☣Explicit lifecycle management☣Debugging
  155. The Ugly
  156. The UglyEasy encapsulation violation
  157. The UglyEasy encapsulation violationComposition can be awkward
  158. CompartmentalizationExecutionCoordinationConclusion
  159. CompartmentalizationExecutionCoordinationConclusionActors
  160. Rx & friends
  161. The Good
  162. The Good✓Typesafe
  163. The Good✓Typesafe✓Non-blocking composition
  164. The Good✓Typesafe✓Non-blocking composition✓Reusable components
  165. The Good✓Typesafe✓Non-blocking composition✓Reusable components✓Stream centric
  166. The Bad
  167. The Bad☣Defers failures to downstream
  168. The Bad☣Defers failures to downstream☣Explicit lifecycle management
  169. The Bad☣Defers failures to downstream☣Explicit lifecycle management☣"Glitches"
  170. The Bad☣Defers failures to downstream☣Explicit lifecycle management☣"Glitches"☣Debugging
  171. The Ugly
  172. The UglyCallback Limbo
  173. The UglyCallback LimboInverted control flow
  174. CompartmentalizationExecutionCoordinationConclusion
  175. CompartmentalizationExecutionCoordinationConclusionRx
  176. Functional ReactiveProgramming
  177. The Good
  178. The Good✓Typesafe
  179. The Good✓Typesafe✓Declarative value composition
  180. The Good✓Typesafe✓Declarative value composition✓Direct style
  181. The Good✓Typesafe✓Declarative value composition✓Direct style✓Deterministic
  182. The Bad
  183. The Bad☣Single-threaded
  184. The Ugly
  185. The UglySide-effecting can introduceglitches
  186. CompartmentalizationExecutionCoordinationConclusion
  187. CompartmentalizationExecutionCoordinationConclusionFRP
  188. Summary60
  189. CompartmentalizationExecutionCoordinationConclusion
  190. CompartmentalizationExecutionCoordinationSTMConclusion
  191. CompartmentalizationExecutionCoordinationSTMConclusionScala Future
  192. CompartmentalizationExecutionCoordinationSTMConclusionScala FutureFRP
  193. CompartmentalizationExecutionCoordinationSTMJava FutureConclusionScala FutureFRP
  194. CompartmentalizationExecutionCoordinationSTMJava FutureConclusionScala FutureFRPActors
  195. CompartmentalizationExecutionCoordinationSTMJava FutureConclusionScala FutureFRPActorsDataflow & Async & Rx
  196. CompartmentalizationExecutionCoordinationSTMJava FutureConclusionScala FutureFRPActorsDataflow & Async & RxThread + Queue
  197. CompartmentalizationExecutionCoordinationSTMJava FutureConclusionScala FutureFRPActorsDataflow & Async & RxThread + QueueExecutor
  198. CompartmentalizationExecutionCoordinationSTMJava FutureConclusionScala FutureFRPActorsDataflow & Async & RxThread + QueueExecutorThread + Locks
  199. Conclusion
  200. ConclusionPick
  201. ConclusionPickyour
  202. ConclusionPickyour☠
  203. E0F

×