ライブ視聴を支えるリアルタイムメッセージ配信基盤の話 / GunosyBeerBash #6

ライブ視聴を支えるリアルタイムメッセージ配信基盤の話 / GunosyBeerBash #6

ライブ視聴を支えるリアルタイムメッセージ配信基盤の話

2016/6/22 Gunosy Beer Bash #6
http://gunosy-beer.connpass.com/event/33614/

382b3308736365eb85f316a531f92252?s=128

Taro Hirose

June 22, 2016
Tweet

Transcript

  1. ϥΠϒࢹௌΛࢧ͑Δ ϦΞϧλΠϜ ϝοηʔδ഑৴ج൫ͷ࿩

  2. ࣗݾ঺հ ኍ੉ ଠ࿠ @ CyberZ ▸ OPENRECࣄۀ෦ ▸ Πϯϑϥ &

    αʔόαΠυΤϯδχΞ ▸ લ৬: ITίϯαϧ / SIer ▸ ಘҙྖҬ: ߏ੒؅ཧ/ࣗಈԽ, ؂ࢹ ▸ Twitter: @uorat ▸ Blog: http://uorat.hatenablog.com/
  3. OPENREC.tv ήʔϜʹಛԽͨ͠ಈը഑৴αʔϏε https://www.openrec.tv/ ϓϨΠಈըͷ౤ߘɺϥΠϒ഑৴ɺήʔϜେձͷϥΠϒதܧ ॴҦe-sportsࢢ৔ 3

  4. OPENREC.tv ഑৴ྫ: Vainglory 4

  5. SHINYA ONUKI ϓϩήʔϚʔܖ໿

  6. ຊ೔ͷ಺༰ ͜ͷ෦෼ 6

  7. νϟοτͷଘࡏҙٛ ۭؒڞ༗ ▸ ؍ઓ࣌ͷྟ৔ײΛΦϯϥΠϯͰମݧ ▸ ྫ: RAGE ▸ ίϛϡχέʔγϣϯखஈ ▸

    ϓϨΠϠʔɿࢹௌऀ ▸ ࢹௌऀɿࢹௌऀ ▸ ྫ: ϚΠϯΫϥϑτ ग़య: http://tappli.org/column-detail.php?id=1166
  8. νϟοτʹٻΊΒΕΔཁ݅ ϦΞϧλΠϜϝοηʔδ഑৴ج൫ ▸ ϦΞϧλΠϜ ▸ ஗Ԇ = e-sportsಛ༗ͷྟ৔ײΛڞ༗Ͱ͖ͳ͍ ▸ ഑৴ऀɿࢹௌऀؒͷର࿩खஈͰ΋͋Δ

    ▸ શࢹௌऀʹରͯ͠Ұ੪ʹϝοηʔδ഑৴͢Δඞཁ͋Γ ▸ ߴ֦ுੑ ▸ ಉ࣌ࢹௌऀ਺͕૿͑ͯ΋εέʔϧΞ΢τͰ͖Δ ▸ ਓؾ഑৴͸਺ສਓҎ্ͷϢʔβ͕ࢹௌ͢Δ ▸ ෳ਺഑৴͋Γɺ഑৴͸໷ʹूத͢Δ ▸ ࢹௌऀ͕਺ेສ, ਺ඦສਓͱ૿͑ͯ΋ϝοηʔδ഑৴ʹࢧো Λ͖ͨ͞ͳ͍͜ͱ
  9. Architecture ΞʔΩςΫνϟ

  10. Point1: ϦΞϧλΠϜ௨৴ WebSocket ▸ ଟ਺ͷΫϥΠΞϯτʹରͯ͠ɺ౤ߘ ͞ΕͨϝοηʔδΛҰ੪഑৴͢Δ ▸ Node.js / Socket.IO

    Λ࠾༻
  11. Point2: ϓϩηεؒͷϝοηʔδ഑৴ Ͳ͏͢Δʁ Pub/Sub

  12. Point2: ϓϩηεؒͷϝοηʔδ഑৴ - Pub/Subͱ͸ ग़൛ - ߪಡܕϞσϧ ▸ ग़൛ऀʢPublisherʣ ▸

    ʮAAA ΫϥεͰ഑৴͠·͢ʯ ▸ ߪಡऀʢSubscriberʣ ▸ ʮAAA ΫϥεΛߪಡ͠·͢ʯ Publisher, Subscriber྆ऀ͸ޓ͍Λҙ ࣝ͠ͳ͍ɻSubscriber͸Ϋϥε͑͞ Θ͔Ε͹ඞཁͳϝοηʔδ͕௨஌͞ ΕΔɻ
  13. Point2: ϓϩηεؒͷϝοηʔδ഑৴ Pub/Sub ෳ਺ͷNode.js αʔόʹରͯ͠ɺ౤ߘ͞Εͨ ϝοηʔδΛҰ੪഑৴͢Δɻ AWS ElasticCache for Redis

    Λ࠾༻ ▸ Subscriber: Node.js ▸ νϟοτۭؒͷSubscribeηογϣϯΛ ੜ੒ ▸ WebSocket઀ଓݩͷશΫϥΠΞϯτʹର ͯ͠ड͚औͬͨϝοηʔδΛBroadcast ▸ Publisher: API ▸ ϝοηʔδ౤ߘ༻ͷPOST༻ APIΛ༻ҙ ▸ ೚ҙͷνϟοτۭؒʹରͯ͠౤ߘϝο ηʔδΛRedis Publish
  14. Point3: όϥϯγϯά WebSocket = ࣋ଓత઀ଓ Statelessͳ઀ଓͰͳ͍ͨΊɺϩʔυό ϥϯαʔΛؒʹڬΈʹ͍͘ ▸ WebSocket͸઀ଓ࣋ଓ͞ΕΔͨ Ίɺϩʔυόϥϯαʔ͕Ϙτϧωο

    ΫʹͳΓ͏Δ
  15. Point3: όϥϯγϯά - WebSocketͱELB ELBʹ͓͚ΔWebSocket઀ଓͷ՝୊ ▸ Protocol: HTTP΋TCP΋ཁ݅ʹ߹Θͣ ▸ HTTP:

    ELBʹΑΓWebSocketͷhandshake࣌ ʹར༻͢ΔHTTP Upgrade header͕࡟ΒΕ ΔͨΊɺWebSocket઀ଓͰ͖ͳ͍ (Socket.IO ͷ৔߹ɺXHR-Polling͕ڧ੍͞ΕΔ) ▸ TCP: Sticky Session͕ར༻Ͱ͖ͳ͍ͨΊɺ Socket.IOͷWebSocket઀ଓཱ֬ʹඞཁͳཁ ٻ͕ผͷαʔόʹৼΓ෼͚ΒΕɺhandshake ʹࣦഊ͢Δ ▸ Timeout໰୊ ▸ ͲͪΒͷProtocolΛબΜͩͱͯ͠΋ɺELBͷ Timeout஋ʹୡ͢Δͱ௨৴͕੾அ͞ΕΔ
  16. Point3: όϥϯγϯά - ղܾࡦ ELB͸࠷ॳͷηογϣϯཱ֬࣌ͷΈར༻ Ҿ༻: WebSocket on AWS (ϩʔυόϥϯαͱSocket઀ଓΛ࢖༻ͨ͠Πϕϯτ௨஌αʔόͷෛՙ෼ࢄ)

    @Amazon Web Service Japan - Slideshare
  17. Architecture ߦ͖ண͍ͨߏ੒ ▸ Web/AppαʔόʹɺNode.jsͱ Apache/PHPΛಉࠝ ▸ ઀ଓ؅ཧͷ࣮૷ΛɺhostnameΛฦ ࣮͢૷Ͱ؆ུԽͨͨ͠Ί ▸ ઀ଓઌཁٻؚΊɺAPI͸طଘࢿ࢈Λ

    ྲྀ༻ͯ͠PHPͰ࣮૷
  18. ෛՙࢼݧ socket.io-client Ͱෛՙࢼݧ ▸ clientΛେྔੜ੒ͯ͠websocket઀ଓΛ ໛฿͢Δ ▸ socket.io-client Λ࢖࣮ͬͯ૷ ▸

    ࢀߟ: ౰࣌ͷࢼݧ݁Ռ֓ཁ ▸ 1,000ಉ࣌઀ଓఔ౓·Ͱ͸҆ఆ ▸ handshakeࣦഊˠ࠶઀ଓൃੜͭͭ͠ ΋2,000ಉ࣌઀ଓఔ౓͸Մೳ ▸ server: m3.large ▸ ※࣮૷΍؀ڥͰڐ༰ྔมΘΔͷͰɺ ͋͘·Ͱࢀߟ஋ʹͱͲΊ͍ͯͩ͘͞
  19. ࢀߟ ಥ؏Ҋ݅ ▸ ϝϯόʔ: Node.js/WebSocketॳ৺ऀ2໊ + ΞʔΩʢࢲʣ ▸ ͏ͪҰਓ͸഑ଐ2ϲ݄໨ͷ৽ਓ ▸

    ։ൃظؒ: 2िؒ
  20. ·ͱΊ লΤωͰϏδωεཁ݅Λୡ੒͠Α͏ ▸ దࡐదॴʹٕज़Λ࠾୒/ઃܭ͢Δ ▸ ElastiCacheͷ࠾୒ʹΑΓɺRedisͷӡ༻͕΄΅ख཭ΕͰ͖ͨɻ ▸ ELB͸Statelessͳ௨৴Ͱ׆༻͢ΔɻStatefulͳ௨৴ʹ͸ෆ޲͖ɻ ▸ Α͋͘ΔቕΓͲ͜Ζ͸ઌճΓͯ͠௵͢

    ▸ ௨৴ཁ݅ʢStateful or Statelessʣ, ΩϟύγςΟ, εέʔϥϏϦςΟ ▸ εϐʔυײɹʼɹׂΓ੾Δ ▸ ίΞϩδοΫͷ࣮૷ʹ஫ྗ͠ɺ઀ଓ؅ཧ͸ׂΓ͖ͬͨɺ ▸ ͦͷ୅ΘΓෛՙࢼݧͱো֐ςετΛపఈ͠ɺ࠷௿ݶͷ඼࣭Λ୲อ ▸ ʮToBeʯσβΠϯ͸ϥϑεέον͚ͩͰ΋ඳ͍͓ͯ͘ͱྑ͍
  21. ࠂ஌ RAGE vol.2 Grand Final [7/30, 31] https://rage-esports.jp/