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
180
Event-Driven asyncio: A Case Study of Trio's API(PyCon US 2024)
jrfk
1
150
EuroPython 2023体験記 - 非英語話者の海外登壇@みんなのPython勉強会#98
jrfk
0
200
Asyncio Evolved: Enhanced Exception Handling with TaskGroup in Python 3.11(PyConTW 2023)
jrfk
0
42
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
480
Python3.11新機能asyncio.TaskGroup()と2022年asyncioの"Hello-ish world"
jrfk
3
3.8k
こわくないasyncio基礎と非同期IO - 動くコードを添えて
jrfk
0
810
Other Decks in Programming
See All in Programming
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
3
1k
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
The rollercoaster of releasing an Android, iOS, and macOS app with Kotlin Multiplatform | droidcon Italy
prof18
0
150
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
120
命名をリントする
chiroruxx
1
390
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
Refactor your code - refactor yourself
xosofox
1
260
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
700
Security_for_introducing_eBPF
kentatada
0
110
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
Full stack testing :: basic to basic
up1
1
930
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
44
13k
Designing for humans not robots
tammielis
250
25k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
For a Future-Friendly Web
brad_frost
175
9.4k
Statistics for Hackers
jakevdp
796
220k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Optimizing for Happiness
mojombo
376
70k
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