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
最速のASGIサーバを探して
Search
Junya Fukuda
October 17, 2020
0
150
最速のASGIサーバを探して
はんなりPython LT
Unagi.py / Python 駿河 LT
の資料です。
Junya Fukuda
October 17, 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
Featured
See All Featured
A better future with KSS
kneath
238
17k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Into the Great Unknown - MozCon
thekraken
32
1.5k
What's in a price? How to price your products and services
michaelherold
243
12k
A designer walks into a library…
pauljervisheath
204
24k
We Have a Design System, Now What?
morganepeng
50
7.2k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
For a Future-Friendly Web
brad_frost
175
9.4k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Producing Creativity
orderedlist
PRO
341
39k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Transcript
࠷ͷ"4(*8FCαʔόΛ ୳ͯ͠ Junya Fukuda はんなりPython Unagi.py / Python駿河
썡쎕썟썷쎣쎟 •ా ൏ʢJunya Fukudaʣʢ@JunyaFffʣ •גࣜձࣾຊγεςϜٕݚʢJSLʣॴଐ ݝͷձࣾ •GEEKLAB.NAGANO •࠷ۙϚΠϯΫϥϑτͰখֶੜ͚Youtube৴࢝ΊΔ •Effective Python
ୈ̎൛ ΦϯϥΠϯಡॻձ ͍ͬͯ·͢ʂ ΪʔΫϥϘ
͍ͷ͖Ͱ͔͢ʁ
쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •Python͍
쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •Python͍ •Θ͔͍ͬͯ·͢ɻɻɻ
쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •Python͍ •Θ͔͍ͬͯ·͢ɻɻɻ •Θ͔͍ͬͯ·͢ɻɻɻɻɻ
쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •Python͍ •Θ͔͍ͬͯ·͢ɻɻɻ •Θ͔͍ͬͯ·͢ɻɻɻɻɻ •Ͱ͍Ζ͍ΖศརͳͷͰ͢ɻɻ
쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •Python͍ •Θ͔͍ͬͯ·͢ɻɻɻ •Θ͔͍ͬͯ·͢ɻɻɻɻɻ •Ͱ͍Ζ͍ΖศརͳͷͰ͢ɻɻ •ػցֶशͱ͔IoTɺσʔλੳɺϓϩάϥϛϯάڭҭͰ͍͍͢͠ɻɻɻ
쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •Python͍ •Θ͔͍ͬͯ·͢ɻɻɻ •Θ͔͍ͬͯ·͢ɻɻɻɻɻ •Ͱ͍Ζ͍ΖศརͳͷͰ͢ɻɻ •ͪΐͬͱͰ͍WebαʔόΛ୳͠ʹߦ͜͏ͱࢥ͍·͢ɻ •FWॆ࣮ͯ͠Δ͠ɺػցֶशͱ͔IoTɺσʔλੳɺGUIͰ͍͍͢͠ɻɻɻ
ͯ͞ɺԿ͔Λ୳͢ͱ͖ʹ ͪΖΜɺɺ
None
ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ Goૣ͍͚ͲɺnodePythonͷjaprontoΉͬͪΌૣ͍ https://qiita.com/tkngue/items/62101788c0f384a5b12e
ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ Goૣ͍͚ͲɺnodePythonͷjaprontoΉͬͪΌૣ͍ python(japronto) v.s. nodejs v.s. golang Ͱ ൺֱͨ࣌͠ ͜ͷ3ͭ
͔ͳΓ͍͍উෛΛ͍ͯ͠·͢Ͷɻ https://qiita.com/tkngue/items/62101788c0f384a5b12e
ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ Goૣ͍͚ͲɺnodePythonͷjaprontoΉͬͪΌૣ͍ python(japronto) v.s. nodejs v.s. golang Ͱ ൺֱͨ࣌͠ ͜ͷ3ͭ
͔ͳΓ͍͍উෛΛ͍ͯ͠·͢Ͷɻ japronto͕͜Μ͚ͩૣ͍ཧ༝த ΄΅C/C++Ͱ ༷ʑͳ ࠷దԽΛ͔͚͍ͯΔͨΊͰ͢ɻ https://qiita.com/tkngue/items/62101788c0f384a5b12e
ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ Goૣ͍͚ͲɺnodePythonͷjaprontoΉͬͪΌૣ͍ python(japronto) v.s. nodejs v.s. golang Ͱ ൺֱͨ࣌͠ ͜ͷ3ͭ
͔ͳΓ͍͍উෛΛ͍ͯ͠·͢Ͷɻ japronto͕͜Μ͚ͩૣ͍ཧ༝த ΄΅C/C++Ͱ ༷ʑͳ ࠷దԽΛ͔͚͍ͯΔͨΊͰ͢ɻ https://qiita.com/tkngue/items/62101788c0f384a5b12e
ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ PythonͷWeb frameworkͷύϑΥʔϚϯεൺֱ (Django, Flask, responder, FastAPI, japronto) https://qiita.com/bee2/items/0ad260ab9835a2087dae
ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ PythonͷWeb frameworkͷύϑΥʔϚϯεൺֱ (Django, Flask, responder, FastAPI, japronto) https://qiita.com/bee2/items/0ad260ab9835a2087dae japronto
>>> FastAPI > responder >>> Flask ~ Django
ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ PythonͷWeb frameworkͷύϑΥʔϚϯεൺֱ (Django, Flask, responder, FastAPI, japronto) https://qiita.com/bee2/items/0ad260ab9835a2087dae japronto
>>> FastAPI > responder >>> Flask ~ Django
썺썽쎕썮썶"4(* •ASGI ؾʹͳͬͨΒΈͯΈ͍ͩ͘͞ https://www.youtube.com/watch?v=EwG5EWKu8nw ASGIʢඇಉظαʔόήʔτΣΠΠϯλʔϑΣʔεʣͷ֓ཁ (Junya Fukuda) [PyCon JP 2020]
ੑೳଌఆͷఆ൪ 5FDI&NQPXFSCFODI.BSLT ΛݟͯΈ·͠ΐ͏
ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ https://www.techempower.com/benchmarks/
ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ https://www.techempower.com/benchmarks/
ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ https://www.techempower.com/benchmarks/
ؙʑ쎅ੑೳଌఆ݁Ռ •Uvicorn͕͍Α͏Ͱ͢ •ͨͩASGIରԠͷαʔό…Uvicorn͔͠ͷ͍ͬͯ·ͤΜ
)551쎂ରԠ썮썶"4(*8FC4FSWFS •ASGI Web ServerͷҰཡ Daphne Mangum IUUQTHJUIVCDPNqPSJNPOENBODBBXFTPNFBTHJ
쎟썝쎛썦쏃쏉썗쏒 •UvicornͱHypercornͷੑೳൺֱ •FWͪΖΜɺେਓؾFastAPIͰ
6WJDPSOͱ)ZQFSDPSOͰ ੑೳΛൺֱ
6WJDPSOͱ)ZQFSDPSOͰ ੑೳΛൺֱʢΏΔͬͱʣ
•࣮ߦڥϩʔΧϧϚγϯ •ࢦඪɺॲཧͷऴྃ·Ͱʹ͔͔ͬͨ࣌ؒʗ1ඵ͋ͨΓʹࡹ͚ΔϦΫΤετ •ੑೳଌఆπʔϧͱͯ͠ɺab ίϚϯυΛ༻͢Δ •؆୯ͳWebΞϓϦέʔγϣϯΛUvicorn/HypercornͰಈ͔͢ 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ •ϓϩτίϧhttp/1.1ʢSͳ͠ʣ
αʔό Webαʔό Web Framework ⁶ ⁶ ʢASGIʣ 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ •Uvicorn •Hypercorn
0.11.0 0.11.8
αʔό •Uvicorn •Hypercorn 0.11.0 0.11.8 Webαʔό Web Framework ⁶ ⁶
ʢASGIʣ 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
ϋʔυΣΞڥ •Macbook Pro •2.6 GHz 6ίΞ Intel Core i7 •ϝϞϦ
16GB 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
쎿썗쏚쎿쎮쏓쎅ॲཧ @app.get("/query") async def get_message(): return {"text": f"spam, egg, spam
and spam!"}
ҎԼ3ͭ݅ •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100 •ΫϥΠΞϯτಉ࣌ଓ 50, ϦΫΤετ 5000 •ΫϥΠΞϯτಉ࣌ଓ
100, ϦΫΤετ 10000 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
ҎԼ3ͭ݅ •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100 •ΫϥΠΞϯτಉ࣌ଓ 50, ϦΫΤετ 5000 •ΫϥΠΞϯτಉ࣌ଓ
100, ϦΫΤετ 10000 ࢦඪ •ॲཧͷऴྃ·Ͱʹ͔͔ͬͨ࣌ؒ •1ඵ͋ͨΓͷॲཧͨ͠ϦΫΤετ 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
ҎԼ3ͭ݅ •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100 •ΫϥΠΞϯτಉ࣌ଓ 50, ϦΫΤετ 5000 •ΫϥΠΞϯτಉ࣌ଓ
100, ϦΫΤετ 10000 ࢦඪ •ॲཧͷऴྃ·Ͱʹ͔͔ͬͨ࣌ؒ •1ඵ͋ͨΓͷॲཧͨ͠ϦΫΤετ → ૣ͍ͱྑ͍ → ଟ͍ͱྑ͍ 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
•ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ
100 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100
ϦΫΤετ [s] 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100 ϦΫΤετ [s] Uvicorn Hypercorn 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ Uvicorn Hypercorn
•ΫϥΠΞϯτಉ࣌ଓ 50, ϦΫΤετ 5000
ऴྃ࣌ؒ [s] ϦΫΤετ [s] 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ Uvicorn Hypercorn Uvicorn Hypercorn
6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ •ΫϥΠΞϯτಉ࣌ଓ 100, ϦΫΤετ 10000
ऴྃ࣌ؒ [s] ϦΫΤετ [s] Uvicorn Hypercorn Uvicorn Hypercorn
None
None
•Uvicorn ܰྔ 6WJDPSO쎅ಛ
6WDPSO쎅ಛ •Uvicorn ܰྔ •Uvicorn uvloop ͱ͍͏ asyncio ͷߴԽπʔϧ͕ೖ͍ͬͯΔ
6WDPSO쎅ಛ •Uvicorn ܰྔ •Uvicorn uvloop ͱ͍͏ asyncio ͷߴԽπʔϧ͕ೖ͍ͬͯΔ
6WDPSO쎅ಛ •Uvicorn ܰྔ •Uvicorn uvloop ͱ͍͏ asyncio ͷߴԽπʔϧ͕ೖ͍ͬͯΔ
6WDPSO쎅ಛ •Uvicorn ܰྔ •Uvicorn uvloop ͱ͍͏ asyncio ͷߴԽπʔϧ͕ೖ͍ͬͯΔ
•Hypercorn Ͱ uvloop Λ͏͜ͱ͕Ͱ͖Δʂʂʂ IUUQTQHKPOFTHJUMBCJPIZQFSDPSO
)ZQFSDPSO썾VWMPPQ쎩썝쎂쎆 import asyncio import uvloop from hypercorn.asyncio import serve from
hypercorn.config import Config import main_fastapi as faster config = Config() config.bind = ["localhost:8080"] asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) loop.run_until_complete(serve(faster.app, config)) IUUQTQHKPOFTHJUMBCJPIZQFSDPSOIPX@UP@HVJEFTBQJ@VTBHFIUNM
)ZQFSDPSO썾VWMPPQ쎩썝쎂쎆 import asyncio import uvloop from hypercorn.asyncio import serve from
hypercorn.config import Config import main_fastapi as faster config = Config() config.bind = ["localhost:8080"] asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) loop.run_until_complete(serve(faster.app, config)) IUUQTQHKPOFTHJUMBCJPIZQFSDPSOIPX@UP@HVJEFTBQJ@VTBHFIUNM
•ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡 썾ੑೳൺֱ
ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡 썾ੑೳൺֱ
ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100 ϦΫΤετ [s] 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡
썾ੑೳൺֱ
ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌ଓ 10, ϦΫΤετ 100 ϦΫΤετ [s] Uvicorn Hypercorn Uvicorn Hypercorn 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡 썾ੑೳൺֱ
•ΫϥΠΞϯτಉ࣌ଓ 50, ϦΫΤετ 5000 ऴྃ࣌ؒ [s] ϦΫΤετ [s] Uvicorn Hypercorn Uvicorn Hypercorn 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡 썾ੑೳൺֱ
•ΫϥΠΞϯτಉ࣌ଓ 100, ϦΫΤετ 10000 ऴྃ࣌ؒ [s] ϦΫΤετ [s] Uvicorn Hypercorn Uvicorn Hypercorn 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡 썾ੑೳൺֱ
•ΫϥΠΞϯτಉ࣌ଓ 100, ϦΫΤετ 10000 ऴྃ࣌ؒ [s] ϦΫΤετ [s] 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡 썾ੑೳൺֱ Uvicorn Hypercorn Uvicorn Hypercorn Hypercorn - uvloop Hypercorn - uvloop
쎕썿쎘 •ͬͺΓUvicorn͍
쎕썿쎘 •ͬͺΓUvicorn͍ •͍ASGI WebαʔόUvicornͰྑͦ͞͏
쎕썿쎘 •ͬͺΓUvicorn͍ •͍ASGI WebαʔόUvicornͰྑͦ͞͏ •Ͱଞͷ͍Βͳ͍….ʁʁ
쎕썿쎘 •ͬͺΓUvicorn͍ •͍ASGI WebαʔόUvicornͰྑͦ͞͏ •Ͱଞͷ͍Βͳ͍….ʁʁ •HypercornΓͩ͘͞ΜͳWebαʔό
쎕썿쎘 •ͬͺΓUvicorn͍ •͍ASGI WebαʔόUvicornͰྑͦ͞͏ •Ͱଞͷ͍Βͳ͍….ʁʁ •HypercornΓͩ͘͞ΜͳWebαʔό •PyCon mini Hiroshima Ͱ͠ΌͬͨͷͰڵຯ͕͋Ε͝ཡ͍ͩ͘͞ʂ
IUUQTTQFBLFSEFDLDPNKSGLIUUQUPBTHJXFCTBCBGBMTFHVBOYJIZQFSDPSOXPMJOJ
ࢀߟࢿྉ •Hypercorn IUUQTQHKPOFTHJUMBCJPIZQFSDPSOJOEFYIUNM •jrfk / fastapi-hypercorn_Performance-measurement IUUQTHJUIVCDPNKSGLGBTUBQJIZQFSDPSO@1FSGPSNBODFNFBTVSFNFOU