SLIDE 1 Async or Bust!?
Todd L. Montgomery @toddlmontgomery
SLIDE 2
About me…
SLIDE 3
✓ The Myth(s) ✓ Illusion & Cognitive Dissonance ✓ Impact of the Myth ✓ Subjectivity of the Myth
SLIDE 4
Do you remember….
SLIDE 5 https://www.youtube.com/watch?v=bzkRVzciAZg
SLIDE 6
The Myth Sequential is good enough
SLIDE 7
The Myth Sequential is good enough …. Async is complicated & error prone
SLIDE 8
A Right Way & MANY Wrong Ways
SLIDE 9
MANY Right Ways & MANY Wrong Ways In Reality…
SLIDE 10
Sequential Synchronous Blocking Asynchronous Non-Blocking Wording
SLIDE 11 What is Sync?
Request Response Processing
SLIDE 12 What is Async?
Request Response Processing
SLIDE 13 What is Async?
Request Response Processing Cross Thread/Core/Node
SLIDE 14 What is Async?
Request Response Processing
?
SLIDE 15 What is Event-Driven?
Request Response
?
SLIDE 16
Illusion of Sequentiality
SLIDE 17
Ordering is an Illusion
SLIDE 18
Compiler can re-order Runtime can re-order CPU can re-order
SLIDE 19
Ordering has to be imposed!
SLIDE 20
Illusion of Sequentiality
SLIDE 21
- CPUs - Load/Store Buffers
Illusion of Sequentiality
SLIDE 22
- CPUs - Load/Store Buffers
- Storage - Caches
Illusion of Sequentiality
SLIDE 23
- CPUs - Load/Store Buffers
- Storage - Caches
- OS - VM & Caches
Illusion of Sequentiality
SLIDE 24
- CPUs - Load/Store Buffers
- Storage - Caches
- OS - VM & Caches
- Library - Promises / Futures
Illusion of Sequentiality
SLIDE 25 @toddlmontgomery
Sync Requests & Responses Request Request Request Response Response Response
As easy* as…
* - for some definition of
SLIDE 26 @toddlmontgomery
Async Requests & Responses Request Request Request Response Response Response
But with efficiency of…
SLIDE 27
Do something while waiting
SLIDE 28 @toddlmontgomery
Async Requests & Responses Correlation! Request 0 Request 1 Request 2 Response 0 Response 1 Response 2
SLIDE 29 @toddlmontgomery
Correlation! Request 0 Request 1 Request 2 Response 0 Response 1 Response 2 Ordering
SLIDE 30 @toddlmontgomery
Correlation! Request 0 Request 1 Request 2 Response 0 Response 1 Response 2 (Valid) Re-Ordering (one of many)
SLIDE 31
The key is to wait… That has a price!
SLIDE 32
- Opportunity to De-Schedule
Price of Illusion
SLIDE 33
- Opportunity to De-Schedule
- Locks + Signaling
Price of Illusion
SLIDE 34
- Opportunity to De-Schedule
- Locks + Signaling
- Semaphores
- Condition Variables
Price of Illusion
SLIDE 35
Cognitive Dissonance
SLIDE 36
- Completed Operation Fallacy
Cognitive Dissonance
SLIDE 37
- Completed Operation Fallacy
- Caching
Cognitive Dissonance
SLIDE 38 @toddlmontgomery
Flush … Request Response Block
Caches
SLIDE 39 @toddlmontgomery
Flush … Request Response Block
Caches
…?
SLIDE 40 @toddlmontgomery
Flush … Request Response Block
Caches
Stable… ? …?
SLIDE 41
- Completed Operation Fallacy
- Caching
- Blocking ACK Spiral
Cognitive Dissonance
SLIDE 42 @toddlmontgomery
Block Request Response ACK Response Block
Blocking ACK
SLIDE 43 @toddlmontgomery
Block Request Response ACK Response Block
Blocking ACK
X
SLIDE 44 @toddlmontgomery
Block Request Response ACK Response Block
Blocking ACK
X
Receiver Blocks Forever
SLIDE 45 @toddlmontgomery
Block Request Response ACK Response Spiral!!! Block
Blocking ACK
Response ACK-ACK
SLIDE 46
- Completed Operation Fallacy
- Caching
- Blocking ACK Spiral
- Wrong Abstraction
- Remote Procedure Call
Cognitive Dissonance
SLIDE 47
“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) Abstraction
SLIDE 48
- Hiding precision
- Inherent asynchronous nature
- Error handling
Remote Procedure Call
SLIDE 49 Don’t assume the network is reliable
https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing
Remote Procedure Call
SLIDE 50
“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 Remote Procedure Call
SLIDE 51
Works sooo poorly, we took it one step further…
SLIDE 52 REST via HTTP/1.1
- Custom Methods
- Custom Response Codes
- No Pipelining
- Everything Request/Response
SLIDE 53 REST via HTTP/2
- Custom Methods
- Custom Error Codes
- Custom Frame Types
- No Pipelining
- Mostly Request/Response
SLIDE 54
- Completed Operation Fallacy
- Caching
- Blocking ACK Spiral
- Wrong Abstraction
- Remote Procedure Call
- Coupling
Cognitive Dissonance
SLIDE 55
Sequential function calls can and do create Coupling
SLIDE 56
Impact
SLIDE 57 @toddlmontgomery
Sync Requests & Responses Request Request Request Response Response Response
SLIDE 58 @toddlmontgomery
Sync Requests & Responses Request Request Request Response Response Response Throughput limited by Round-Trip Time (RTT)
SLIDE 59
Speed of Light isn’t only a good idea, it’s the Law
SLIDE 60 Accumulated Improvement Time Network Bandwidth Response Time Storage Capacity CPU Cores Memory Capacity
SLIDE 61 @toddlmontgomery
Data Data Data ACK ACK ACK Throughput = Data Length / RTT RTT Stop-And-Wait Flow Control
SLIDE 62
SLIDE 63 Delay Bandwidth BDP = (Byte / sec) * sec = Bytes BDP (Buffer)
SLIDE 64 @toddlmontgomery
Data ACK RTT Throughput = N * Data Length / RTT … N Data “Blobs”
SLIDE 65
So… How big is N?
SLIDE 66
N = Number of Cores Thread-Per-Request
SLIDE 67
How big is N? TCP Flow & Congestion Control
SLIDE 68
How big is N? It depends… TCP Flow & Congestion Control
SLIDE 69
Big… but Don’t overflow receiver Don’t overflow “network”
SLIDE 70
TCP Flow Control Receiver advertises N
SLIDE 71
TCP Congestion Control Sender probes for network N
SLIDE 72 TCP BBR Congestion Control Bottleneck Bandwidth vs. Round-Trip Time
http://queue.acm.org/detail.cfm?id=3022184
SLIDE 73 TCP Sender min(Receiver N, Network N)
Only go as fast as Network & Receiver
SLIDE 74
Static N? Based on number of cores(threads)? REALLY?!
SLIDE 75
But that isn’t the worst…
SLIDE 76 Locks & Signaling
SLIDE 77 "AmdahlsLaw" by Daniels220 at English Wikipedia - Own work based on: File:AmdahlsLaw.png. Licensed under CC BY-SA 3.0 via Wikimedia Commons
SLIDE 78 Locks & Signaling
- Introduces Serialization
- Introduces Coherence Penalty
SLIDE 79 Universal Scalability Law
2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024
Speedup Processors
Amdahl USL
SLIDE 80 Locks & Signaling
- Introduces Serialization
- Introduces Coherence Penalty
Limits Scaling!
SLIDE 81 1 thread of awesome > 128 cores of so-so
http://www.frankmcsherry.org/graph/scalability/cost/2015/01/15/COST.html http://blog.acolyer.org/2015/06/05/scalability-but-at-what-cost/
SLIDE 82
Async is HARD!!!
SLIDE 83
- Callback Hell
- Back Pressure!
Async is HARD!!
SLIDE 84
Composition is hard
SLIDE 85 ReactiveX
http://reactivex.io/
SLIDE 86
Observables
SLIDE 87 JavaScript
- RxJS
- ECMAScript Observables
https://github.com/ReactiveX/RxJS https://github.com/zenparsing/es-observable
SLIDE 88
Challenges?
SLIDE 89
- Non-Blocking Back Pressure
- Heterogeneous Connectivity
Challenges
SLIDE 90 Dealing with Back Pressure
- ReactiveStreams
- RxJava 2.0
http://www.reactive-streams.org/
SLIDE 91 Rx Heterogenous Connectivity
http://reactivesocket.io/
SLIDE 92
- Callback Hell
- Back Pressure!
- Breaking up work units?
Async is HARD!!
SLIDE 93 Threaded Work Units
- Work between System Calls
SLIDE 94 Threaded Work Units
- Work between System Calls
- Time between System Calls
High Variance
SLIDE 95 Async Duty Cycle
- Work within a single cycle
First Class Concern
SLIDE 96
- Callback Hell
- Back Pressure!
- Duty Cycle
- Error Handling
Async is HARD!!
SLIDE 97 Error Handling
No real difference!!
SLIDE 98
Error Handling Be Honest…
SLIDE 99
Takeaways!
SLIDE 100
Still Think… Sequential is good enough? …. Async is complicated & error prone?
SLIDE 101 @toddlmontgomery
Questions?
Thank You!