Upgrade to Pro — share decks privately, control downloads, hide ads and more …

最速のASGIサーバを探して

D3be793aaf76ed1915295001712ce0f1?s=47 jrfk
October 17, 2020
11

 最速のASGIサーバを探して

はんなりPython LT
Unagi.py / Python 駿河 LT
の資料です。

D3be793aaf76ed1915295001712ce0f1?s=128

jrfk

October 17, 2020
Tweet

Transcript

  1. ࠷଎ͷ"4(*8FCαʔόΛ ୳ͯ͠ Junya Fukuda はんなりPython Unagi.py / Python駿河

  2. 썡쎕썟썷쎣쎟 •෱ా ൏໵ʢJunya Fukudaʣʢ@JunyaFffʣ •גࣜձࣾ೔ຊγεςϜٕݚʢJSLʣॴଐ ௕໺ݝͷձࣾ •GEEKLAB.NAGANO •࠷ۙϚΠϯΫϥϑτͰখֶੜ޲͚Youtube഑৴࢝ΊΔ •Effective Python

    ୈ̎൛ ΦϯϥΠϯಡॻձ ΍͍ͬͯ·͢ʂ ΪʔΫϥϘ௕໺
  3. ଎͍ͷ͸޷͖Ͱ͔͢ʁ

  4. 쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •Python͸஗͍

  5. 쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •Python͸஗͍ •Θ͔͍ͬͯ·͢ɻɻɻ

  6. 쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •Python͸஗͍ •Θ͔͍ͬͯ·͢ɻɻɻ •Θ͔͍ͬͯ·͢ɻɻɻɻɻ

  7. 쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •Python͸஗͍ •Θ͔͍ͬͯ·͢ɻɻɻ •Θ͔͍ͬͯ·͢ɻɻɻɻɻ •Ͱ΋͍Ζ͍ΖศརͳͷͰ͢ɻɻ

  8. 쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •Python͸஗͍ •Θ͔͍ͬͯ·͢ɻɻɻ •Θ͔͍ͬͯ·͢ɻɻɻɻɻ •Ͱ΋͍Ζ͍ΖศརͳͷͰ͢ɻɻ •ػցֶशͱ͔IoTɺσʔλ෼ੳɺϓϩάϥϛϯάڭҭͰ΋࢖͍΍͍͢͠ɻɻɻ

  9. 쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •Python͸஗͍ •Θ͔͍ͬͯ·͢ɻɻɻ •Θ͔͍ͬͯ·͢ɻɻɻɻɻ •Ͱ΋͍Ζ͍ΖศརͳͷͰ͢ɻɻ •ͪΐͬͱͰ΋଎͍WebαʔόΛ୳͠ʹߦ͜͏ͱࢥ͍·͢ɻ •FWॆ࣮ͯ͠Δ͠ɺػցֶशͱ͔IoTɺσʔλ෼ੳɺGUIͰ΋࢖͍΍͍͢͠ɻɻɻ

  10. ͯ͞ɺԿ͔Λ୳͢ͱ͖ʹ͸ ΋ͪΖΜɺɺ

  11. None
  12. ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ Go΋ૣ͍͚Ͳɺnode΋Pythonͷjapronto΋ΉͬͪΌૣ͍ https://qiita.com/tkngue/items/62101788c0f384a5b12e

  13. ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ Go΋ૣ͍͚Ͳɺnode΋Pythonͷjapronto΋ΉͬͪΌૣ͍ python(japronto) v.s. nodejs v.s. golang Ͱ ൺֱͨ࣌͠ ͜ͷ3ͭ͸

    ͔ͳΓ͍͍উෛΛ͍ͯ͠·͢Ͷɻ https://qiita.com/tkngue/items/62101788c0f384a5b12e
  14. ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ Go΋ૣ͍͚Ͳɺnode΋Pythonͷjapronto΋ΉͬͪΌૣ͍ python(japronto) v.s. nodejs v.s. golang Ͱ ൺֱͨ࣌͠ ͜ͷ3ͭ͸

    ͔ͳΓ͍͍উෛΛ͍ͯ͠·͢Ͷɻ japronto͕͜Μ͚ͩૣ͍ཧ༝͸த਎͸ ΄΅C/C++Ͱ ༷ʑͳ ࠷దԽΛ͔͚͍ͯΔͨΊͰ͢ɻ https://qiita.com/tkngue/items/62101788c0f384a5b12e
  15. ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ Go΋ૣ͍͚Ͳɺnode΋Pythonͷjapronto΋ΉͬͪΌૣ͍ python(japronto) v.s. nodejs v.s. golang Ͱ ൺֱͨ࣌͠ ͜ͷ3ͭ͸

    ͔ͳΓ͍͍উෛΛ͍ͯ͠·͢Ͷɻ japronto͕͜Μ͚ͩૣ͍ཧ༝͸த਎͸ ΄΅C/C++Ͱ ༷ʑͳ ࠷దԽΛ͔͚͍ͯΔͨΊͰ͢ɻ https://qiita.com/tkngue/items/62101788c0f384a5b12e
  16. ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ PythonͷWeb frameworkͷύϑΥʔϚϯεൺֱ (Django, Flask, responder, FastAPI, japronto) https://qiita.com/bee2/items/0ad260ab9835a2087dae

  17. ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ PythonͷWeb frameworkͷύϑΥʔϚϯεൺֱ (Django, Flask, responder, FastAPI, japronto) https://qiita.com/bee2/items/0ad260ab9835a2087dae japronto

    >>> FastAPI > responder >>> Flask ~ Django
  18. ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ PythonͷWeb frameworkͷύϑΥʔϚϯεൺֱ (Django, Flask, responder, FastAPI, japronto) https://qiita.com/bee2/items/0ad260ab9835a2087dae japronto

    >>> FastAPI > responder >>> Flask ~ Django
  19. ஌썺썽쎕썮썶"4(* •ASGI ؾʹͳͬͨΒΈͯΈ͍ͩ͘͞ https://www.youtube.com/watch?v=EwG5EWKu8nw ASGIʢඇಉظαʔόήʔτ΢ΣΠΠϯλʔϑΣʔεʣͷ֓ཁ (Junya Fukuda) [PyCon JP 2020]

  20. ੑೳଌఆͷఆ൪ 5FDI&NQPXFSCFODI.BSLT ΛݟͯΈ·͠ΐ͏

  21. ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ https://www.techempower.com/benchmarks/

  22. ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ https://www.techempower.com/benchmarks/

  23. ݱঢ়쎅1ZUIPO쎅ੑೳଌఆ https://www.techempower.com/benchmarks/

  24. ؙʑ쎅ੑೳଌఆ݁Ռ •Uvicorn͕଎͍Α͏Ͱ͢ •ͨͩASGIରԠͷαʔό͸…Uvicorn͔͠ͷ͍ͬͯ·ͤΜ

  25. )551쎂ରԠ썮썶"4(*8FC4FSWFS •ASGI Web ServerͷҰཡ Daphne Mangum IUUQTHJUIVCDPNqPSJNPOENBODBBXFTPNFBTHJ

  26. 쎟썝쎛썦쏃쏉썗쏒஍఺ •UvicornͱHypercornͷੑೳൺֱ •FW͸΋ͪΖΜɺେਓؾFastAPIͰ

  27. 6WJDPSOͱ)ZQFSDPSOͰ ੑೳΛൺֱ

  28. 6WJDPSOͱ)ZQFSDPSOͰ ੑೳΛൺֱʢΏΔͬͱʣ

  29. •࣮ߦ؀ڥ͸ϩʔΧϧϚγϯ •ࢦඪ͸ɺॲཧͷऴྃ·Ͱʹ͔͔ͬͨ࣌ؒʗ1ඵ͋ͨΓʹࡹ͚ΔϦΫΤετ਺ •ੑೳଌఆπʔϧͱͯ͠ɺab ίϚϯυΛ࢖༻͢Δ •؆୯ͳWebΞϓϦέʔγϣϯΛUvicorn/HypercornͰಈ͔͢ 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ •ϓϩτίϧ͸http/1.1ʢSͳ͠ʣ

  30. αʔό Webαʔό Web Framework ⁶ ⁶ ʢASGIʣ 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ •Uvicorn •Hypercorn

    0.11.0 0.11.8
  31. αʔό •Uvicorn •Hypercorn 0.11.0 0.11.8 Webαʔό Web Framework ⁶ ⁶

    ʢASGIʣ 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
  32. ϋʔυ΢ΣΞ؀ڥ •Macbook Pro •2.6 GHz 6ίΞ Intel Core i7 •ϝϞϦ

    16GB 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
  33. 쎿썗쏚쎿쎮쏓쎅ॲཧ @app.get("/query") async def get_message(): return {"text": f"spam, egg, spam

    and spam!"}
  34. ҎԼ3ͭ৚݅ •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100 •ΫϥΠΞϯτಉ࣌઀ଓ 50, ϦΫΤετ਺ 5000 •ΫϥΠΞϯτಉ࣌઀ଓ

    100, ϦΫΤετ਺ 10000 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
  35. ҎԼ3ͭ৚݅ •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100 •ΫϥΠΞϯτಉ࣌઀ଓ 50, ϦΫΤετ਺ 5000 •ΫϥΠΞϯτಉ࣌઀ଓ

    100, ϦΫΤετ਺ 10000 ࢦඪ •ॲཧͷऴྃ·Ͱʹ͔͔ͬͨ࣌ؒ •1ඵ͋ͨΓͷॲཧͨ͠ϦΫΤετ਺ 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
  36. ҎԼ3ͭ৚݅ •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100 •ΫϥΠΞϯτಉ࣌઀ଓ 50, ϦΫΤετ਺ 5000 •ΫϥΠΞϯτಉ࣌઀ଓ

    100, ϦΫΤετ਺ 10000 ࢦඪ •ॲཧͷऴྃ·Ͱʹ͔͔ͬͨ࣌ؒ •1ඵ͋ͨΓͷॲཧͨ͠ϦΫΤετ਺ → ૣ͍ͱྑ͍ → ଟ͍ͱྑ͍ 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
  37. •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ

  38. ऴྃ࣌ؒ [s]      •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺

    100 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ
  39. ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100    

     ϦΫΤετ [s] 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ     
  40.          

    ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100 ϦΫΤετ [s] Uvicorn Hypercorn 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ Uvicorn Hypercorn
  41.      •ΫϥΠΞϯτಉ࣌઀ଓ 50, ϦΫΤετ਺ 5000 

        ऴྃ࣌ؒ [s] ϦΫΤετ [s] 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ Uvicorn Hypercorn Uvicorn Hypercorn
  42. 6WJDPSO썿)ZQFSDPSO썾ੑೳൺֱ      •ΫϥΠΞϯτಉ࣌઀ଓ 100, ϦΫΤετ਺ 10000

         ऴྃ࣌ؒ [s] ϦΫΤετ [s] Uvicorn Hypercorn Uvicorn Hypercorn
  43. None
  44. None
  45. •Uvicorn ͸ ܰྔ 6WJDPSO쎅ಛ௃

  46. 6WDPSO쎅ಛ௃ •Uvicorn ͸ ܰྔ •Uvicorn ͸ uvloop ͱ͍͏ asyncio ͷߴ଎Խπʔϧ͕ೖ͍ͬͯΔ

  47. 6WDPSO쎅ಛ௃ •Uvicorn ͸ ܰྔ •Uvicorn ͸ uvloop ͱ͍͏ asyncio ͷߴ଎Խπʔϧ͕ೖ͍ͬͯΔ

  48. 6WDPSO쎅ಛ௃ •Uvicorn ͸ ܰྔ •Uvicorn ͸ uvloop ͱ͍͏ asyncio ͷߴ଎Խπʔϧ͕ೖ͍ͬͯΔ

  49. 6WDPSO쎅ಛ௃ •Uvicorn ͸ ܰྔ •Uvicorn ͸ uvloop ͱ͍͏ asyncio ͷߴ଎Խπʔϧ͕ೖ͍ͬͯΔ

    •Hypercorn Ͱ΋ uvloop Λ࢖͏͜ͱ͕Ͱ͖Δʂʂʂ IUUQTQHKPOFTHJUMBCJPIZQFSDPSO
  50. )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
  51. )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
  52. •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡 썾ੑೳൺֱ

  53. ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡 썾ੑೳൺֱ 

       
  54. ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100 ϦΫΤετ [s] 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡

    썾ੑೳൺֱ          
  55.          

    ऴྃ࣌ؒ [s] •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100 ϦΫΤετ [s] Uvicorn Hypercorn Uvicorn Hypercorn 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡 썾ੑೳൺֱ
  56.          

    •ΫϥΠΞϯτಉ࣌઀ଓ 50, ϦΫΤετ਺ 5000 ऴྃ࣌ؒ [s] ϦΫΤετ [s] Uvicorn Hypercorn Uvicorn Hypercorn 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡 썾ੑೳൺֱ
  57.          

    •ΫϥΠΞϯτಉ࣌઀ଓ 100, ϦΫΤετ਺ 10000 ऴྃ࣌ؒ [s] ϦΫΤετ [s] Uvicorn Hypercorn Uvicorn Hypercorn 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡 썾ੑೳൺֱ
  58.          

    •ΫϥΠΞϯτಉ࣌઀ଓ 100, ϦΫΤετ਺ 10000 ऴྃ࣌ؒ [s] ϦΫΤετ [s] 6WJDPSO썿)ZQFSDPSO VWMPPQ썙쎡 썾ੑೳൺֱ Uvicorn Hypercorn Uvicorn Hypercorn Hypercorn - uvloop Hypercorn - uvloop
  59. 쎕썿쎘 •΍ͬͺΓUvicorn͸͸΍͍

  60. 쎕썿쎘 •΍ͬͺΓUvicorn͸͸΍͍ •଎͍ASGI Webαʔό͸UvicornͰྑͦ͞͏

  61. 쎕썿쎘 •΍ͬͺΓUvicorn͸͸΍͍ •଎͍ASGI Webαʔό͸UvicornͰྑͦ͞͏ •Ͱ͸ଞͷ͸͍Βͳ͍….ʁʁ

  62. 쎕썿쎘 •΍ͬͺΓUvicorn͸͸΍͍ •଎͍ASGI Webαʔό͸UvicornͰྑͦ͞͏ •Ͱ͸ଞͷ͸͍Βͳ͍….ʁʁ •Hypercorn͸੝Γͩ͘͞ΜͳWebαʔό

  63. 쎕썿쎘 •΍ͬͺΓUvicorn͸͸΍͍ •଎͍ASGI Webαʔό͸UvicornͰྑͦ͞͏ •Ͱ͸ଞͷ͸͍Βͳ͍….ʁʁ •Hypercorn͸੝Γͩ͘͞ΜͳWebαʔό •PyCon mini Hiroshima Ͱ͠Ό΂ͬͨͷͰڵຯ͕͋Ε͹͝ཡ͍ͩ͘͞ʂ

    IUUQTTQFBLFSEFDLDPNKSGLIUUQUPBTHJXFCTBCBGBMTFHVBOYJIZQFSDPSOXPMJOJ
  64. ࢀߟࢿྉ •Hypercorn IUUQTQHKPOFTHJUMBCJPIZQFSDPSOJOEFYIUNM •jrfk / fastapi-hypercorn_Performance-measurement IUUQTHJUIVCDPNKSGLGBTUBQJIZQFSDPSO@1FSGPSNBODFNFBTVSFNFOU