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
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Speed Design
sergeychernyshev
24
610
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Ruby is Unlike a Banana
tanoku
97
11k
KATA
mclloyd
29
14k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Statistics for Hackers
jakevdp
796
220k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
How to train your dragon (web standard)
notwaldorf
88
5.7k
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