Delivered at Python Toronto on 18th Sep 2018. Asyncio's is the new frontier in Python and these slides share my experiences with it while working at SwissBorg.
1. Python Toronto : Sep 2018
Final Frontier in
Python : Async
Ankit Mittal - @ankitml
SwissBorg
2. Python has come a
long way in last 4 years
Generators were the original
final frontiers
3. Experiences from writing a crypto exchange in Async Python
Async Components
• RESTful API
• Websockets
• Order Matching Engine
• Accounting Engine
4. An async lament
3 Failed projects, until it did not
Starting up with async not a
painless activity
5. Asyncio: The hard parts
❖ New Syntax
❖ Architecture and abstractions
for async programs
❖ New terms : coroutines, tasks, event
loops, awaitables, executables, futures
❖ New Libraries
❖ One does not simply write
async and meet deadlines
6. The silver lining
❖ Real problem is not asyncio’s
complexity or learning curve
❖ Non blocking mental model is
hard, coming from years of
blocking python
❖ Non blocking abstractions take
time to marinate the brain
❖ All of these are learnable,
intuition starts appearing
❖ Concurrency without locks is a
major win
8. Simultaneous Exhibition as Async execution
❖ Miguel Grinberg in his pycon talk explains
async mental model with a chess analogy
❖ A grandmaster needs to play 30
games. Other players responds in 5 minutes
for a turn and the game ends in 12 turns.
❖ Blocking Code: He plays them one
by one (30 hours)
❖ Non Blocking Code is like an
exhibition match, grandmaster does not
wait for player’s response and moves on to
the next game. Grandmaster himself
decides when he wants to move on to next
game. (This is explicit yield of control, act of
awaiting a task)
9. Eventual Simplicity
❖ After grokking async model
and its python abstractions
❖ Async model feels much
simpler than other concurrency
models
❖ Predictability arising from
explicit yield.
❖ Predictable outcomes makes it
much more accessible to real
world async problems
11. Summing up :
❖ Ayncio’s Explicit non-blocking architecture
can give a big leverage to python programs.
❖ Its biggest problem is initial learning curve.
❖ Give it a try and embrace the new frontier in python.
12. ❖ Product Team Stack: Scala, Akka, Reactive ecosystem
❖ Research Team Stack : Python, Financial Markets
(Hint: This is a hiring slide)
Thank You