Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ASGIについて
Search
Kaito
May 07, 2021
Programming
0
310
ASGIについて
コード例
Kaito
May 07, 2021
Tweet
Share
More Decks by Kaito
See All by Kaito
CGと機械学習
kaitolucifer
0
170
Other Decks in Programming
See All in Programming
Navigation 3: 적응형 UI를 위한 앱 탐색
fornewid
1
440
tparseでgo testの出力を見やすくする
utgwkk
2
270
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
7
2.3k
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
440
Go コードベースの構成と AI コンテキスト定義
andpad
0
140
TestingOsaka6_Ozono
o3
0
170
Navigating Dependency Injection with Metro
l2hyunwoo
1
170
バックエンドエンジニアによる Amebaブログ K8s 基盤への CronJobの導入・運用経験
sunabig
0
170
認証・認可の基本を学ぼう前編
kouyuume
0
270
Python札幌 LT資料
t3tra
6
1k
Patterns of Patterns
denyspoltorak
0
280
開発に寄りそう自動テストの実現
goyoki
2
1.4k
Featured
See All Featured
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
100
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
170
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Prompt Engineering for Job Search
mfonobong
0
120
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
120
Are puppies a ranking factor?
jonoalderson
0
2.4k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
SEO for Brand Visibility & Recognition
aleyda
0
4.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
Agile that works and the tools we love
rasmusluckow
331
21k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
80
Transcript
ASGIについて
⽬次 1. WSGIとは 2. WSGIの限界 3. コルーチン 4. Pythonのコルーチン 5.
イベントループ 6. Pythonのイベントループ 7. ASGIとは 8. ASGIの問題点 2
WSGIとは n PEP333で提案され、PEP3333でアップグレードされたPythonのWebサーバーインターフェース Ø Pythonにおいて、WebアプリケーションとWebサーバーのインタラクションをスタンダート 化する n WSGIフレームワーク n WSGIサーバー
3 ASGIについて mod_wsgi
WSGIとは n WSGIサーバーとWSGIアプリケーション 4 ASGIについて 画像参照:https://www.cabotsolutions.com/a-detailed-study-of-wsgi-web-server-gateway-interface-of-python
WSGIとは n WSGIアプリケーションのインターフェース 5 ASGIについて
WSGIの限界 n 公式ではwebsocketに対応していない Ø は公式の解決策ではない 6 ASGIについて 画像参照: https://ja.javascript.info/websocket
WSGIの限界 n HTTP/2に対応してない Ø WSGIサーバーがWSGIアプリケーションを呼び出した後は戻り値が戻ってくるまでブロッキ ングする(基本的には) 7 ASGIについて 画像参照:https://medium.com/475cumulus/wsgi-is-not-enough-anymore-part-i-bc9713a79841
WSGIの限界 n ネイティブコルーチンと連携できない Ø asyncとawaitが使えない Ø gevent workerなどを使⽤する場合、既存のイベントループと別に、新しいイベントループを 作る必要がある Ø
Python3.7から使えるasyncio.runも実は新しいイベントループを作っている 8 ASGIについて
コルーチン 9 ASGIについて n ⼀時中断や再開が可能なプログラミング構造
Pythonのコルーチン n ネイティブコルーチン Ø async、awaitで実現されたコルーチン n ジェネレーターベースのコルーチン Ø ジェネレーターのyield,yield from,sendなどで実現されたコルーチン
Ø 現在は⾮推奨 n greenlet Ø サードパーティのC⾔語拡張で実現されたコルーチン Ø geventなどで、標準ライブラリのio処理を⾮同期化できる(モンキーパッチ) Ø サードパーティと⾊々互換性の問題がある 10 ASGIについて
イベントループ 11 ASGIについて 画像参照: https://dev.to/djangostars/asynchronous-programming-in-python--asyncio-guide-2c61
Pythonイベントループ n asyncioのデフォルトイベントループ Ø 基本的に遅い n uvloop Ø nodejsで使われたlibuvのPythonバインディング n
curio Ø asyncioの代替で、独⾃のイベントループを実装 n trio Ø asyncioの代替で、独⾃のイベントループを実装 12 ASGIについて
ASGIとは n Django Software Foundationが提案したPythonの⾮同期サーバーインターフェース Ø https://channels.readthedocs.io/en/stable/asgi.html Ø WSGIの各制限を解決するためのもの n
ASGIフレームワーク n ASGIサーバー 13 ASGIについて Daphne
ASGIとは n ASGIアプリケーションのインターフェース 14 ASGIについて
ASGIとは n ⾼速 Ø 同期WSGIサーバー・アプリケーションより2倍以上速い n リソースの利⽤率が⾼い Ø CPUのアイドル時間を減らせる n
WebSocketとHTTP/2の対応 15 ASGIについて 画像参照: https://florimond.dev/blog/articles/2019/08/introduction-to-asgi-async-python-web/
ASGIの問題点 n 同期ioと混在すると、⾜が引っ張られる Ø all inする必要がある n ライブラリはまだ充実してない Ø 例えば、⾮同期ORMはTortoise
ORMぐらいしかない n エラーハンドルが難しい Ø trioはこの問題に特化したライブラリ 16 ASGIについて