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
160
最速の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
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
43
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
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Building Adaptive Systems
keathley
38
2.3k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
What's in a price? How to price your products and services
michaelherold
243
12k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Rails Girls Zürich Keynote
gr2m
94
13k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Faster Mobile Websites
deanohume
305
30k
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