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
150
Event-Driven asyncio: A Case Study of Trio's API(PyCon US 2024)
jrfk
1
140
EuroPython 2023体験記 - 非英語話者の海外登壇@みんなのPython勉強会#98
jrfk
0
190
Asyncio Evolved: Enhanced Exception Handling with TaskGroup in Python 3.11(PyConTW 2023)
jrfk
0
37
Asyncio Evolved: Enhanced Exception Handling with TaskGroup in Python 3.11(EuroPython 2023)
jrfk
3
1.2k
Django 4.1のAsynchronous
jrfk
1
2.3k
New in Python 3.11: asyncio.TaskGroup and “Hello-ish World” of Asyncio
jrfk
0
480
Python3.11新機能asyncio.TaskGroup()と2022年asyncioの"Hello-ish world"
jrfk
3
3.8k
こわくないasyncio基礎と非同期IO - 動くコードを添えて
jrfk
0
790
Other Decks in Programming
See All in Programming
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
受け取る人から提供する人になるということ
little_rubyist
0
240
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
Better Code Design in PHP
afilina
PRO
0
130
cmp.Or に感動した
otakakot
3
200
Click-free releases & the making of a CLI app
oheyadam
2
120
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Building Adaptive Systems
keathley
38
2.3k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
BBQ
matthewcrist
85
9.3k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
It's Worth the Effort
3n
183
27k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Statistics for Hackers
jakevdp
796
220k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Become a Pro
speakerdeck
PRO
25
5k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
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