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

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

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

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

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

Taro Hirose

June 22, 2016
Tweet

More Decks by Taro Hirose

Other Decks in Technology

Transcript

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

    αʔόαΠυΤϯδχΞ ▸ લ৬: ITίϯαϧ / SIer ▸ ಘҙྖҬ: ߏ੒؅ཧ/ࣗಈԽ, ؂ࢹ ▸ Twitter: @uorat ▸ Blog: http://uorat.hatenablog.com/
  2. νϟοτͷଘࡏҙٛ ۭؒڞ༗ ▸ ؍ઓ࣌ͷྟ৔ײΛΦϯϥΠϯͰମݧ ▸ ྫ: RAGE ▸ ίϛϡχέʔγϣϯखஈ ▸

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

    ▸ શࢹௌऀʹରͯ͠Ұ੪ʹϝοηʔδ഑৴͢Δඞཁ͋Γ ▸ ߴ֦ுੑ ▸ ಉ࣌ࢹௌऀ਺͕૿͑ͯ΋εέʔϧΞ΢τͰ͖Δ ▸ ਓؾ഑৴͸਺ສਓҎ্ͷϢʔβ͕ࢹௌ͢Δ ▸ ෳ਺഑৴͋Γɺ഑৴͸໷ʹूத͢Δ ▸ ࢹௌऀ͕਺ेສ, ਺ඦສਓͱ૿͑ͯ΋ϝοηʔδ഑৴ʹࢧো Λ͖ͨ͞ͳ͍͜ͱ
  4. Point2: ϓϩηεؒͷϝοηʔδ഑৴ - Pub/Subͱ͸ ग़൛ - ߪಡܕϞσϧ ▸ ग़൛ऀʢPublisherʣ ▸

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

    Λ࠾༻ ▸ Subscriber: Node.js ▸ νϟοτۭؒͷSubscribeηογϣϯΛ ੜ੒ ▸ WebSocket઀ଓݩͷશΫϥΠΞϯτʹର ͯ͠ड͚औͬͨϝοηʔδΛBroadcast ▸ Publisher: API ▸ ϝοηʔδ౤ߘ༻ͷPOST༻ APIΛ༻ҙ ▸ ೚ҙͷνϟοτۭؒʹରͯ͠౤ߘϝο ηʔδΛRedis Publish
  6. 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஋ʹୡ͢Δͱ௨৴͕੾அ͞ΕΔ
  7. ෛՙࢼݧ socket.io-client Ͱෛՙࢼݧ ▸ clientΛେྔੜ੒ͯ͠websocket઀ଓΛ ໛฿͢Δ ▸ socket.io-client Λ࢖࣮ͬͯ૷ ▸

    ࢀߟ: ౰࣌ͷࢼݧ݁Ռ֓ཁ ▸ 1,000ಉ࣌઀ଓఔ౓·Ͱ͸҆ఆ ▸ handshakeࣦഊˠ࠶઀ଓൃੜͭͭ͠ ΋2,000ಉ࣌઀ଓఔ౓͸Մೳ ▸ server: m3.large ▸ ※࣮૷΍؀ڥͰڐ༰ྔมΘΔͷͰɺ ͋͘·Ͱࢀߟ஋ʹͱͲΊ͍ͯͩ͘͞
  8. ·ͱΊ লΤωͰϏδωεཁ݅Λୡ੒͠Α͏ ▸ దࡐదॴʹٕज़Λ࠾୒/ઃܭ͢Δ ▸ ElastiCacheͷ࠾୒ʹΑΓɺRedisͷӡ༻͕΄΅ख཭ΕͰ͖ͨɻ ▸ ELB͸Statelessͳ௨৴Ͱ׆༻͢ΔɻStatefulͳ௨৴ʹ͸ෆ޲͖ɻ ▸ Α͋͘ΔቕΓͲ͜Ζ͸ઌճΓͯ͠௵͢

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