async or bust
play

Async or Bust!? Todd L. Montgomery @toddlmontgomery About me The - PowerPoint PPT Presentation

Async or Bust!? Todd L. Montgomery @toddlmontgomery About me The Myth(s) Illusion & Cognitive Dissonance Impact of the Myth Subjectivity of the Myth Do you remember. https://www.youtube.com/watch?v=bzkRVzciAZg The


  1. Async or Bust!? Todd L. Montgomery @toddlmontgomery

  2. About me…

  3. ✓ The Myth(s) ✓ Illusion & Cognitive Dissonance ✓ Impact of the Myth ✓ Subjectivity of the Myth

  4. Do you remember….

  5. https://www.youtube.com/watch?v=bzkRVzciAZg

  6. The Myth Sequential is good enough

  7. The Myth Sequential is good enough …. Async is complicated & error prone

  8. A Right Way & MANY Wrong Ways

  9. In Reality… MANY Right Ways & MANY Wrong Ways

  10. Wording Sequential Asynchronous Synchronous Non-Blocking Blocking

  11. What is Sync? Request Processing Response

  12. What is Async? Request Processing Response

  13. What is Async? Request Processing Response Cross Thread/Core/Node

  14. What is Async? Request ? Processing Response

  15. What is Event-Driven? Request ? Response

  16. Illusion of Sequentiality

  17. Ordering is an Illusion

  18. Compiler can re-order Runtime can re-order CPU can re-order

  19. Ordering has to be imposed!

  20. Illusion of Sequentiality

  21. Illusion of Sequentiality • CPUs - Load/Store Buffers

  22. Illusion of Sequentiality • CPUs - Load/Store Buffers • Storage - Caches

  23. Illusion of Sequentiality • CPUs - Load/Store Buffers • Storage - Caches • OS - VM & Caches

  24. Illusion of Sequentiality • CPUs - Load/Store Buffers • Storage - Caches • OS - VM & Caches • Library - Promises / Futures

  25. As easy* as… Request Response Request Sync Requests Response & Request Responses Response * - for some definition of @toddlmontgomery

  26. But with efficiency of… Request Request Async Requests Request & Response Responses Response Response @toddlmontgomery

  27. Do something while waiting

  28. Request 0 Request 1 Async Requests Request 2 & Response 0 Responses Response 1 Response 2 Correlation! @toddlmontgomery

  29. Request 0 Request 1 Ordering Request 2 Response 0 Response 1 Response 2 Correlation! @toddlmontgomery

  30. Request 0 Response 0 (Valid) Request 1 Re-Ordering (one of many) Response 1 Request 2 Response 2 Correlation! @toddlmontgomery

  31. The key is to wait… That has a price!

  32. Price of Illusion • Opportunity to De-Schedule

  33. Price of Illusion • Opportunity to De-Schedule • Locks + Signaling

  34. Price of Illusion • Opportunity to De-Schedule • Locks + Signaling • Semaphores • Condition Variables

  35. Cognitive Dissonance

  36. Cognitive Dissonance • Completed Operation Fallacy

  37. Cognitive Dissonance • Completed Operation Fallacy • Caching

  38. Caches Request Block Response Flush … @toddlmontgomery

  39. Caches Request Block Response Flush … …? @toddlmontgomery

  40. Caches Request Block Response Flush … …? Stable… ? @toddlmontgomery

  41. Cognitive Dissonance • Completed Operation Fallacy • Caching • Blocking ACK Spiral

  42. Blocking ACK Request Block Response Block Response ACK @toddlmontgomery

  43. Blocking ACK Request Block Response Block Response ACK X @toddlmontgomery

  44. Blocking ACK Request Block Response Block Response ACK X Receiver Blocks Forever @toddlmontgomery

  45. Blocking ACK Request Block Response Block Response ACK Response ACK-ACK Spiral!!! @toddlmontgomery

  46. Cognitive Dissonance • Completed Operation Fallacy • Caching • Blocking ACK Spiral • Wrong Abstraction • Remote Procedure Call

  47. Abstraction “The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise” — Edsger W. Dijkstra (The Humble Programmer)

  48. Remote Procedure Call • Hiding precision • Inherent asynchronous nature • Error handling

  49. Remote Procedure Call Don’t assume the network is reliable https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing

  50. Remote Procedure Call “Yeah, yeah, but your scientists were so preoccupied with whether or not they could that they didn't stop to think if they should.” — Jurassic Park

  51. Works sooo poorly, we took it one step further…

  52. REST via HTTP/1.1 • Custom Methods • Custom Response Codes • No Pipelining • Everything Request/Response

  53. REST via HTTP/2 • Custom Methods • Custom Error Codes • Custom Frame Types • No Pipelining • Mostly Request/Response

  54. Cognitive Dissonance • Completed Operation Fallacy • Caching • Blocking ACK Spiral • Wrong Abstraction • Remote Procedure Call • Coupling

  55. Sequential function calls can and do create Coupling

  56. Impact

  57. Request Response Request Sync Requests Response & Request Responses Response @toddlmontgomery

  58. Request Response Request Sync Requests Response & Request Responses Response Throughput limited by Round-Trip Time (RTT) @toddlmontgomery

  59. Speed of Light isn’t only a good idea, it’s the Law

  60. Accumulated Network Improvement Bandwidth CPU Cores Storage Capacity Memory Capacity Response Time Time

  61. Data RTT ACK Data Stop-And-Wait Flow Control ACK Data ACK Throughput = Data Length / RTT @toddlmontgomery

  62. Bandwidth BDP Delay (Buffer) BDP = (Byte / sec) * sec = Bytes

  63. Data N Data … RTT “Blobs” ACK Throughput = N * Data Length / RTT @toddlmontgomery

  64. So… How big is N?

  65. Thread-Per-Request N = Number of Cores

  66. TCP Flow & Congestion Control How big is N?

  67. TCP Flow & Congestion Control How big is N? It depends…

  68. Big… but Don’t overflow receiver Don’t overflow “network”

  69. TCP Flow Control Receiver advertises N

  70. TCP Congestion Control Sender probes for network N

  71. TCP BBR Congestion Control Bottleneck Bandwidth vs. Round-Trip Time http://queue.acm.org/detail.cfm?id=3022184

  72. TCP Sender min(Receiver N, Network N) Only go as fast as Network & Receiver

  73. Static N? Based on number of cores(threads)? REALLY?!

  74. But that isn’t the worst…

  75. Locks & Signaling • Introduces Serialization

  76. "AmdahlsLaw" by Daniels220 at English Wikipedia - Own work based on: File:AmdahlsLaw.png. Licensed under CC BY-SA 3.0 via Wikimedia Commons

  77. Locks & Signaling • Introduces Serialization • Introduces Coherence Penalty

  78. Universal Scalability Law 20 18 16 14 Speedup 12 10 8 6 4 2 0 1 2 4 8 16 32 64 128 256 512 1024 Processors Amdahl USL

  79. Locks & Signaling • Introduces Serialization • Introduces Coherence Penalty Limits Scaling!

  80. 1 thread of awesome > 128 cores of so-so http://blog.acolyer.org/2015/06/05/scalability-but-at-what-cost/ http://www.frankmcsherry.org/graph/scalability/cost/2015/01/15/COST.html

  81. Async is HARD!!!

  82. Async is HARD!! • Callback Hell • Back Pressure!

  83. Composition is hard

  84. ReactiveX http://reactivex.io/

  85. Observables

  86. JavaScript • RxJS • ECMAScript Observables https://github.com/ReactiveX/RxJS https://github.com/zenparsing/es-observable

  87. Challenges?

  88. Challenges • Non-Blocking Back Pressure • Heterogeneous Connectivity

  89. Dealing with Back Pressure • ReactiveStreams • RxJava 2.0 http://www.reactive-streams.org/

  90. Rx Heterogenous Connectivity • ReactiveSocket http://reactivesocket.io/

  91. Async is HARD!! • Callback Hell • Back Pressure! • Breaking up work units?

  92. Threaded Work Units • Work between System Calls

  93. Threaded Work Units • Work between System Calls • Time between System Calls High Variance

  94. Async Duty Cycle • Work within a single cycle First Class Concern

  95. Async is HARD!! • Callback Hell • Back Pressure! • Duty Cycle • Error Handling

  96. Error Handling • Errors are events No real difference!!

  97. Error Handling Be Honest…

  98. Takeaways!

  99. Still Think… Sequential is good enough? …. Async is complicated & error prone?

Recommend


More recommend