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
  2. Yokohama.pmͷ ΄͏͔Βདྷɾɾɾ

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

  4. YAPC::Fukuoka 2017 HAKATA

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

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

  7. ݁ہͳΜ΍ͶΜ

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

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

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

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

  12. kuiperbelt loves Perl

  13. kuiperbelt loves Perl5(like languages) • kuiperbelt͸͋͘·ͰσʔϞϯɻԿͰॻ͔Ε͍ͯΔ͔ҙ ࣝ͢Δ͜ͱ͸ͳ͍ • ΠϯλʔϑΣΠε͸HTTP APIɻcurlͰ΋ͳΜͰ΋ୟ͚Δ

    ͠ड͚ΒΕΔɻυΩϡϝϯτͰ͸netcatΛ࢖͍ͬͯΔ • Perl5੡WebAppͷऑ఺Λิ͏ͨΊʹੜ·Εͨͷ͕ kuiperbelt
  14. Perl5੡WebAppͷऑ఺ͱ͸ʁ kuiperbeltͷੜ·ΕͨॠؒΛͨͲΔ

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

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

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

    શ͕ͯίʔϧόοΫܗࣜͰॻ͘Α͏ʹͳΔ
  18. Q: ԿނAnyEvent͕ඞཁ͔ʁ ↓
 A: Ұͭͷϓϩηε͕ෳ਺ͷ઀ ଓΛ࣋ͯͳ͍ͱ΍ͬͯΒΕͳ ͍(C10k Problem)

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

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

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

  22. 2014-06-21

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

  24. 2015-10-21
 WebSocketͰશ໘తʹॻ͖௚͢

  25. 2015-10-21
 WebSocketͰશ໘తʹॻ͖௚͢ ࣮͸Perlͷίʔυ͕͋Γ·͢

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

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

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

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

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

    ͍͢࢓૊Έ
  31. ࢥ૝2 -> Կ͔ʹґଘ͠ͳ͍

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

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

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

    -> ܨ͕ͬͨ࣌ʹWebAppଆʹ఻͑Δ
  35. ӬଓతίωΫγϣϯΛΞϓϦΛ ෼཭͢ΔࣄʹΑΔԸܙ • ΞϓϦ͕ӬଓతίωΫγϣϯΛ࣋ͭͱߋ৽࣌ͳͲͰίωΫγϣ ϯ͕੾ΕΔ • ࠶઀ଓͰҰؾʹෛՙ͕͔͔ͬͨΓετϨε͕ཷ·ͬͨΓ͢ Δ • ͋·ΓϩδοΫΛ࣋ͨͣߋ৽Λ͢Δඞཁ͕ͳ͍αʔό͕ίωΫ

    γϣϯΛ࣋ͭ͜ͱͰΞϓϦߋ৽࣌ʹ੾அ͕ى͜Βͳ͘ͳΔ • ͱ͍͏Θ͚ͰGoͷϓϩδΣΫτͰ΋࠾༻͞ΕΔΑ͏ʹͳΓ ·ͨ͠
  36. ૝૾͠΍͍͢࢓૊Έ ґଘΛۃྗͳ͘͢͜ͱͰ ࢖ΘΕ΍͘͢͢Δ

  37. ͦΜͳ͜ΜͳͰ

  38. ·ͱΊ • kuiperbeltͱ͍͏WebSocketΛҡ࣋ͯ͘͠ΕΔσʔϞϯΛ ॻ͍͍ͯ·͢ • kuiperbelt͸Perl5 loveͰ͢ɻผʹޙΖ͸ͳΜͰ΋͍͍͚Ε Ͳ࡞ऀతʹ͸Perl5ͷͨΊʹॻ͔Ε͍ͯ·͢ • Ұ෦͚ͩ೉͍͠ͱ͜ΖΛ੾Γग़͢ͷΧοίΠΠ

    • ࢖ͬͯײ૝Λฉ͔ͤͯ͘Εʂʂɹ೔ຊޠυΩϡϝϯτ΋ॻ ͍ͨͧʂʂʂɹཔΉʂʂʂʂʂ