Asyncio in Production
Asyncio in Production
Asyncio in Production
Hrafn Eiriksson
Why you no asyncio?!
Why you no asyncio?!
Credit: https://www.destroyallsoftware.com/talks/wat
A bit of background...
How we (typically) scale our services
Instance 1
Gunicorn
worker 1
Instance 2
Gunicorn
Clients Gunicorn worker 2
Instance 3
master
Load
Gunicorn
balancer
Instance 4 worker 3
... ...
Gunicorn
Instance x
worker y
flow
TLDR
- Explicit
- Part of the language
Part 2: Migrating to asyncio
The asyncio ecosystem
[1] https://github.com/python/asyncio/wiki/ThirdParty
A microservice migration
Based on a true story
Asyncio web frameworks
Sanic
aiohttp
WebSockets
support
Mature
Flask-like
Fast
Flask compatible
HTTP 2.0
An example: Quart
Flask Quart [2]
[2] https://gitlab.com/pgjones/quart
aiohttp
A migration example: Sentry
Then problems hit...
Issues with asyncio
- A lot of new concepts to wrap your head around
- async/await everywhere
- Debugging asyncio code can be problematic
- Be wary of running synchronous code in async functions
TLDR
VS
Requests/sec
Local comparison: Database access
Requests/sec
In production comparison
Requests/sec
Conclusion