Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
A Brief History of Channels
Andrew Godwin
March 31, 2016
Programming
2
1.6k
A Brief History of Channels
A talk I gave at DjangoCon Europe 2016
Andrew Godwin
March 31, 2016
Tweet
Share
More Decks by Andrew Godwin
See All by Andrew Godwin
Writing Maintainable Software At Scale
andrewgodwin
0
180
A Newcomer's Guide To Airflow's Architecture
andrewgodwin
0
150
Async, Python, and the Future
andrewgodwin
2
440
How To Break Django: With Async
andrewgodwin
1
420
Taking Django's ORM Async
andrewgodwin
0
400
The Long Road To Asynchrony
andrewgodwin
0
420
The Scientist & The Engineer
andrewgodwin
1
440
Pioneering Real-Time
andrewgodwin
0
190
Just Add Await: Retrofitting Async Into Django
andrewgodwin
2
1.2k
Other Decks in Programming
See All in Programming
Hasura の Relationship と権限管理
karszawa
0
160
子育てとEMと転職と
_atsushisakai
1
330
WordPress(再)入門 - 基礎知識・環境編
oleindesign
1
120
Circuit⚡
monaapk
0
200
Enumを自動で網羅的にテストしてみた
estie
0
1.2k
Swift Concurrency in GoodNotes
inamiy
4
1.3k
PHPDocにおける配列の型定義を少し知る
shimabox
1
130
Makuakeの認証基盤とRe-Architectureチーム
bmf_san
0
380
T3 Stack and TypeScript ecosystem
quramy
3
720
Ruby Pattern Matching
bkuhlmann
0
610
花き業界のサプライチェーンを繋げるプロダクト開発の進め方
userlike1
0
150
ちょうぜつ改め21世紀ふつうのソフトウェア設計
tanakahisateru
7
6.3k
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
89
4.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
317
22k
Ruby is Unlike a Banana
tanoku
93
9.5k
Done Done
chrislema
178
14k
Into the Great Unknown - MozCon
thekraken
2
280
Art, The Web, and Tiny UX
lynnandtonic
284
18k
Optimizing for Happiness
mojombo
365
64k
Why You Should Never Use an ORM
jnunemaker
PRO
49
7.9k
Principles of Awesome APIs and How to Build Them.
keavy
117
15k
We Have a Design System, Now What?
morganepeng
37
5.9k
Designing on Purpose - Digital PM Summit 2013
jponch
108
5.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
236
1.1M
Transcript
Andrew Godwin @andrewgodwin BRIEF HISTORY of CHANNELS A
Andrew Godwin Hi, I'm Django core developer Senior Software Engineer
at Likes networking a little bit too much
Channels
Channels?
WebSocket
HTTP 1 request response Browser Server request response request response
request response
HTTP 2 request response Browser Server request response request 1
response 2 request 2 response 1
WSGI request response Browser Server Django call app return val
WebSockets receive send Browser Server send receive send send
receive send Browser Server send receive send send Django ?
Hard to deadlock Built-in authorisation Scales down Widely deployable Optional
Django is not built for this.
But what if it was?
Instead of requests, we have events
Events of the same type are grouped on a named
channel
HTTP requests HTTP responses WebSocket connecteds WebSocket frames received WebSocket
frames sent WebSocket disconnections
A channel is a: named, first-in-first-out, at-most-once, non-broadcast, network-transparent queue
of messages
http.request Protocol Server Worker Server http.response websocket.connect websocket.send websocket.receive websocket.send
websocket.send
Responses are on single-reader channels (http.response!1A2B3C)
You can send onto channels from anywhere
How do you use it?
View request response callable
Consumer event event callable event event
Every message on a channel runs the consumer function
http.request routes to a view system consumer
def ws_message(message): # Get things from message data = json.loads(message['text'])
# Use ORM like normal MyModel.objects.create( value=data['value'], ) # Send a reply and close socket message.reply_channel.send({ 'text': 'OK', 'close': True, })
routing.py: urls.py for Channels
message.user: like request.user
message.channel_session: per-socket sessions
Groups broadcast/pub-sub
Add a channel to a Group Remove a channel from
a Group Send to a Group
Worked Examples github.com/andrewgodwin/channels-examples
Liveblog http.request Django view layer websocket.connect Add to liveblog Group
websocket.disconnect Remove from liveblog Group <Article.save> Send notification to liveblog
Chat http.request Django view layer websocket.receive Either add to room
Group or send to chat_messages websocket.disconnect Remove from room Groups chat_messages Send to room Groups
It's so easy to join! CALL NOW
Things I didn't even get to: Replacing WSGI Pluggable channel
backends Sharding and scaling It's still just runserver
A base for the future Scheduler? Retry logic? Generic Consumers?
...and much more
1.10 "Provisional"?
1.8 1.9 pip install channels
channels.readthedocs.com github.com/andrewgodwin/channels-examples
Thanks. Andrew Godwin @andrewgodwin