Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Concurrency to Channels
Search
Andrew Godwin
October 08, 2017
Programming
1
330
Concurrency to Channels
My keynote from Python Brasil 13 (2017).
Andrew Godwin
October 08, 2017
Tweet
Share
More Decks by Andrew Godwin
See All by Andrew Godwin
Reconciling Everything
andrewgodwin
1
270
Django Through The Years
andrewgodwin
0
170
Writing Maintainable Software At Scale
andrewgodwin
0
400
A Newcomer's Guide To Airflow's Architecture
andrewgodwin
0
330
Async, Python, and the Future
andrewgodwin
2
620
How To Break Django: With Async
andrewgodwin
1
690
Taking Django's ORM Async
andrewgodwin
0
690
The Long Road To Asynchrony
andrewgodwin
0
620
The Scientist & The Engineer
andrewgodwin
1
720
Other Decks in Programming
See All in Programming
苦しいTiDBへの移行を乗り越えて快適な運用を目指す
leveragestech
0
1.1k
XStateを用いた堅牢なReact Components設計~複雑なClient Stateをシンプルに~ @React Tokyo ミートアップ #2
kfurusho
1
990
読まないコードリーディング術
hisaju
0
110
バッチを作らなきゃとなったときに考えること
irof
2
530
LINE messaging APIを使ってGoogleカレンダーと連携した予約ツールを作ってみた
takumakoike
0
120
How mixi2 Uses TiDB for SNS Scalability and Performance
kanmo
41
16k
楽しく向き合う例外対応
okutsu
0
700
Honoのおもしろいミドルウェアをみてみよう
yusukebe
1
230
Django NinjaによるAPI開発の効率化とリプレースの実践
kashewnuts
1
280
PHPのバージョンアップ時にも役立ったAST
matsuo_atsushi
0
230
SwiftUI Viewの責務分離
elmetal
PRO
2
280
PHPカンファレンス名古屋2025 タスク分解の試行錯誤〜レビュー負荷を下げるために〜
soichi
1
720
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1030
460k
Mobile First: as difficult as doing things right
swwweet
223
9.5k
Faster Mobile Websites
deanohume
306
31k
How to Think Like a Performance Engineer
csswizardry
22
1.4k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
430
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.1k
BBQ
matthewcrist
87
9.5k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Gamification - CAS2011
davidbonilla
80
5.2k
Building an army of robots
kneath
303
45k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.3k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Transcript
Andrew Godwin @andrewgodwin
Hi, I’m Andrew Godwin • Django core developer • Senior
Software Engineer at • South, Django migrations, Channels
What is Channels?
What is Channels?
Why Channels?
2000 2008 2015
Python 1.5 Threading 2000
Twisted 1.0 2002
WSGI (PEP 333) 2003
Python 2.6 Multiprocessing 2008
Django 1.0 2008
Eventlet / gevent 2009
Python 3.4 asyncio 2014
Python 3.5 async / await 2015
Web request handling is “solved” We have good patterns and
standards
Web request handling is easy It’s stateless, and has a
fixed response pattern
Client Server Request Response Process
Other protocols are not so easy Like WebSockets and MQTT
This is why they are more efficient No overheads of
cookies, headers and TCP handshake
Client Server Connect Data ??? Data Data Data
Writing async code is harder There’s a reason we don’t
do it all the time
Deadlocks Livelocks Race conditions Resource starvation
Simple Race Condition
Thread 1 Thread 2 if self.funds[..] < .. if self.funds[..]
< .. self.funds[..] += .. self.funds[..] -= .. self.funds[..] += .. self.funds[..] -= .. {"a": 20, "b": 0} {"a": 0, "b": 20} {"a": -20, "b": 40}
“Fixing” it, but actually adding a deadlock
Thread 1 Thread 2 get lock a get lock b
release lock b release lock a get lock b get lock a release lock a release lock b
Thread 1 Thread 2 get lock a get lock b
get lock b get lock a
More threads = more problems And hard to find in
development when you have no users
CSP “Communicating Sequential Processes” Algebra for talking about concurrency &
problems
You don’t need everything async Only the important bits
Channels: sync + async tooling Traditional synchronous Django with async
handling
“ASGI”: WSGI + async An interface that works for more
than request-response.
Goal: You mostly write sync code Channels/Django handles the annoying
part
Sync code for async behaviour
Why not just use asyncio? Do we need channels at
all?
Channels 1: Can’t write async code too Have to write
it separate outside of Channels framework
Channels 2: asyncio + sync support You can write code
as complex as you need to
Channels does not solve everything Neither does Django, the goal
is a good place to start
Working on more than just WebSocket Ways to write Django/Python
against anything with “events”
WebSockets? Emails? Chat? SMS?
What is Django in future? Is it HTTP requests forever?
Making async code easier = good Give people a way
to learn safely
Make Python the best place for these Even if it
doesn’t end up being Django.
Thanks. Andrew Godwin @andrewgodwin aeracode.org