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

SwooleでLaravelを高速化してみる

 SwooleでLaravelを高速化してみる

Swoole使うと早くなるよっていう話とLaravel遅いなぁっていう話がステレオで聞こえてくる今日このごろ。
ならばSwoole使ってLaravel早くすればいいじゃない!って思って、検証をしてみました。
確かに早くなったはいいのですが、それによって何が犠牲になっていったのか、果たして実用に向くのか、という内容で話した資料です。

NIIKURA Ryota

April 01, 2019
Tweet

More Decks by NIIKURA Ryota

Other Decks in Technology

Transcript

  1. -BSBWFMΛ4XPPMFͰ
    ߴ଎Խͯ͠ΈΔ
    1)1FS,BJHJ
    ࿅അཱ۠۠ຽɾ࢈ۀϓϥβ$PDPOFSJϗʔϧ
    4$065&3৽૔ྋଠ

    View full-size slide

  2. ϫλγ
    w UXJUUFS!OJJTBOUPLZP
    w ݩ޻ࣄ԰
    w ΤϯδχΞྺ1)1FSྺZFBST
    w 8γεςϜΛ։ൃ͢Δ͓࢓ࣄ
    w ίϯςφ։ൃͨ͠Βӡ༻·Ͱ͍ͨ͠ਓ
    w ήʔϜ͕ͦΕͳΓʹ޷͖ͳਓ
    w ͨ·ʹ-5ͱ͔Ͱ஻Δਓ
    w ࠓ͸4$065&3ʹ͍·͢
    ஻͖ͬͯͨྫ
    1)1ΧϯϑΝϨϯεؔ੢
    1)1ΧϯϑΝϨϯεؔ੢
    1)1ΧϯϑΝϨϯεוా
    1Z$PO

    View full-size slide

  3. ࠓ͸4$065&3
    8FBSFIJSJOH

    View full-size slide

  4. ͍ͱ͕͜ຊग़͠·ͨ͠

    View full-size slide

  5. ΏΔ΅ ׂͱ੾࣮

    w͓͢͢Ίͷ-JOVYϚγϯ͕͋ͬͨΒڭ͑ͯʂʂ
    w 04ͳ͠ͰΠν͔ΒೖΕΔͷͰ΋͋Γ
    w ͓͢͢ΊͷσΟετϦϏϡʔγϣϯ΋߹Θͤͯʂ
    w ϝϞϦ͸(#͋Ε͹े෼ͳؾ͕͢Δ

    View full-size slide

  6. ͓඼ॻ͖
    w 4XPPMF
    w -BSBWFMʹ4XPPMFΛೖΕͯΈΔ
    w ಈ࡞ɾੑೳݕূ
    w ߟ࡯ͱ·ͱΊ

    View full-size slide

  7. িܸͷهࣄ
    ͨͩͰ͑͞଎͍ͱධ൑ͷ#&"34VOEBZ͕4XPPMFͱ૊Έ߹
    ΘͤΔ͜ͱʹΑͬͯɺ଎౓͕ഒʹͳΔͱ͍͏িܸ

    View full-size slide

  8. ͦ͏͍͑͹ɺੲɾɾɾ
    w ͓ͦΒ͘ΤΫεςϯγϣϯͰ͋ΔͳͲͷ
    ཧ༝ʹΑΓলུ͍ͯ͠Δ

    w ਅ໘໨ʹௐ΂͓͚ͯ͹Α͔ͬͨɻɻɻ

    View full-size slide

  9. 4XPPMF
    w 1)1ʹΠϕϯτࣜͷඇಉظॲཧ΍ίϧʔνϯΛಋೖͯ͘͠
    ΕΔΤΫεςϯγϣϯ
    w ΋ͪΖΜɺΠϕϯτϧʔϓܗࣜͷ8FCαʔόΛͨͯΔ͜ͱ
    ΋Ͱ͖Δ
    w த՚ύϫʔʹΑͬͯ࡞ΒΕ͍ͯΔ

    View full-size slide

  10. ҆૷
    QFDM
    ιʔείʔυϏϧυ

    View full-size slide

  11. 4XPPMFXFCTFSWFS

    View full-size slide

  12. 4XPPMFXFCTFSWFS
    IUUQMPDBMIPTU
    ಠཱͨ͠8FC4FSWFSΛͨͯΔ͜ͱ͕Ͱ͖Δ

    View full-size slide

  13. Πϕϯτϧʔϓ
    ͜ͷΠϕϯτΩϡʔʹͨ·ΔΠϕϯτ͕ʮϦΫΤετʯͰɺ
    ίʔϧόοΫͰʮϨεϙϯεʯΛฦ͢ܗͰ8FCαʔόΛ࣮ݱ͢Δ

    View full-size slide

  14. 4XPPMFXFCTFSWFS
    w ಠཱͨ͠8FC4FSWFSʹͳΔ
    w Πϕϯτϧʔϓࣜͷ8FC4FSWFSͱͳ͍ͬͯͯɺॲཧΛ࣮
    ߦ͢ΔϫʔΧʔͷϓϩηε͕֤ϦΫΤετʹରͯ͠࢖͍ճ
    ͞ΕΔ
    w ιʔείʔυͷಡΈࠐΈ΍ύʔε͕͸͡ΊͷಡΈࠐΈҰճ
    ͰࡁΉͷͰɺߴ଎Ͱͷಈ࡞͕ظ଴͞ΕΔ

    View full-size slide

  15. -BSBWFMPO4XPPMF

    View full-size slide

  16. -BSBWFM
    w 1)1ͷ8FCϑϨʔϜϫʔΫͷҰͭ
    w ௚ײతͰ࢖͍΍͍͢03.
    ʮ&MPRVFOUʯ಺ଂ
    w ̏͜͜೥ͣͬͱ࢖ͬͯΔ

    View full-size slide

  17. -BSBWFM஗͍఻આ
    IUUQXXXQIQCFODINBSLTDPNFO
    w -BSBWFMͷείΞ͸ϒʔϏʔ৆
    w τοϓʹରͯ̏͠ഒڧ΋ࠩΛͭ
    ͚ΒΕ͍ͯΔ
    w ͱ͜ΖͰ6CJRVJUZͬͯͳʹʁ

    View full-size slide

  18. 4XPPMF࢖ͬͨΒૣ͘ͳΔʁ
    w #&"34VOEBZ͸̒ഒ΋ૣ͘ͳͬͨͱ͍͏͜ͱͰɺ
    -BSBWFM΋ૣ͘ͳΒͳ͍ͩΖ͏͔
    w 4XPPMFͷ8FC4FSWFS͸ΠϕϯτϧʔϓࣜͰɺৗʹ࣮ߦ
    ঢ়ଶͳͷͰɺҰճಡΈࠐΜͩϑΝΠϧ͸ೋ౓ಡΈࠐΉඞཁ
    ͕ͳ͘ͳΔ
    w ಡΈࠐΈϑΝΠϧ਺ͷଟ͍ ݸ͘Β͍
    -BSBWFMͰ͋Ε
    ͹ɺιʔεͷಡΈࠐΈ΍ύʔεͷলུʹΑΔߴ଎ԽͷޮՌ
    ͕ΑΓظ଴Ͱ͖ͦ͏ʹݟ͑Δ

    View full-size slide

  19. -BSBWFMΛ4XPPMF
    Ͱಈ͔ͯ͠ΈΔ
    w ࣮૷ͱͯ͠͸ɺ4XPPMFͷαʔόΛ্ཱͪ͛ͯɺॲཧΛ
    -BSBWFMʹ΍ΒͤΔͱ͍͏ܗΛͱΔ
    w -BSBWFMΛ4XPPMF্Ͱಈ͔ͨ͢ΊͷϥΠϒϥϦ͕͍͔ͭ͘
    ͋ͬͯɺࠓճ͸A-BSBWFM4Aͱ͍͏ͷΛ࢖͏

    View full-size slide

  20. -BSBWFMPO4XPPMF
    -BSBWFM4ͷΠϯετʔϧ
    -BSBWFM4ͷύϒϦογϡ
    IUUQTHJUIVCDPNIIYTWMBSBWFMT

    View full-size slide

  21. -BSBWFMPO4XPPMF
    -BSBWFM4ͷىಈ

    View full-size slide

  22. ݕূͷํ๏
    w ݕূαʔό͸.BDCPPL1SP্ͷ%PDLFSʹίϯςφΛཱ
    ͯͯ࡞Δ DQV (#NFNPSZ

    BQBDIF /HJOYQIQGQN TXPPMFΛ༻ҙ
    w ෛՙΛ͔͚Δαʔό͸84-্ʹBCΛΠϯετʔϧͯ͠
    ࢖༻ ͍Ζ͍Ζένͬͨ݁Ռ

    w ຊ౰͸Ϋϥ΢υͰ΍Γ͔͕ͨͬͨɺෛՙݕূ༻͸ͩΊͬ
    ͍ͯ͏ͷͰɻɻɻ

    View full-size slide

  23. ୯७ͳJOEFYͷදࣔ
    IUUQMPDBMIPTU

    View full-size slide

  24. JOEFYੑೳൺֱ
    BCUDIUUQ

    View full-size slide

  25. JOEFYੑೳൺֱ·ͱΊ
    w ಉ࣌ϦΫΤετͱ͍͏ɺׂͱେ͖ΊͷෛՙΛ͔͚ͨ
    w ඵؒ͋ͨΓͷϦΫΤετ਺Ͱɺ4XPPMF͸/HJOY1)1
    '1.ͷഒ΋͋Δ
    w ͕͢͞ʹBQBDIF͕͓ͦ͗͢ΔΑ͏ʹݟ͑Δ͕ݪҼෆ໌

    View full-size slide

  26. ૣ͘ͳͬͨʂ

    View full-size slide

  27. Α͘ߟ͑ͯΈΔ
    w JOEFYදࣔ͢Δ͚ͩͷγεςϜ࡞Δ͜ͱ͸Ίͬͨʹͳ͍
    w ೝূͱ͔%#ͷૢ࡞ͱ͔
    w ཁ͢Δʹɺ࣮༻Ͱ࢖͑Δ͔Ͳ͏͔͕େࣄͷ͸ͣ

    View full-size slide

  28. ͱΓ͋͑ͣϩάΠϯ࡞Δ
    ˞ݕূͷͨΊʹ࡞ͬͨίʔυͰ͢ͷͰɺ঎༻؀ڥͰ͸ਅࣅ͠ͳ͍Ͱ͍ͩ͘͞

    View full-size slide

  29. ϫʔΧʔͷ਺ΛҰݸʹ͢Δ

    View full-size slide

  30. ϩάΠϯͯ͠ΈΔ

    View full-size slide

  31. ϩάΠϯͷঢ়ଶΛݟΔ

    View full-size slide

  32. ҰମԿ͕ى͍ͬͯ͜Δͷ͔ɻɻɻ
    ;ͨΓͱ΋࣍࿠͘Μʂʂ

    View full-size slide

  33. Կ͕ىͬͨ͜ͷ͔
    w ʮϩάΠϯʯ͢Δͱ"VUIVTFS
    ͕ࢦࣔ͢͠Ϣʔβʔ͕
    ܾఆ͢Δ
    w ௨ৗͰ͋Ε͹ϨεϙϯεΛฦͨ͋͠ͱɺϓϩηε͕ऴྃ͠ɺ
    "VUIͷมߋ΋Ϧηοτ͞ΕΔ͕ɺ4XPPMFͰ͸ϓϩηε
    ͕ੜ͖ଓ͚ΔͷͰɺ"VUIͷঢ়ଶ΋ͦͷ··ʹͳΔ
    w ࣍ͷϦΫΤετʹରͯ͠ɺ"VUIVTFS
    ͷঢ়ଶ͕อ࣋
    ͞Εͨ··ʹͳΔ

    View full-size slide

  34. ܦҢ
    ॳظঢ়ଶ"VUIVTFS
    OVMM
    Ұ࿠͘Μ͕ϩάΠϯ"VUIVTFS
    Ұ࿠͘Μ
    ࣍࿠͘Μ͕ϩάΠϯ"VUIVTFS
    ࣍࿠͘Μ
    ࣍࿠͘Μͷ໊લ͸ʁ"VUIVTFS
    ࣍࿠͘Μ
    Ұ࿠͘Μͷ໊લ͸ʁ"VUIVTFS
    ࣍࿠͘Μ

    View full-size slide

  35. ͜ΕͰղܾʂ
    w ঢ়ଶΛ࣋ͬͨγϯάϧτϯ΍੩తϓϩύςΟΛॲཧޙʹϦηοτ͢Δ

    DMFBOFSΛ༻ҙͯ͠΍Δͷͩ
    w DPOpHMBSBWFMTQIQͰઃఆՄೳ
    w Ϧηοτ͠ͳ͚Ε͹ͳΒͳ͍ঢ়ଶ͕͍ͭ͋͘Δͷ͔

    Θ͔Βͳ͍ͷ͕໰୊͕ͩɻɻɻ

    View full-size slide

  36. TMFFQ
    w ͱΓ͋͑͢ɺϦΫΤετ͞ΕͨΒඵ଴ͭ
    w ௕͍*0Λ૝ఆ͍ͯ͠Δ

    View full-size slide

  37. TMFFQੑೳൺֱ
    BCUDIUUQTMFFQ

    View full-size slide

  38. TMFFQੑೳൺֱ
    w 4XPPMF͕஗͘ͳ͍ͬͯΔʂʁ
    w ΠϕϯτϧʔϓܗࣜͷαʔόͳͷͰɺॲཧ଴͕ͪൃੜͯ͠
    ͍Δͷ͔΋
    w QIQGQN΋ϫʔΧʔͷ਺্͕ݶʹୡͯ͠଴͕ͪൃੜͯ͠
    ͍Δͱߟ͑Δ
    w BQBDIF͸ϓϩηε੍ݶΛಛʹ͍ͯ͠ͳ͍ͷͰɺੑೳʹ໰
    ୊Λٴ΅͞ͳ͔ͬͨͷ͔΋

    View full-size slide

  39. ͳΒ͹ඇಉظॲཧͩ
    w $PTMFFQͰίϧʔνϯͷTMFFQΛݺͿ͜
    ͱ͕Ͱ͖Δ
    w ϫʔΧʔ͕Ұ౓ʹෳ਺ͷϦΫΤετΛड͚
    ࣋ͯΔ
    w ͪͳΈʹɺެࣜͰ͸΍ΔͳͬͯݴΘΕ͍ͯΔ

    View full-size slide

  40. ඇಉظॲཧΛೖΕͨੑೳ
    BCUDIUUQTMFFQBTZOD
    w ඇಉظԽͷޮՌ͸͋Γͦ͏
    BCUDIUUQTMFFQ

    View full-size slide

  41. ೦ͷҝೝূΛݟͯΈΔ
    wඵ଴ػ͔ͯ͠Βࣗ෼ͷ໊લΛग़ྗ͢Δ
    w଴ػத΋ϫʔΧʔ͸ଞͷϦΫΤετΛड͚෇͚Δ

    View full-size slide

  42. ͜͏ͳΓ·͢
    σʔλ͕ࠞͬͨ͟ޙɺ͋ͱ͔Β
    ೖͬͨਓ͸ϩάΞ΢τ͠·͢

    View full-size slide

  43. ͪͳΈʹߴෛՙ
    w ॲཧΛ͍ͯ͠ΔϫʔΧʔ͕ಈ͔ͳ͘ͳ͍ͬͯΔ໛༷
    w ҰͭͷϫʔΧʔ಺ʹ଴ػ͍ͯ͠ΔλεΫ਺͕ଟ͘ͳΔͱ
    ͜ͷࣄ৅͕ى͜Δ໛༷

    View full-size slide

  44. -BSBWFMͷ4XPPMFʹΑΔ
    ߴ଎Խʹ͍ͭͯ
    w είΞΛ্͛Δ͚ͩͷߴ଎ԽͳΒͰ͖Δ
    w -1ͷΑ͏ʹɺ͋·Γঢ়ଶΛ࣋ͨͳ͍Α͏ͳγεςϜͰ͋
    Ε͹ɺߴ଎Խʹར༻ͯ͠΋ྑ͍ͱߟ͑ΒΕΔ
    w ศརͳ੩తϝιου΍γϯάϧτϯΛଟ༻͢Δ-BSBWFM͸
    4XPPMF8FCαʔόͰಈ͔͢ʹ͸ɺঢ়ଶͷϦηοτΛߟ
    ྀ͢Δඞཁ͕͋Γɺ͔ͳΓͷোน͕͋Δ

    View full-size slide

  45. 4XPPMFͷՄೳੑʹ͍ͭͯ
    w ୯७ͳߴ଎ԽͰ͋Ε͹ɺQSFMPBE΍+*5ͳͲɺ1)1ຊମͷ
    ରԠʹΑ࣮ͬͯݱ͞ΕΔՄೳੑ͕͋Δ
    w ͔͠͠ɺ)551ରԠ΍H31$αʔόԽ ༧ఆ
    ͳͲɺ1)1ຊ
    ମ͕ରԠ͠ͳ͍͜ͱʹ΋௅ઓ͍ͯ͠ΔͷͰɺ௥͍ͬͯͯଛ
    ͸ͳ͍
    w ࢖͏ͷͰ͋Ε͹
    ݸਓతʹ͸ඇಉظͰδϣϒΛ౤͛Δͱ͖
    ʹίϧʔνϯͷه๏Λ࢖͏ͷ͕͍͍ͱࢥ͍ͬͯΔ

    View full-size slide

  46. ·ͱΊ
    w ϕϯνϚʔΫʹΑΔͱ-BSBWFM͸ϑϨʔϜϫʔΫͷதͰ͸
    ஗͍Β͍͠
    w -BSBWFMΛ4XPPMFͰಈ͔͢͜ͱͰɺJOEFYͳͲͷ୯७ͳॲ
    ཧͷϖʔδग़ྗ͸ߴ଎Խ͢Δ
    w ੩తϝιου΍γϯάϧτϯΛଟ༻͢Δ-BSBWFMΛ4XPPMF
    Ͱಈ͔͢͜ͱ͸࣮༻తʹ͸೉͕͋Δ

    View full-size slide

  47. ͝ਗ਼ௌ͋Γ͕ͱ͏͟͝
    ͍·͢ʂʂʂ

    View full-size slide