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

HTTP2とASGI Webサーバの関係 - Hypercornを例に

D3be793aaf76ed1915295001712ce0f1?s=47 jrfk
October 10, 2020

HTTP2とASGI Webサーバの関係 - Hypercornを例に

PyCon mini Hiroshima 2020 登壇資料

D3be793aaf76ed1915295001712ce0f1?s=128

jrfk

October 10, 2020
Tweet

Transcript

  1. )551ͱ"4(*8FCαʔόͷؔ܎ )ZQFSDPSOΛྫʹ Junya Fukuda PyCon mini Hiroshima 2020

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

  3. ຊ쏅쏍쏁쏱쏽쎅ྲྀ쎣 •ASGIͬͯͳʹʁ •HTTP/2ͬͯͳʹʁ •Hypercorn×FastAPIͰετϦʔϜ •Hypercorn×FastAPIΛ࢖ͬͨHTTP/1.1 HTTP/2ੑೳଌఆ

  4. 1ZUIPO8FCͰ )551Λҙࣝͨ͜͠ͱ ͋Γ·͔͢ʁ

  5. 쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •HTTP/2Λҙࣝͨ͜͠ͱ͸͋·Γͳ͍ •σϓϩΠ؀ڥʹ͸ϦόʔεϓϩΩγ͍Δ͠ɺHTTP/2ؾʹ͢Δͷ͸ͦ͘͜Β͍

  6. 쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •HTTP/2Λҙࣝͨ͜͠ͱ͸͋·Γͳ͍ •σϓϩΠ؀ڥʹ͸ϦόʔεϓϩΩγ͍Δ͠ɺHTTP/2ؾʹ͢Δͷ͸ͦ͘͜Β͍ •ϩʔυόϥϯαʔ ͷ಺ଆ͸HTTP/1.1Ͱे෼

  7. 쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •HTTP/2Λҙࣝͨ͜͠ͱ͸͋·Γͳ͍ •σϓϩΠ؀ڥʹ͸ϦόʔεϓϩΩγ͍Δ͠ɺHTTP/2ؾʹ͢Δͷ͸ͦ͘͜Β͍ •ϩʔυόϥϯαʔ ͷ಺ଆ͸HTTP/1.1Ͱे෼ •ʢPure Python ͷWebαʔόͳΜͯʣ

  8. 쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •HTTP/2Λҙࣝͨ͜͠ͱ͸͋·Γͳ͍ •σϓϩΠ؀ڥʹ͸ϦόʔεϓϩΩγ͍Δ͠ɺHTTP/2ؾʹ͢Δͷ͸ͦ͘͜Β͍ •ϩʔυόϥϯαʔ ͷ಺ଆ͸HTTP/1.1Ͱे෼ •ͦΜͳͳ͔ɺASGIͱHypercornͱग़ձͬͨ •Python WebͰHTTP/2ʹ͢Δͱͳʹ͕͓͍͍͠ͷʁ •ʢPure Python

    ͷWebαʔόͳΜͯʣ
  9. 쏬쏋쏣썗쏁쏱쏽썿쎾썗쏵 •HTTP/2Λҙࣝͨ͜͠ͱ͸͋·Γͳ͍ •σϓϩΠ؀ڥʹ͸ϦόʔεϓϩΩγ͍Δ͠ɺHTTP/2ؾʹ͢Δͷ͸ͦ͘͜Β͍ •ϩʔυόϥϯαʔ ͷ಺ଆ͸HTTP/1.1Ͱे෼ •ͦΜͳͳ͔ɺASGIͱHypercornͱग़ձͬͨ •Python WebͰHTTP/2ʹ͢Δͱͳʹ͕͓͍͍͠ͷʁ •ʢPure Python

    ͷWebαʔόͳΜͯʣ •HTTP/3 RFC໨લɻ࠷ޙʂʁͷHTTP/2ωλ
  10. "4(*ͬͯͳʹʁ

  11. "4(*썺썽쎁쎂 •Asynchronous Server Gateway Interface ͷུ •WSGIͷޙܧ •WebαʔόͱΞϓϦέʔγϣϯͷΠϯλʔϑΣʔεͷ࢓༷

  12. "4(*썺썽쎁쎂 •Asynchronous Server Gateway Interface ͷུ •Webαʔό͕ΞϓϦέʔγϣϯͷ async/await ʹରԠ •WSGIͷޙܧ

    •WebαʔόͱΞϓϦέʔγϣϯͷΠϯλʔϑΣʔεͷ࢓༷
  13. "4(*썺썽쎁쎂 •Asynchronous Server Gateway Interface ͷུ •Webαʔό͕ΞϓϦέʔγϣϯͷ async/await ʹରԠ •WSGIͷޙܧ

    •WebαʔόͱΞϓϦέʔγϣϯͷΠϯλʔϑΣʔεͷ࢓༷ https://www.youtube.com/watch?v=EwG5EWKu8nw ASGIʢඇಉظαʔόήʔτ΢ΣΠΠϯλʔϑΣʔεʣͷ֓ཁ (Junya Fukuda) [PyCon JP 2020]
  14. "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ʯ
  15. "4(*썺썽쎁쎂 •୅දతͳASGIؔ࿈ͷαʔόͱϑϨʔϜϫʔΫ

  16. )551ͬͯͳʹʁ

  17. )551썺썽쎁쎂 •HTTP/̍.1͔Β16೥ͷࡀ݄Λܦͯɺ2015೥ʹRFC •଎౓վળΛ໨తͱͨ͠࢓༷

  18. )551썺썽쎁쎂 •HTTP/̍.1͔Β16೥ͷࡀ݄Λܦͯɺ2015೥ʹRFC •αʔόαΠυϓογϡ •ϔομʔͷѹॖ •ετϦʔϜʢϦΫΤετͷଟॏԽʣ •଎౓վળΛ໨తͱͨ͠࢓༷

  19. )551썺썽쎁쎂 •HTTP/̍.1͔Β16೥ͷࡀ݄Λܦͯɺ2015೥ʹRFC •αʔόαΠυϓογϡ •ϔομʔͷѹॖ •ετϦʔϜʢϦΫΤετͷଟॏԽʣ •଎౓վળΛ໨తͱͨ͠࢓༷

  20. )551썺썽쎁쎂 •ετϦʔϜ

  21. )551썺썽쎁쎂 •ετϦʔϜ ‣ HTTP/̍.1ͷ໰୊఺Λղܾ͢ΔͨΊͷ࢓༷ •1ͭͷϦΫΤετ͕׬ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍໰୊

  22. )551썺썽쎁쎂 ‣ HTTP/̍.1ͷ໰୊఺Λղܾ͢ΔͨΊͷ࢓༷ •1ͭͷϦΫΤετ͕׬ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍໰୊ ‣ ΫϥΠΞϯτ ‣ αʔόʔ

  23. )551썺썽쎁쎂 ‣ HTTP/̍.1ͷ໰୊఺Λղܾ͢ΔͨΊͷ࢓༷ •1ͭͷϦΫΤετ͕׬ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍໰୊ ‣ ΫϥΠΞϯτ ‣ αʔόʔ

  24. )551썺썽쎁쎂 ‣ HTTP/̍.1ͷ໰୊఺Λղܾ͢ΔͨΊͷ࢓༷ •1ͭͷϦΫΤετ͕׬ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍໰୊ ‣ ΫϥΠΞϯτ ‣ αʔόʔ

  25. )551썺썽쎁쎂 ‣ HTTP/̍.1ͷ໰୊఺Λղܾ͢ΔͨΊͷ࢓༷ •1ͭͷϦΫΤετ͕׬ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍໰୊ ‣ ΫϥΠΞϯτ ‣ αʔόʔ

  26. )551썺썽쎁쎂 ‣ HTTP/̍.1ͷ໰୊఺Λղܾ͢ΔͨΊͷ࢓༷ •1ͭͷϦΫΤετ͕׬ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍໰୊ ‣ ΫϥΠΞϯτ ‣ αʔόʔ

  27. )551썺썽쎁쎂 ‣ HTTP/̍.1ͷ໰୊఺Λղܾ͢ΔͨΊͷ࢓༷ •1ͭͷϦΫΤετ͕׬ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍໰୊ ‣ ΫϥΠΞϯτ ‣ αʔόʔ HTTP/̍.1ͷϦΫΤετ-Ϩεϙ ϯε͸ɺৗʹॱ൪Λอͪಉظత

    ʹߦΘΕΔඞཁ͕͋Δ
  28. )551썺썽쎁쎂 ‣ HTTP/̍.1ͷ໰୊఺Λղܾ͢ΔͨΊͷ࢓༷ •1ͭͷϦΫΤετ͕׬ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍໰୊ ‣ ΫϥΠΞϯτ ‣ αʔόʔ HTTP/̍.1ͷϦΫΤετ-Ϩεϙ ϯε͸ɺৗʹॱ൪Λอͪಉظత

    ʹߦΘΕΔඞཁ͕͋Δ WebγεςϜͰ͸ ը໘දࣔ࣌ʹ80ϦΫΤετ
  29. )551썺썽쎁쎂 ‣ ྫ͑͹օ͞Μ͕࢖͍ͬͯΔGmail

  30. )551썺썽쎁쎂 ‣ HTTP/̍.1ͷ໰୊఺Λղܾ͢ΔͨΊͷ࢓༷ •1ͭͷϦΫΤετ͕׬ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍໰୊ ‣ ΫϥΠΞϯτ ‣ αʔόʔ ‣ TCP

    × 6ຊ
  31. )551썺썽쎁쎂 ‣ HTTP/̍.1ͷ໰୊఺Λղܾ͢ΔͨΊͷ࢓༷ •1ͭͷϦΫΤετ͕׬ྃ͢Δ·Ͱݪଇɺ࣍ͷϦΫΤετΛૹΕͳ͍໰୊ ‣ ΫϥΠΞϯτ ‣ αʔόʔ

  32. )551썺썽쎁쎂 •ετϦʔϜ ‣ ΫϥΠΞϯτ ‣ αʔόʔ ‣ ΫϥΠΞϯτ ‣ αʔόʔ

    HTTP/1.1 HTTP/2
  33. )551썺썽쎁쎂 •ετϦʔϜ ‣ ΫϥΠΞϯτ ‣ αʔόʔ ‣ ΫϥΠΞϯτ ‣ αʔόʔ

    HTTP/1.1 HTTP/2
  34. )551썺썽쎁쎂 •ετϦʔϜ ‣ ΫϥΠΞϯτ ‣ αʔόʔ ‣ ΫϥΠΞϯτ ‣ αʔόʔ

    ‣ 1ͭͷTCPͷίωΫγϣϯͷதͰॱ൪଴ͪΛ͢Δ͜ͱͳ͘ɺฒྻʹॲཧ HTTP/1.1 HTTP/2 ฒྻʹॲཧ
  35. )551썺썽쎁쎂 •ετϦʔϜ ‣ ΫϥΠΞϯτ ‣ αʔόʔ ‣ ΫϥΠΞϯτ ‣ αʔόʔ

    HTTP/1.1 HTTP/2 ฒྻʹॲཧ ‣ 1ͭͷTCPͷίωΫγϣϯͷதͰॱ൪଴ͪΛ͢Δ͜ͱͳ͘ɺฒྻʹॲཧ
  36. )551쎂ରԠ썮썶"4(*8FC4FSWFS •ASGI Web ServerͷҰཡ Daphne Mangum IUUQTHJUIVCDPNqPSJNPOENBODBBXFTPNFBTHJ

  37. )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ͷαϙʔτ͕༧ఆ͞Ε͍ͯ·͢ɻ
  38. )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 × × ×
  39. )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 × × ×
  40. )551쎂ରԠ썮썶"4(*8FC4FSWFS •ϋΠύʔίʔϯͱಡΈ·͢ •WSGI Web αʔόͷGunicornʹΠϯεύΠΞ͞Ε͍ͯΔ •HTTP / 1ɺHTTP / 2ɺWebSocketʢHTTP

    / 1͓ΑͼHTTP / 2ܦ༝ʣαϙʔτ •worker ͷλΠϓʹ asyncio,uvloop,trio ΛࢦఆՄೳ •worker ਺ΛࢦఆՄೳ
  41. ຊ쏅쏍쏁쏱쏽썾쎅)551쎅࢖썛ಓ •HTTP/2αʔόͱΞϓϦέʔγϣϯͷϦΫΤετɾϨεϙϯεʹண໨ •੩తϑΝΠϧͷ഑৴͸ผͰɻΦϒδΣΫτετϨʔδ΍CDNͰ

  42. ຊ쏅쏍쏁쏱쏽썾쎅)551쎅࢖썛ಓ ೥୅ͷίϯςφ࣌୅ͷ1ZUIPOΞʔΩςΫνϟσϓϩΠ TIJCVLBXB <1Z$PO+1> IUUQTXXXZPVUVCFDPNXBUDI W0Y3O%-6OP*TUBSU •HTTP/2αʔόͱΞϓϦέʔγϣϯͷϦΫΤετɾϨεϙϯεʹண໨ •੩తϑΝΠϧͷ഑৴͸ผͰɻΦϒδΣΫτετϨʔδ΍CDNͰ

  43. )ZQFSDPSOΛྫʹ ετϦʔϜʢଟॏԽʣΛ

  44. )ZQFSDPSO썾쏃쏒쏴썗쏪 •؆୯ͳWebΞϓϦέʔγϣϯΛHypercornͰಈ͔͢ •ϒϥ΢β͔ΒJavascriptͰΞΫηε •WebΞϓϦέʔγϣϯͷίʔυ͸ಉ͡ •HTTP/1.1ͱHTTP/2ͷҧ͍ΛɺΈͯΈ·͠ΐ͏

  45. ؀ڥ •Hypercorn •fastapi 0.61.1 0.11.0 Webαʔό Web Framework ⁶ ⁶

    ʢASGIʣ ʢHTTP/2ʣ ʢHTTP/1.1ʣ )ZQFSDPSO썾쏃쏒쏴썗쏪
  46. ؀ڥ •Hypercorn •fastapi 0.61.1 0.11.0 Webαʔό Web Framework ⁶ ⁶

    ʢASGIʣ ʢHTTP/2ʣ ʢHTTP/1.1ʣ )ZQFSDPSO썾쏃쏒쏴썗쏪
  47. 쎿썗쏚쎿쎮쏓쎅ॲཧ @app.get("/message/{id}") async def get_message(id:str): await asyncio.sleep(3) return {"text": f"spam,

    egg, spam and spam!, {id}!"}
  48. 쎹쏳쎮쎬쏽쏒쎅ॲཧ requestButton.onclick = async function() { result = []; for

    (let i = 0; i < 24; i++) { result.push(fetch(`/message/${i}/`)); } await Promise.all(result); }
  49. )551쎅৔߹

  50. )551쎅৔߹

  51. )551쎅৔߹

  52. )551쎅৔߹ TFDˎຊ

  53. )551쎅৔߹ TFDˎຊ TFDˎຊ

  54. )551쎅৔߹ TFDˎຊ TFDˎຊ TFDˎຊ

  55. )551쎅৔߹ TFDˎຊ TFDˎຊ TFDˎຊ TFDˎຊ

  56. )551쎅৔߹ TFDˎຊ TFDˎຊ TFDˎຊ TFDˎຊ τʔλϧTFD

  57. )551쎅৔߹

  58. )551쎅৔߹

  59. )551쎅৔߹ TFDˎຊ

  60. )551쎅৔߹ TFDˎຊ τʔλϧTFD

  61. )551ͱ)551̍ ੑೳΛൺֱ

  62. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ •࣮ߦ؀ڥ͸ϩʔΧϧϚγϯ •ࢦඪ͸ɺॲཧͷऴྃ·Ͱʹ͔͔ͬͨ࣌ؒʗ1ඵ͋ͨΓʹࡹ͚ΔϦΫΤετ਺ •ੑೳଌఆπʔϧͱͯ͠ɺh2load ίϚϯυΛ࢖༻͢Δ •؆୯ͳWebΞϓϦέʔγϣϯΛHypercornͰಈ͔͢

  63. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ αʔό HTTP/1.1 HTTP/2 •Hypercorn •fastapi 0.61.1 0.11.0 Webαʔό Web

    Framework ⁶ ⁶ ʢASGIʣ ʢHTTP/2ʣ ʢHTTP/1.1ʣ
  64. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ αʔό HTTP/1.1 HTTP/2 •Hypercorn •fastapi 0.61.1 0.11.0 Webαʔό Web

    Framework ⁶ ⁶ ʢASGIʣ ʢHTTP/2ʣ ʢHTTP/1.1ʣ
  65. ϋʔυ΢ΣΞ؀ڥ •Macbook Pro •2.6 GHz 6ίΞ Intel Core i7 •ϝϞϦ

    16GB )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ
  66. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ •h2load ίϚϯυ Φϓγϣϯ ҙຯ -n ૯ϦΫΤετ਺ -c ΫϥΠΞϯτ਺ɻಉ࣌ΞΫηε਺ -p

    ϓϩτίϧʢࣗಈ൑ผʣ •h2load -c 100 -n 10000 https://127.0.0.1:8000/query
  67. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ҎԼ3ͭ৚݅ •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100 •ΫϥΠΞϯτಉ࣌઀ଓ 50, ϦΫΤετ਺ 5000

    •ΫϥΠΞϯτಉ࣌઀ଓ 100, ϦΫΤετ਺ 10000
  68. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ҎԼ3ͭ৚݅ •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100 •ΫϥΠΞϯτಉ࣌઀ଓ 50, ϦΫΤετ਺ 5000

    •ΫϥΠΞϯτಉ࣌઀ଓ 100, ϦΫΤετ਺ 10000 ࢦඪ •ॲཧͷऴྃ·Ͱʹ͔͔ͬͨ࣌ؒ •1ඵ͋ͨΓͷॲཧͨ͠ϦΫΤετ਺
  69. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ҎԼ3ͭ৚݅ •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100 •ΫϥΠΞϯτಉ࣌઀ଓ 50, ϦΫΤετ਺ 5000

    •ΫϥΠΞϯτಉ࣌઀ଓ 100, ϦΫΤετ਺ 10000 ࢦඪ •ॲཧͷऴྃ·Ͱʹ͔͔ͬͨ࣌ؒ •1ඵ͋ͨΓͷॲཧͨ͠ϦΫΤετ਺ → ૣ͍ͱྑ͍ → ଟ͍ͱྑ͍
  70. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100

  71. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s]      •ΫϥΠΞϯτಉ࣌઀ଓ 10,

    ϦΫΤετ਺ 100
  72. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s]      •ΫϥΠΞϯτಉ࣌઀ଓ 10,

    ϦΫΤετ਺ 100      ϦΫΤετ [s]
  73. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s]      •ΫϥΠΞϯτಉ࣌઀ଓ 10,

    ϦΫΤετ਺ 100      ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
  74. None
  75. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s]      •ΫϥΠΞϯτಉ࣌઀ଓ 10,

    ϦΫΤετ਺ 100      ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
  76. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ      •ΫϥΠΞϯτಉ࣌઀ଓ 50, ϦΫΤετ਺ 5000

         ऴྃ࣌ؒ [s] ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
  77. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ      •ΫϥΠΞϯτಉ࣌઀ଓ 100, ϦΫΤετ਺ 10000

         ऴྃ࣌ؒ [s] ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
  78. None
  79. )551썺썽쎁쎂 •HTTP/̍.1͔Β16೥ͷࡀ݄Λܦͯɺ2015೥ʹRFC •αʔόαΠυϓογϡ •ϔομʔͷѹॖ •ετϦʔϜʢϦΫΤετͷଟॏԽʣ •଎౓վળΛ໨తʹͨ͠࢓༷

  80. )551썺썽쎁쎂 •HTTP/̍.1͔Β16೥ͷࡀ݄Λܦͯɺ2015೥ʹRFC •αʔόαΠυϓογϡ •ϔομʔͷѹॖ •ετϦʔϜʢϦΫΤετͷଟॏԽʣ •଎౓վળΛ໨తʹͨ͠࢓༷

  81. )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>
  82. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ •ΫϥΠΞϯτಉ࣌઀ଓ 10, ϦΫΤετ਺ 100, ετϦʔϜ 5

  83. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s]      •ΫϥΠΞϯτಉ࣌઀ଓ 10,

    ϦΫΤετ਺ 100, ετϦʔϜ 5
  84. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s]      •ΫϥΠΞϯτಉ࣌઀ଓ 10,

    ϦΫΤετ਺ 100, ετϦʔϜ 5      ϦΫΤετ [s]
  85. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ऴྃ࣌ؒ [s]      •ΫϥΠΞϯτಉ࣌઀ଓ 10,

    ϦΫΤετ਺ 100, ετϦʔϜ 5      ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
  86. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ      •ΫϥΠΞϯτಉ࣌઀ଓ 50, ϦΫΤετ਺ 5000,

    ετϦʔϜ 5      ऴྃ࣌ؒ [s] ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
  87. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ      •ΫϥΠΞϯτಉ࣌઀ଓ 100, ϦΫΤετ਺ 10000,

    ετϦʔϜ 5      ऴྃ࣌ؒ [s] ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
  88. )551)551쏛쏟쎳썗쏨쏽쏃ൺֱ ετϦʔϜͳ͠ ετϦʔϜ͋Γ      •ΫϥΠΞϯτಉ࣌઀ଓ 100,

    ϦΫΤετ਺ 10000, ετϦʔϜ 5 ετϦʔϜͳ͠ ετϦʔϜ͋Γ      ऴྃ࣌ؒ [s] ϦΫΤετ [s] HTTP/1.1 HTTP/2 HTTP/1.1 HTTP/2
  89. 쎕썿쎘 •ϦΫΤετͷଟॏԽ͕͞Ε͍ͯΔͱ͜ΖͰ͋Ε͹HTTP/2͸ɺ͸΍͍

  90. 쎕썿쎘 •WebαΠτ΁ͷ1ճͷΞΫηεͰɺෳ਺ճαʔό΁ϦΫΤετΛ৔߹ •ϦΫΤετͷଟॏԽ͕͞Ε͍ͯΔͱ͜ΖͰ͋Ε͹HTTP/2͸ɺ͸΍͍

  91. 쎕썿쎘 → γεςϜ؂ࢹμογϡϘʔυ •WebαΠτ΁ͷ1ճͷΞΫηεͰɺෳ਺ճαʔό΁ϦΫΤετΛ৔߹ → ϦΞϧλΠϜσʔλ → νϟοτΞϓϦ •ϦΫΤετͷଟॏԽ͕͞Ε͍ͯΔͱ͜ΖͰ͋Ε͹HTTP/2͸ɺ͸΍͍

  92. 쎕썿쎘 → γεςϜ؂ࢹμογϡϘʔυ •WebαΠτ΁ͷ1ճͷΞΫηεͰɺෳ਺ճαʔό΁ϦΫΤετΛ৔߹ → ϦΞϧλΠϜσʔλ → νϟοτΞϓϦ •طଘͷαΠτͰܧ͗଍͠ܧ͗଍͠ʹͳͬͯ͠·͍ͬͯΔ৔߹ʢ΍Ήͳ͘ʣ •ϦΫΤετͷଟॏԽ͕͞Ε͍ͯΔͱ͜ΖͰ͋Ε͹HTTP/2͸ɺ͸΍͍

  93. 쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ

  94. 쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ → ଎౓͕վળͷՄೳੑ

  95. 쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ •ࣗ͝਎ͷPython Web Application Λ͝ཡʹͳͬͯΈ͍ͯͩ͘͞ɻ •ϒϥ΢βͷσόοΨΛ։͍ͯϦϩʔυ → ଎౓͕վળͷՄೳੑ

  96. 쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ •ࣗ͝਎ͷPython Web Application Λ͝ཡʹͳͬͯΈ͍ͯͩ͘͞ɻ •ϒϥ΢βͷσόοΨΛ։͍ͯϦϩʔυ •Protocol=HTTP/1.1ʹͳ͍ͬͯΔʢLBͷ಺ଆ͕HTTP/1.1ͷՄೳੑ΋ʣ → ଎౓͕վળͷՄೳੑ

  97. 쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ •Typeʹ fetch ΍ xhr ͕ଟ͍ •ࣗ͝਎ͷPython Web Application

    Λ͝ཡʹͳͬͯΈ͍ͯͩ͘͞ɻ •ϒϥ΢βͷσόοΨΛ։͍ͯϦϩʔυ •Protocol=HTTP/1.1ʹͳ͍ͬͯΔʢLBͷ಺ଆ͕HTTP/1.1ͷՄೳੑ΋ʣ → ଎౓͕վળͷՄೳੑ
  98. 쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ •Typeʹ fetch ΍ xhr ͕ଟ͍ •ࣗ͝਎ͷPython Web Application

    Λ͝ཡʹͳͬͯΈ͍ͯͩ͘͞ɻ •ϒϥ΢βͷσόοΨΛ։͍ͯϦϩʔυ •Protocol=HTTP/1.1ʹͳ͍ͬͯΔʢLBͷ಺ଆ͕HTTP/1.1ͷՄೳੑ΋ʣ
  99. 쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ •HTTP/2ͷWebserver Hypercorn ʹ͢Δ͜ͱͰ଎౓վળ͕ΈΒΕΔ •Typeʹ fetch ΍ xhr ͕ଟ͍

    •ࣗ͝਎ͷPython Web Application Λ͝ཡʹͳͬͯΈ͍ͯͩ͘͞ɻ •ϒϥ΢βͷσόοΨΛ։͍ͯϦϩʔυ •Protocol=HTTP/1.1ʹͳ͍ͬͯΔʢLBͷ಺ଆ͕HTTP/1.1ͷՄೳੑ΋ʣ → ଎౓͕վળͷՄೳੑ
  100. 쎕썿쎘 •HTTP/2Կ͕͓͍͍͠ͷʁ •Typeʹ fetch ΍ xhr ͕ଟ͍ •ࣗ͝਎ͷPython Web Application

    Λ͝ཡʹͳͬͯΈ͍ͯͩ͘͞ɻ •ϒϥ΢βͷσόοΨΛ։͍ͯϦϩʔυ •Protocol=HTTP/1.1ʹͳ͍ͬͯΔʢLBͷ಺ଆ͕HTTP/1.1ͷՄೳੑ΋ʣ ͔΋͠Ε·ͤΜ •HTTP/2ͷWebserver Hypercorn ʹ͢Δ͜ͱͰ଎౓վળ͕ΈΒΕΔ → ଎౓͕վળͷՄೳੑ
  101. 썡쎕써 •AWSͰσϓϩΠ͍ͯ͠Δ৔߹ •ALB ʹ ಺ଆ͸HTTP/2 ະରԠͷͨΊɺHTTP/̍.1 ϒϥ΢β ALB Web Server

    Web FW )551 )551 84(*"4(*
  102. 썡쎕써 •AWSͰσϓϩΠ͍ͯ͠Δ৔߹ •ALB ʹ ಺ଆ͸HTTP/2 ະରԠͷͨΊɺHTTP/̍.1 •NLB ʹ 2020೥6݄ʹ಺ଆHTTP/2ରԠ͍ͯ͠Δ ϒϥ΢β

    Ϧόʔε ϓϩΩγ Hyper corn Web FW )551 )551 "4(* IUUQTBXTBNB[PODPNKQBCPVUBXTXIBUTOFXOFUXPSLMPBECBMBODFSOPXTVQQPSUTUMTBMQOQPMJDJFT
  103. 썡쎕써̎ •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
  104. 쏑쏡쏷쎮쎅બ୒ࢶ썿썮썽 •GunicornˎWSGIϑϨʔϜϫʔΫ •GunicornˎWSGIϑϨʔϜϫʔΫˎmeinheld •seroryˎGunicornˎWSGIϑϨʔϜϫʔΫ •UvicornˎASGIϑϨʔϜϫʔΫ

  105. 쏑쏡쏷쎮쎅બ୒ࢶ썿썮썽 •GunicornˎWSGIϑϨʔϜϫʔΫ •GunicornˎWSGIϑϨʔϜϫʔΫˎmeinheld •seroryˎGunicornˎWSGIϑϨʔϜϫʔΫ •UvicornˎASGIϑϨʔϜϫʔΫ •HypercornˎASGIϑϨʔϜϫʔΫ/WSGIϑϨʔϜϫʔΫ

  106. 쏑쏡쏷쎮쎅બ୒ࢶ썿썮썽 •GunicornˎWSGIϑϨʔϜϫʔΫ •GunicornˎWSGIϑϨʔϜϫʔΫˎmeinheld •seroryˎGunicornˎWSGIϑϨʔϜϫʔΫ •UvicornˎASGIϑϨʔϜϫʔΫ •HypercornˎASGIϑϨʔϜϫʔΫ/WSGIϑϨʔϜϫʔΫ

  107. ࢀߟࢿྉ •How to serve HTTP/2 using Python IUUQTNFEJVNDPNQZUIPOQBOEFNPOJVNIPXUPTFSWFIUUQVTJOHQZUIPOFCCEF⒎ •HTTP/1 should

    die IUUQTNFEJVNDPN!QHKPOFTIUUQTIPVMEEJFCEF •Hypercorn IUUQTQHKPOFTHJUMBCJPIZQFSDPSOJOEFYIUNM •jrfk / fastapi-hypercorn_Performance-measurement IUUQTHJUIVCDPNKSGLGBTUBQJIZQFSDPSO@1FSGPSNBODFNFBTVSFNFOU