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

The tale of kuiperbelt ...and Perl.

mackee
July 14, 2017

The tale of kuiperbelt ...and Perl.

吉祥寺.pm11

mackee

July 14, 2017
Tweet

More Decks by mackee

Other Decks in Programming

Transcript

  1. The tale of
    kuiperbelt
    …and Perl.
    ٢঵ࣉ.pm11 2017-07-13
    macopy a.k.a @mackee_w

    View full-size slide

  2. Yokohama.pmͷ
    ΄͏͔Βདྷɾɾɾ

    View full-size slide

  3. (๭໘നͳͷͰຊ೔͸ຊ౰ʹ)
    ח૔͔Βདྷ·ͨ͠

    View full-size slide

  4. YAPC::Fukuoka 2017 HAKATA

    View full-size slide

  5. ༧ఆͰ͸όʔδϣϯݻఆͨ͠
    CPANϞδϡʔϧͱͦͷཧ༝
    Έ͍ͨͳ࿩Λ͢Δ༧ఆͰͨ͠
    ͕ফۃతͰ໘ന͘ແͦ͞͏ͳ
    ͷͰkuiperbeltͷ࿩Λ͠·͢

    View full-size slide

  6. kuiperbeltͱ͸
    github.com/mackee/kuiperbelt

    View full-size slide

  7. ݁ہͳΜ΍ͶΜ

    View full-size slide

  8. WebSocketͱHTTP1.1ͷ
    ૬ޓม׵ϓϩΩγαʔό

    View full-size slide

  9. kuiperbeltͷ໾ׂ
    • WebSocketͷίωΫγϣϯͷҡ࣋
    • ΞϓϦέʔγϣϯαʔό͕ӬଓతίωΫγϣ
    ϯΛ࣋ͭ͜ͱͷݞ୅ΘΓΛ͢Δ
    • ӬଓతίωΫγϣϯͷෛՙ෼ࢄ
    • ΑΓݫີʹݴ͑͹ෛՙ෼ࢄͷ࢓૊Έ

    View full-size slide

  10. kuiperbeltͷ࠾༻ྫ
    • ࠓͷͱ͜Ζݴ͑Δ΍͕ͭͳ͍
    • ͔ࣾ͠͠಺Ͱݕ౼ٴͼݕূ͸ਐΜͰ͍Δͱͩ
    ͚ਃ͋͛͠·͢ɻࠓͷͱ͜Ζ࢖͑ͯͦ͏

    View full-size slide

  11. ͱ͜ΖͰkuiperbeltͬͯGoͩΑͶ

    View full-size slide

  12. kuiperbelt loves Perl

    View full-size slide

  13. kuiperbelt loves
    Perl5(like languages)
    • kuiperbelt͸͋͘·ͰσʔϞϯɻԿͰॻ͔Ε͍ͯΔ͔ҙ
    ࣝ͢Δ͜ͱ͸ͳ͍
    • ΠϯλʔϑΣΠε͸HTTP APIɻcurlͰ΋ͳΜͰ΋ୟ͚Δ
    ͠ड͚ΒΕΔɻυΩϡϝϯτͰ͸netcatΛ࢖͍ͬͯΔ
    • Perl5੡WebAppͷऑ఺Λิ͏ͨΊʹੜ·Εͨͷ͕
    kuiperbelt

    View full-size slide

  14. Perl5੡WebAppͷऑ఺ͱ͸ʁ
    kuiperbeltͷੜ·ΕͨॠؒΛͨͲΔ

    View full-size slide

  15. ࡞Ζ͏ͱࢥͬͨ௚લ͸
    ۭલͷAnyEventϚΠϒʔϜ
    • Mishima.pm#01ͰAnyEventͱ͔δϣϒΩϡʔ
    ͷ࿩Ͱ੝Γ্͕Δ
    • Hachioji.pmͰYanchaͱ͍͏νϟοτΞϓϦͷ
    ։ൃ͕ਐΜͰ͍ͨ(AnyEventͰWebSocketΛ
    ड͚Δߏ੒ͩͬͨ)

    View full-size slide

  16. Perl5ͰWebSocketΛड͚Δʹ͸
    • Net::WebSocket, Mojo::WebSocket…
    • ΠϕϯτۦಈϥΠϒϥϦ
    • TwiggyͳͲΛ࢖ͬͯҰͭͷϓϩηεͰෳ਺
    ͷ઀ଓΛ࣋ͯΔ

    View full-size slide

  17. ΠϕϯτۦಈͷσϝϦοτ
    • ϒϩοΩϯάಈ࡞Λߦ͏ॲཧ͕ॻ͚ͳ͍
    • ී௨ʹDBI࢖͏ͱ͔(τϥϯβΫγϣϯͱ͔)
    • ී௨ʹϑΝΠϧIO࢖͏ͱ͔
    • ී௨ʹAPIϦΫΤετ͢Δͱ͔
    • શ͕ͯίʔϧόοΫܗࣜͰॻ͘Α͏ʹͳΔ

    View full-size slide

  18. Q: ԿނAnyEvent͕ඞཁ͔ʁ
    ↓

    A: Ұͭͷϓϩηε͕ෳ਺ͷ઀
    ଓΛ࣋ͯͳ͍ͱ΍ͬͯΒΕͳ
    ͍(C10k Problem)

    View full-size slide

  19. ී௨ͷPreforkϞσϧͳ
    WebAppΛॻ͖ͭͭ
    ͪΐͬ͜ͱ͚ͩWebSocketʹ
    Ͱ͖ͳ͍͔

    View full-size slide

  20. WebSocketͷ઀ଓΛ࣋ͭ෦෼
    ͚ͩʮ୭͔ʯʹ΍ͬͯ΋Β͑
    Ε͹͍͍ͷͰ͸ͳ͍͔ʁ
    ͦͷਓͱ͸HTTPͰ͠Ό΂Ε͹
    ී௨ʹPerlͰϦΞϧλΠϜΞ
    ϓϦ͕ॻ͚Δ

    View full-size slide

  21. ͓खܰʹϚϧνεϨουΛॻ
    ͚Δݴޠͱͯ͠GoΛ࠾༻

    View full-size slide

  22. ͔͜͠͠ͷͱ͖͸WebSocket
    ೉ͦ͠͏ͩͬͨͷͰ
    Server Sent Eventతͳϓϩτ
    ίϧͰ࣮૷

    View full-size slide

  23. 2015-10-21

    WebSocketͰશ໘తʹॻ͖௚͢

    View full-size slide

  24. 2015-10-21

    WebSocketͰશ໘తʹॻ͖௚͢
    ࣮͸Perlͷίʔυ͕͋Γ·͢

    View full-size slide

  25. “sample psgi app”
    • ϑϩʔͳͲΛఆٛͯ͠Έͨ΋ͷͷ࣮ࡍͷΞϓ
    Ϧॻ͍ͯΈͳ͍ͱ͜ΕͰ͍͚Δ͔෼͔ΒΜͳ
    ͱͳͬͨ
    • ୈҰݴޠ͕PerlͳͷͰϖϥΠνPSGIͰνϟο
    τΞϓϦΛॻ͍ͯΈͯػೳ͢Δ͔Λॻ͍ͯΈ
    ͨ

    View full-size slide

  26. ͦͷޙ
    • ࣾ಺Ͱʮ࢖ͬͯ͘ΕʙʯͬͯԿճ͔ϓϨθϯ͢
    Δ
    • ࣮ࡍʹݕ౼͕࢝·ΓಋೖΞϓϦͷϑΟʔυόο
    ΫΛड͚ΔܗͰػೳ௥Ճ
    • strict broadcast
    • application/octet-stream

    View full-size slide

  27. ͦͷޙ
    • fujiwara͞ΜʹϕϯνϚʔΫॻ͍ͯ΋Βͬͯ
    νϡʔχϯάͯ͠΋Β͏
    • ͦΕΛݟͯଞͷϓϩδΣΫτͰಋೖݕ౼͕޿
    ͕Δ

    View full-size slide

  28. ࢥ૝1 -> ౔؅ʹప͢Δ

    View full-size slide

  29. ʮ͍ΒΜ͜ͱ͸͠ͳ͍ʯϝιου
    • ͋͘·Ͱʮ઀ଓ؅ཧʯʮϝοηʔδ഑৴ʯʹప
    ͢Δ
    • ϝοηʔδͷத਎͸ಡ·ͳ͍
    • ೉͍͜͠ͱΛ΍Βͳ͍
    • ͜͏ͳͬͨΒ͜͏ͳΔΈ͍ͨͳͷ͕૝૾͠΍
    ͍͢࢓૊Έ

    View full-size slide

  30. ࢥ૝2 -> Կ͔ʹґଘ͠ͳ͍

    View full-size slide

  31. stretcher͔Βͷֶͼ
    • fujiwara͞ΜͷpullܕσϓϩΠπʔϧstretcher
    ʹ͓͍ͯσϓϩΠΛ఻͑Δ܅ͱtarballΛஔ͘
    ͱ͜Ζ͸࣮͸ͳΜͰ΋ྑ͍
    • Α͘consulͱS3͕࢖ΘΕΔ͕ઐ༻Ͱ͸ͳ͍

    View full-size slide

  32. kuiperbeltͷྫ
    • ෳ਺୆ͷkuiperbeltΛ࢖͏৔߹ɺͲͷ
    kuiperbelt͕ಛఆͷ઀ଓΛ͍࣋ͬͯΔ͔͸઀ଓ
    ͞Εͨ࣌ʹϔομʹIPΞυϨεΛೖΕͯ఻͑ͯ
    ͘Δ
    • Α͘Redisʹ֨ೲ͍ͯ͠Δ͕memcachedͰ
    ΋RDBͰ΋ͳΜͰ΋ྑ͍

    View full-size slide

  33. ୭͕ԿΛ͍࣋ͬͯΔ͔ΛΫϥΠΞ
    ϯτ͕൑அ͢ΔγϟʔσΟϯά
    • ketamaͳͲͷconsistent hashingΛ༻͍ͨ
    memcachedͷsharding͔Βண૝
    • ͔͠͠kuiperbelt͸खલʹLBΛஔ͘લఏͳͷ
    ͰͲ͜ͷkuiperbeltʹͭͳ͛Δ͔Λ੍ޚ͸Ͱ͖
    ͳ͍ -> ܨ͕ͬͨ࣌ʹWebAppଆʹ఻͑Δ

    View full-size slide

  34. ӬଓతίωΫγϣϯΛΞϓϦΛ
    ෼཭͢ΔࣄʹΑΔԸܙ
    • ΞϓϦ͕ӬଓతίωΫγϣϯΛ࣋ͭͱߋ৽࣌ͳͲͰίωΫγϣ
    ϯ͕੾ΕΔ
    • ࠶઀ଓͰҰؾʹෛՙ͕͔͔ͬͨΓετϨε͕ཷ·ͬͨΓ͢
    Δ
    • ͋·ΓϩδοΫΛ࣋ͨͣߋ৽Λ͢Δඞཁ͕ͳ͍αʔό͕ίωΫ
    γϣϯΛ࣋ͭ͜ͱͰΞϓϦߋ৽࣌ʹ੾அ͕ى͜Βͳ͘ͳΔ
    • ͱ͍͏Θ͚ͰGoͷϓϩδΣΫτͰ΋࠾༻͞ΕΔΑ͏ʹͳΓ
    ·ͨ͠

    View full-size slide

  35. ૝૾͠΍͍͢࢓૊Έ
    ґଘΛۃྗͳ͘͢͜ͱͰ
    ࢖ΘΕ΍͘͢͢Δ

    View full-size slide

  36. ͦΜͳ͜ΜͳͰ

    View full-size slide

  37. ·ͱΊ
    • kuiperbeltͱ͍͏WebSocketΛҡ࣋ͯ͘͠ΕΔσʔϞϯΛ
    ॻ͍͍ͯ·͢
    • kuiperbelt͸Perl5 loveͰ͢ɻผʹޙΖ͸ͳΜͰ΋͍͍͚Ε
    Ͳ࡞ऀతʹ͸Perl5ͷͨΊʹॻ͔Ε͍ͯ·͢
    • Ұ෦͚ͩ೉͍͠ͱ͜ΖΛ੾Γग़͢ͷΧοίΠΠ
    • ࢖ͬͯײ૝Λฉ͔ͤͯ͘Εʂʂɹ೔ຊޠυΩϡϝϯτ΋ॻ
    ͍ͨͧʂʂʂɹཔΉʂʂʂʂʂ

    View full-size slide