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
HTTP2とASGI Webサーバの関係 - Hypercornを例に
Search
Junya Fukuda
October 10, 2020
Programming
0
1.3k
HTTP2とASGI Webサーバの関係 - Hypercornを例に
PyCon mini Hiroshima 2020 登壇資料
Junya Fukuda
October 10, 2020
Tweet
Share
More Decks by Junya Fukuda
See All by Junya Fukuda
プロダクションでのPython非同期ユースケース - Trio/Trio-Utilを中心に
jrfk
2
190
Event-Driven asyncio: A Case Study of Trio's API(PyCon US 2024)
jrfk
1
160
EuroPython 2023体験記 - 非英語話者の海外登壇@みんなのPython勉強会#98
jrfk
0
210
Asyncio Evolved: Enhanced Exception Handling with TaskGroup in Python 3.11(PyConTW 2023)
jrfk
0
52
Asyncio Evolved: Enhanced Exception Handling with TaskGroup in Python 3.11(EuroPython 2023)
jrfk
3
1.3k
Django 4.1のAsynchronous
jrfk
1
2.3k
New in Python 3.11: asyncio.TaskGroup and “Hello-ish World” of Asyncio
jrfk
0
490
Python3.11新機能asyncio.TaskGroup()と2022年asyncioの"Hello-ish world"
jrfk
3
3.9k
こわくないasyncio基礎と非同期IO - 動くコードを添えて
jrfk
0
820
Other Decks in Programming
See All in Programming
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
7
1.4k
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
390
カンファレンス動画鑑賞会のススメ / Osaka.swift #1
hironytic
0
170
情報漏洩させないための設計
kubotak
5
1.3k
盆栽転じて家具となる / Bonsai and Furnitures
aereal
0
1.8k
traP の部内 ISUCON とそれを支えるポータル / PISCON Portal
ikura_hamu
0
180
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
0
140
週次リリースを実現するための グローバルアプリ開発
tera_ny
1
1.2k
VisionProで部屋の明るさを反映させるシェーダーを作った話
segur
0
100
ISUCON14感想戦で85万点まで頑張ってみた
ponyo877
1
590
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
370
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
3
190
Featured
See All Featured
Site-Speed That Sticks
csswizardry
2
270
Being A Developer After 40
akosma
89
590k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
192
16k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.7k
Thoughts on Productivity
jonyablonski
68
4.4k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
A better future with KSS
kneath
238
17k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
A Modern Web Designer's Workflow
chriscoyier
693
190k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Transcript
)551ͱ"4(*8FCαʔόͷؔ )ZQFSDPSOΛྫʹ Junya Fukuda PyCon mini Hiroshima 2020
썡쎕썟썷쎣쎟 •ా ൏ʢJunya Fukudaʣʢ@JunyaFffʣ •גࣜձࣾຊγεςϜٕݚʢJSLʣॴଐ ݝͷձࣾ •ੜ·Εౡݝͷ͓ྡɺࢁޱݝ •GEEKLAB.NAGANO •࠷ۙϚΠϯΫϥϑτͰখֶੜ͚Youtube৴࢝ΊΔ ΪʔΫϥϘϚΠΫϥ
ຊ쏅쏍쏁쏱쏽쎅ྲྀ쎣 •ASGIͬͯͳʹʁ •HTTP/2ͬͯͳʹʁ •Hypercorn×FastAPIͰετϦʔϜ •Hypercorn×FastAPIΛͬͨHTTP/1.1 HTTP/2ੑೳଌఆ
1ZUIPO8FCͰ )551Λҙࣝͨ͜͠ͱ ͋Γ·͔͢ʁ
쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •HTTP/2Λҙࣝͨ͜͠ͱ͋·Γͳ͍ •σϓϩΠڥʹϦόʔεϓϩΩγ͍Δ͠ɺHTTP/2ؾʹ͢Δͷͦ͘͜Β͍
쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •HTTP/2Λҙࣝͨ͜͠ͱ͋·Γͳ͍ •σϓϩΠڥʹϦόʔεϓϩΩγ͍Δ͠ɺHTTP/2ؾʹ͢Δͷͦ͘͜Β͍ •ϩʔυόϥϯαʔ ͷଆHTTP/1.1Ͱे
쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •HTTP/2Λҙࣝͨ͜͠ͱ͋·Γͳ͍ •σϓϩΠڥʹϦόʔεϓϩΩγ͍Δ͠ɺHTTP/2ؾʹ͢Δͷͦ͘͜Β͍ •ϩʔυόϥϯαʔ ͷଆHTTP/1.1Ͱे •ʢPure Python ͷWebαʔόͳΜͯʣ
쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •HTTP/2Λҙࣝͨ͜͠ͱ͋·Γͳ͍ •σϓϩΠڥʹϦόʔεϓϩΩγ͍Δ͠ɺHTTP/2ؾʹ͢Δͷͦ͘͜Β͍ •ϩʔυόϥϯαʔ ͷଆHTTP/1.1Ͱे •ͦΜͳͳ͔ɺASGIͱHypercornͱग़ձͬͨ •Python WebͰHTTP/2ʹ͢Δͱͳʹ͕͓͍͍͠ͷʁ •ʢPure Python
ͷWebαʔόͳΜͯʣ
쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •HTTP/2Λҙࣝͨ͜͠ͱ͋·Γͳ͍ •σϓϩΠڥʹϦόʔεϓϩΩγ͍Δ͠ɺHTTP/2ؾʹ͢Δͷͦ͘͜Β͍ •ϩʔυόϥϯαʔ ͷଆHTTP/1.1Ͱे •ͦΜͳͳ͔ɺASGIͱHypercornͱग़ձͬͨ •Python WebͰHTTP/2ʹ͢Δͱͳʹ͕͓͍͍͠ͷʁ •ʢPure Python
ͷWebαʔόͳΜͯʣ •HTTP/3 RFCલɻ࠷ޙʂʁͷHTTP/2ωλ
"4(*ͬͯͳʹʁ
"4(*썺썽쎁쎂 •Asynchronous Server Gateway Interface ͷུ •WSGIͷޙܧ •WebαʔόͱΞϓϦέʔγϣϯͷΠϯλʔϑΣʔεͷ༷
"4(*썺썽쎁쎂 •Asynchronous Server Gateway Interface ͷུ •Webαʔό͕ΞϓϦέʔγϣϯͷ async/await ʹରԠ •WSGIͷޙܧ
•WebαʔόͱΞϓϦέʔγϣϯͷΠϯλʔϑΣʔεͷ༷
"4(*썺썽쎁쎂 •Asynchronous Server Gateway Interface ͷུ •Webαʔό͕ΞϓϦέʔγϣϯͷ async/await ʹରԠ •WSGIͷޙܧ
•WebαʔόͱΞϓϦέʔγϣϯͷΠϯλʔϑΣʔεͷ༷ https://www.youtube.com/watch?v=EwG5EWKu8nw ASGIʢඇಉظαʔόήʔτΣΠΠϯλʔϑΣʔεʣͷ֓ཁ (Junya Fukuda) [PyCon JP 2020]
"4(*썺썽쎁쎂 •Asynchronous Server Gateway Interface ͷུ •Webαʔό͕ΞϓϦέʔγϣϯͷ async/await ʹରԠ •WSGIͷޙܧ
•WebαʔόͱΞϓϦέʔγϣϯͷΠϯλʔϑΣʔεͷ༷ https://www.youtube.com/watch?v=EwG5EWKu8nw ASGIʢඇಉظαʔόήʔτΣΠΠϯλʔϑΣʔεʣͷ֓ཁ (Junya Fukuda) [PyCon JP 2020] •ෳͷҰൠతͳϓϩτίϧΛॲཧՄೳʮHTTP/1.1ʯʮHTTP/2ʯʮWebsocketʯ
"4(*썺썽쎁쎂 •දతͳASGIؔ࿈ͷαʔόͱϑϨʔϜϫʔΫ
)551ͬͯͳʹʁ
)551썺썽쎁쎂 •HTTP/̍.1͔Β16ͷࡀ݄Λܦͯɺ2015ʹRFC •վળΛతͱ༷ͨ͠
)551썺썽쎁쎂 •HTTP/̍.1͔Β16ͷࡀ݄Λܦͯɺ2015ʹRFC •αʔόαΠυϓογϡ •ϔομʔͷѹॖ •ετϦʔϜʢϦΫΤετͷଟॏԽʣ •վળΛతͱ༷ͨ͠
)551썺썽쎁쎂 •HTTP/̍.1͔Β16ͷࡀ݄Λܦͯɺ2015ʹRFC •αʔόαΠυϓογϡ •ϔομʔͷѹॖ •ετϦʔϜʢϦΫΤετͷଟॏԽʣ •վળΛతͱ༷ͨ͠
)551썺썽쎁쎂 •ετϦʔϜ
)551썺썽쎁쎂 •ετϦʔϜ ‣ HTTP/̍.1ͷΛղܾ͢ΔͨΊͷ༷ •1ͭͷϦΫΤετ͕ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍
)551썺썽쎁쎂 ‣ HTTP/̍.1ͷΛղܾ͢ΔͨΊͷ༷ •1ͭͷϦΫΤετ͕ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍ ‣ ΫϥΠΞϯτ ‣ αʔόʔ
)551썺썽쎁쎂 ‣ HTTP/̍.1ͷΛղܾ͢ΔͨΊͷ༷ •1ͭͷϦΫΤετ͕ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍ ‣ ΫϥΠΞϯτ ‣ αʔόʔ
)551썺썽쎁쎂 ‣ HTTP/̍.1ͷΛղܾ͢ΔͨΊͷ༷ •1ͭͷϦΫΤετ͕ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍ ‣ ΫϥΠΞϯτ ‣ αʔόʔ
)551썺썽쎁쎂 ‣ HTTP/̍.1ͷΛղܾ͢ΔͨΊͷ༷ •1ͭͷϦΫΤετ͕ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍ ‣ ΫϥΠΞϯτ ‣ αʔόʔ
)551썺썽쎁쎂 ‣ HTTP/̍.1ͷΛղܾ͢ΔͨΊͷ༷ •1ͭͷϦΫΤετ͕ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍ ‣ ΫϥΠΞϯτ ‣ αʔόʔ
)551썺썽쎁쎂 ‣ HTTP/̍.1ͷΛղܾ͢ΔͨΊͷ༷ •1ͭͷϦΫΤετ͕ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍ ‣ ΫϥΠΞϯτ ‣ αʔόʔ HTTP/̍.1ͷϦΫΤετ-Ϩεϙ ϯεɺৗʹॱ൪Λอͪಉظత
ʹߦΘΕΔඞཁ͕͋Δ
)551썺썽쎁쎂 ‣ HTTP/̍.1ͷΛղܾ͢ΔͨΊͷ༷ •1ͭͷϦΫΤετ͕ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍ ‣ ΫϥΠΞϯτ ‣ αʔόʔ HTTP/̍.1ͷϦΫΤετ-Ϩεϙ ϯεɺৗʹॱ൪Λอͪಉظత
ʹߦΘΕΔඞཁ͕͋Δ WebγεςϜͰ ը໘දࣔ࣌ʹ80ϦΫΤετ
)551썺썽쎁쎂 ‣ ྫ͑օ͞Μ͕͍ͬͯΔGmail
)551썺썽쎁쎂 ‣ HTTP/̍.1ͷΛղܾ͢ΔͨΊͷ༷ •1ͭͷϦΫΤετ͕ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍ ‣ ΫϥΠΞϯτ ‣ αʔόʔ ‣ TCP
× 6ຊ
)551썺썽쎁쎂 ‣ HTTP/̍.1ͷΛղܾ͢ΔͨΊͷ༷ •1ͭͷϦΫΤετ͕ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍ ‣ ΫϥΠΞϯτ ‣ αʔόʔ
)551썺썽쎁쎂 •ετϦʔϜ ‣ ΫϥΠΞϯτ ‣ αʔόʔ ‣ ΫϥΠΞϯτ ‣ αʔόʔ
HTTP/1.1 HTTP/2
)551썺썽쎁쎂 •ετϦʔϜ ‣ ΫϥΠΞϯτ ‣ αʔόʔ ‣ ΫϥΠΞϯτ ‣ αʔόʔ
HTTP/1.1 HTTP/2
)551썺썽쎁쎂 •ετϦʔϜ ‣ ΫϥΠΞϯτ ‣ αʔόʔ ‣ ΫϥΠΞϯτ ‣ αʔόʔ
‣ 1ͭͷTCPͷίωΫγϣϯͷதͰॱ൪ͪΛ͢Δ͜ͱͳ͘ɺฒྻʹॲཧ HTTP/1.1 HTTP/2 ฒྻʹॲཧ
)551썺썽쎁쎂 •ετϦʔϜ ‣ ΫϥΠΞϯτ ‣ αʔόʔ ‣ ΫϥΠΞϯτ ‣ αʔόʔ
HTTP/1.1 HTTP/2 ฒྻʹॲཧ ‣ 1ͭͷTCPͷίωΫγϣϯͷதͰॱ൪ͪΛ͢Δ͜ͱͳ͘ɺฒྻʹॲཧ
)551쎂ରԠ썮썶"4(*8FC4FSWFS •ASGI Web ServerͷҰཡ Daphne Mangum IUUQTHJUIVCDPNqPSJNPOENBODBBXFTPNFBTHJ
)551쎂ରԠ썮썶"4(*8FC4FSWFS •ASGI WebServer ͱ͍͑ Uvicorn •·ͩHTTP/2ະରԠ ʢରԠ༧ఆ͋Γʣ Uvicorn currently supports
HTTP/1.1 and WebSockets. Support for HTTP/2 is planned. UvicornݱࡏɺHTTP/1.1ͱWebSocketsΛαϙʔτ͍ͯ͠·͢ɻ HTTP/2ͷαϙʔτ͕༧ఆ͞Ε͍ͯ·͢ɻ
)551쎂ରԠ썮썶"4(*8FC4FSWFS •ASGI༷ͷରԠঢ়گ Framework HTTP WebSockets Server Push WebSocket HTTP Hypercorn
1 ◦ 2 ◦ 1 ◦ 2 ◦ ◦ ◦ Uvicorn 1 ◦ 2 × 1 ◦ 2 × × × Daphne 1 ◦ 2 ◦ 1 ◦ 2 × × × Mangum 1 ◦ 2 × 1 ◦ 2 × × ×
)551쎂ରԠ썮썶"4(*8FC4FSWFS •ASGI༷ͷରԠঢ়گ Framework HTTP WebSockets Server Push WebSocket HTTP Hypercorn
1 ◦ 2 ◦ 1 ◦ 2 ◦ ◦ ◦ Uvicorn 1 ◦ 2 × 1 ◦ 2 × × × Daphne 1 ◦ 2 ◦ 1 ◦ 2 × × × Mangum 1 ◦ 2 × 1 ◦ 2 × × ×
)551쎂ରԠ썮썶"4(*8FC4FSWFS •ϋΠύʔίʔϯͱಡΈ·͢ •WSGI Web αʔόͷGunicornʹΠϯεύΠΞ͞Ε͍ͯΔ •HTTP / 1ɺHTTP / 2ɺWebSocketʢHTTP
/ 1͓ΑͼHTTP / 2ܦ༝ʣαϙʔτ •worker ͷλΠϓʹ asyncio,uvloop,trio ΛࢦఆՄೳ •worker ΛࢦఆՄೳ
ຊ쏅쏍쏁쏱쏽썾쎅)551쎅썛ಓ •HTTP/2αʔόͱΞϓϦέʔγϣϯͷϦΫΤετɾϨεϙϯεʹண •੩తϑΝΠϧͷ৴ผͰɻΦϒδΣΫτετϨʔδCDNͰ
ຊ쏅쏍쏁쏱쏽썾쎅)551쎅썛ಓ ͷίϯςφ࣌ͷ1ZUIPOΞʔΩςΫνϟσϓϩΠ TIJCVLBXB <1Z$PO+1> IUUQTXXXZPVUVCFDPNXBUDI W0Y3O%-6OP*TUBSU •HTTP/2αʔόͱΞϓϦέʔγϣϯͷϦΫΤετɾϨεϙϯεʹண •੩తϑΝΠϧͷ৴ผͰɻΦϒδΣΫτετϨʔδCDNͰ
)ZQFSDPSOΛྫʹ ετϦʔϜʢଟॏԽʣΛ
)ZQFSDPSO썾쏃쏒쏴썗쏪 •؆୯ͳWebΞϓϦέʔγϣϯΛHypercornͰಈ͔͢ •ϒϥβ͔ΒJavascriptͰΞΫηε •WebΞϓϦέʔγϣϯͷίʔυಉ͡ •HTTP/1.1ͱHTTP/2ͷҧ͍ΛɺΈͯΈ·͠ΐ͏
ڥ •Hypercorn •fastapi 0.61.1 0.11.0 Webαʔό Web Framework ⁶ ⁶
ʢASGIʣ ʢHTTP/2ʣ ʢHTTP/1.1ʣ )ZQFSDPSO썾쏃쏒쏴썗쏪
ڥ •Hypercorn •fastapi 0.61.1 0.11.0 Webαʔό Web Framework ⁶ ⁶
ʢASGIʣ ʢHTTP/2ʣ ʢHTTP/1.1ʣ )ZQFSDPSO썾쏃쏒쏴썗쏪
쎿썗쏚쎿쎮쏓쎅ॲཧ @app.get("/message/{id}") async def get_message(id:str): await asyncio.sleep(3) return {"text": f"spam,
egg, spam and spam!, {id}!"}
쎹쏳쎮쎬쏽쏒쎅ॲཧ requestButton.onclick = async function() { result = []; for
(let i = 0; i < 24; i++) { result.push(fetch(`/message/${i}/`)); } await Promise.all(result); }
)551쎅߹
)551쎅߹
)551쎅߹
)551쎅߹ TFDˎຊ
)551쎅߹ TFDˎຊ TFDˎຊ
)551쎅߹ TFDˎຊ TFDˎຊ TFDˎຊ
)551쎅߹ TFDˎຊ TFDˎຊ TFDˎຊ TFDˎຊ
)551쎅߹ TFDˎຊ TFDˎຊ TFDˎຊ TFDˎຊ τʔλϧTFD
)551쎅߹
)551쎅߹
)551쎅߹ TFDˎຊ
)551쎅߹ TFDˎຊ τʔλϧTFD
)551ͱ)551̍ ੑೳΛൺֱ
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ •࣮ߦڥϩʔΧϧϚγϯ •ࢦඪɺॲཧͷऴྃ·Ͱʹ͔͔ͬͨ࣌ؒʗ1ඵ͋ͨΓʹࡹ͚ΔϦΫΤετ •ੑೳଌఆπʔϧͱͯ͠ɺh2load ίϚϯυΛ༻͢Δ •؆୯ͳWebΞϓϦέʔγϣϯΛHypercornͰಈ͔͢
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ αʔό HTTP/1.1 HTTP/2 •Hypercorn •fastapi 0.61.1 0.11.0 Webαʔό Web
Framework ⁶ ⁶ ʢASGIʣ ʢHTTP/2ʣ ʢHTTP/1.1ʣ
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ αʔό HTTP/1.1 HTTP/2 •Hypercorn •fastapi 0.61.1 0.11.0 Webαʔό Web
Framework ⁶ ⁶ ʢASGIʣ ʢHTTP/2ʣ ʢHTTP/1.1ʣ
ϋʔυΣΞڥ •Macbook Pro •2.6 GHz 6ίΞ Intel Core i7 •ϝϞϦ
16GB )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ •h2load ίϚϯυ Φϓγϣϯ ҙຯ -n ૯ϦΫΤετ -c ΫϥΠΞϯτɻಉ࣌ΞΫηε -p
ϓϩτίϧʢࣗಈผʣ •h2load -c 100 -n 10000 https://127.0.0.1:8000/query
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ҎԼ3ͭ݅ •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100 •ΫϥΠΞϯτಉ࣌ଓ 50, ϦΫΤετ 5000
•ΫϥΠΞϯτಉ࣌ଓ 100, ϦΫΤετ 10000
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ҎԼ3ͭ݅ •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100 •ΫϥΠΞϯτಉ࣌ଓ 50, ϦΫΤετ 5000
•ΫϥΠΞϯτಉ࣌ଓ 100, ϦΫΤετ 10000 ࢦඪ •ॲཧͷऴྃ·Ͱʹ͔͔ͬͨ࣌ؒ •1ඵ͋ͨΓͷॲཧͨ͠ϦΫΤετ
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ҎԼ3ͭ݅ •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100 •ΫϥΠΞϯτಉ࣌ଓ 50, ϦΫΤετ 5000
•ΫϥΠΞϯτಉ࣌ଓ 100, ϦΫΤετ 10000 ࢦඪ •ॲཧͷऴྃ·Ͱʹ͔͔ͬͨ࣌ؒ •1ඵ͋ͨΓͷॲཧͨ͠ϦΫΤετ → ૣ͍ͱྑ͍ → ଟ͍ͱྑ͍
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌ଓ 10,
ϦΫΤετ 100
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌ଓ 10,
ϦΫΤετ 100 ϦΫΤετ [s]
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌ଓ 10,
ϦΫΤετ 100 ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
None
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌ଓ 10,
ϦΫΤετ 100 ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ •ΫϥΠΞϯτಉ࣌ଓ 50, ϦΫΤετ 5000
ऴྃ࣌ؒ [s] ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ •ΫϥΠΞϯτಉ࣌ଓ 100, ϦΫΤετ 10000
ऴྃ࣌ؒ [s] ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
None
)551썺썽쎁쎂 •HTTP/̍.1͔Β16ͷࡀ݄Λܦͯɺ2015ʹRFC •αʔόαΠυϓογϡ •ϔομʔͷѹॖ •ετϦʔϜʢϦΫΤετͷଟॏԽʣ •վળΛతʹ༷ͨ͠
)551썺썽쎁쎂 •HTTP/̍.1͔Β16ͷࡀ݄Λܦͯɺ2015ʹRFC •αʔόαΠυϓογϡ •ϔομʔͷѹॖ •ετϦʔϜʢϦΫΤετͷଟॏԽʣ •վળΛతʹ༷ͨ͠
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ •h2load — help Max concurrent streams to issue per
session. When http/1.1 is used, this specifies the number of HTTP pipelining requests in-flight. ηογϣϯ͝ͱʹൃߦ͢Δ࠷େಉ࣌ετϦʔϜɻ http/1.1 Λ༻͢Δ߹ɺ HTTP ύΠϓϥΠϯϦΫΤετ ͷΛࢦఆ͠·͢ɻ -m, --max-concurrent-streams=<N>
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100, ετϦʔϜ 5
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌ଓ 10,
ϦΫΤετ 100, ετϦʔϜ 5
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌ଓ 10,
ϦΫΤετ 100, ετϦʔϜ 5 ϦΫΤετ [s]
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌ଓ 10,
ϦΫΤετ 100, ετϦʔϜ 5 ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ •ΫϥΠΞϯτಉ࣌ଓ 50, ϦΫΤετ 5000,
ετϦʔϜ 5 ऴྃ࣌ؒ [s] ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ •ΫϥΠΞϯτಉ࣌ଓ 100, ϦΫΤετ 10000,
ετϦʔϜ 5 ऴྃ࣌ؒ [s] ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
)551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ετϦʔϜͳ͠ ετϦʔϜ͋Γ •ΫϥΠΞϯτಉ࣌ଓ 100,
ϦΫΤετ 10000, ετϦʔϜ 5 ετϦʔϜͳ͠ ετϦʔϜ͋Γ ऴྃ࣌ؒ [s] ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
쎕썿쎘 •ϦΫΤετͷଟॏԽ͕͞Ε͍ͯΔͱ͜ΖͰ͋ΕHTTP/2ɺ͍
쎕썿쎘 •WebαΠτͷ1ճͷΞΫηεͰɺෳճαʔόϦΫΤετΛ߹ •ϦΫΤετͷଟॏԽ͕͞Ε͍ͯΔͱ͜ΖͰ͋ΕHTTP/2ɺ͍
쎕썿쎘 → γεςϜࢹμογϡϘʔυ •WebαΠτͷ1ճͷΞΫηεͰɺෳճαʔόϦΫΤετΛ߹ → ϦΞϧλΠϜσʔλ → νϟοτΞϓϦ •ϦΫΤετͷଟॏԽ͕͞Ε͍ͯΔͱ͜ΖͰ͋ΕHTTP/2ɺ͍
쎕썿쎘 → γεςϜࢹμογϡϘʔυ •WebαΠτͷ1ճͷΞΫηεͰɺෳճαʔόϦΫΤετΛ߹ → ϦΞϧλΠϜσʔλ → νϟοτΞϓϦ •طଘͷαΠτͰܧ͗͠ܧ͗͠ʹͳͬͯ͠·͍ͬͯΔ߹ʢΉͳ͘ʣ •ϦΫΤετͷଟॏԽ͕͞Ε͍ͯΔͱ͜ΖͰ͋ΕHTTP/2ɺ͍
쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ
쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ → ͕վળͷՄೳੑ
쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ •ࣗ͝ͷPython Web Application Λ͝ཡʹͳͬͯΈ͍ͯͩ͘͞ɻ •ϒϥβͷσόοΨΛ։͍ͯϦϩʔυ → ͕վળͷՄೳੑ
쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ •ࣗ͝ͷPython Web Application Λ͝ཡʹͳͬͯΈ͍ͯͩ͘͞ɻ •ϒϥβͷσόοΨΛ։͍ͯϦϩʔυ •Protocol=HTTP/1.1ʹͳ͍ͬͯΔʢLBͷଆ͕HTTP/1.1ͷՄೳੑʣ → ͕վળͷՄೳੑ
쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ •Typeʹ fetch xhr ͕ଟ͍ •ࣗ͝ͷPython Web Application
Λ͝ཡʹͳͬͯΈ͍ͯͩ͘͞ɻ •ϒϥβͷσόοΨΛ։͍ͯϦϩʔυ •Protocol=HTTP/1.1ʹͳ͍ͬͯΔʢLBͷଆ͕HTTP/1.1ͷՄೳੑʣ → ͕վળͷՄೳੑ
쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ •Typeʹ fetch xhr ͕ଟ͍ •ࣗ͝ͷPython Web Application
Λ͝ཡʹͳͬͯΈ͍ͯͩ͘͞ɻ •ϒϥβͷσόοΨΛ։͍ͯϦϩʔυ •Protocol=HTTP/1.1ʹͳ͍ͬͯΔʢLBͷଆ͕HTTP/1.1ͷՄೳੑʣ
쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ •HTTP/2ͷWebserver Hypercorn ʹ͢Δ͜ͱͰվળ͕ΈΒΕΔ •Typeʹ fetch xhr ͕ଟ͍
•ࣗ͝ͷPython Web Application Λ͝ཡʹͳͬͯΈ͍ͯͩ͘͞ɻ •ϒϥβͷσόοΨΛ։͍ͯϦϩʔυ •Protocol=HTTP/1.1ʹͳ͍ͬͯΔʢLBͷଆ͕HTTP/1.1ͷՄೳੑʣ → ͕վળͷՄೳੑ
쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ •Typeʹ fetch xhr ͕ଟ͍ •ࣗ͝ͷPython Web Application
Λ͝ཡʹͳͬͯΈ͍ͯͩ͘͞ɻ •ϒϥβͷσόοΨΛ։͍ͯϦϩʔυ •Protocol=HTTP/1.1ʹͳ͍ͬͯΔʢLBͷଆ͕HTTP/1.1ͷՄೳੑʣ ͔͠Ε·ͤΜ •HTTP/2ͷWebserver Hypercorn ʹ͢Δ͜ͱͰվળ͕ΈΒΕΔ → ͕վળͷՄೳੑ
썡쎕써 •AWSͰσϓϩΠ͍ͯ͠Δ߹ •ALB ʹ ଆHTTP/2 ະରԠͷͨΊɺHTTP/̍.1 ϒϥβ ALB Web Server
Web FW )551 )551 84(*"4(*
썡쎕써 •AWSͰσϓϩΠ͍ͯ͠Δ߹ •ALB ʹ ଆHTTP/2 ະରԠͷͨΊɺHTTP/̍.1 •NLB ʹ 20206݄ʹଆHTTP/2ରԠ͍ͯ͠Δ ϒϥβ
Ϧόʔε ϓϩΩγ Hyper corn Web FW )551 )551 "4(* IUUQTBXTBNB[PODPNKQBCPVUBXTXIBUTOFXOFUXPSLMPBECBMBODFSOPXTVQQPSUTUMTBMQOQPMJDJFT
썡쎕써̎ •WSGIΞϓϦέʔγϣϯͷ߹ •HypercornʢASGI WebαʔόWSGIରԠ͍ͯ͠·͢ʣͰσϓϩΠՄೳ •ࢼͯ͠ΈΔՁ͕͋Δ͔ʂʁ •Django 2ܥ - wsgi.pyΛϥοϓ͢Δ͚ͩ from
hypercorn.middleware import AsyncioWSGIMiddleware import sampleproject.wsgi as wsgi_app asyncio_app = AsyncioWSGIMiddleware(wsgi_app.application) https://github.com/jrfk/django2-hypercorn
쏑쏡쏷쎮쎅બࢶ썿썮썽 •GunicornˎWSGIϑϨʔϜϫʔΫ •GunicornˎWSGIϑϨʔϜϫʔΫˎmeinheld •seroryˎGunicornˎWSGIϑϨʔϜϫʔΫ •UvicornˎASGIϑϨʔϜϫʔΫ
쏑쏡쏷쎮쎅બࢶ썿썮썽 •GunicornˎWSGIϑϨʔϜϫʔΫ •GunicornˎWSGIϑϨʔϜϫʔΫˎmeinheld •seroryˎGunicornˎWSGIϑϨʔϜϫʔΫ •UvicornˎASGIϑϨʔϜϫʔΫ •HypercornˎASGIϑϨʔϜϫʔΫ/WSGIϑϨʔϜϫʔΫ
쏑쏡쏷쎮쎅બࢶ썿썮썽 •GunicornˎWSGIϑϨʔϜϫʔΫ •GunicornˎWSGIϑϨʔϜϫʔΫˎmeinheld •seroryˎGunicornˎWSGIϑϨʔϜϫʔΫ •UvicornˎASGIϑϨʔϜϫʔΫ •HypercornˎASGIϑϨʔϜϫʔΫ/WSGIϑϨʔϜϫʔΫ
ࢀߟࢿྉ •How to serve HTTP/2 using Python IUUQTNFEJVNDPNQZUIPOQBOEFNPOJVNIPXUPTFSWFIUUQVTJOHQZUIPOFCCEF⒎ •HTTP/1 should
die IUUQTNFEJVNDPN!QHKPOFTIUUQTIPVMEEJFCEF •Hypercorn IUUQTQHKPOFTHJUMBCJPIZQFSDPSOJOEFYIUNM •jrfk / fastapi-hypercorn_Performance-measurement IUUQTHJUIVCDPNKSGLGBTUBQJIZQFSDPSO@1FSGPSNBODFNFBTVSFNFOU