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

Ruby on Rails & Vitessによる
DBスケールアウト

junsumida
February 10, 2016

Ruby on Rails & Vitessによる
DBスケールアウト

ソーシャルゲームのような高負荷がかかるWebアプリケーションにおいては、何十, 何百台ものサーバーでスケールアウトするのが当然の時代になりました。特にDBサーバーでは垂直分割、水平分割による複数のDBへの負荷の分散が行われ、アプリケーション側でハンドリングすべきことが増してきています。

今回は、Google社のyoutubeの基盤として大量のクエリを捌いているVitessを、当社のゲームにおいて実際にDBサーバーのマネージ&スケールアウトに使用した話をします。主にVitess, gRPC, MySQL/KVSとの比較, Rails/ActiveRecordにおけるデータベース分割, VitessとRails, Live Resharding周りの話です。

junsumida

February 10, 2016
Tweet

More Decks by junsumida

Other Decks in Technology

Transcript

  1. > < next previous Railsʹ͓͚ΔDB෼ׂ ‣ Octopus ‣ ਫฏਨ௚෼ׂʹରԠ ‣

    SwitchPoint ‣ Cookpad͞Μ ‣ ਨ௚෼ׂʹରԠ ‣ ActiveRecord::Turntable ‣ Drecom͞Μ ‣ ਫฏਨ௚෼ׂʹରԠ ‣ ฐࣾͰ΋࢖͍ͬͯ·͢ * https://github.com/thiagopradi/octopus * http://techlife.cookpad.com/entry/2014/08/28/194147 * https://github.com/drecom/activerecord-turntable
  2. > < next previous Vitessʹ͍ͭͯ؆୯ʹ ‣ ݩʑ͸Youtube༻ͷconnection-pooling proxy ‣ ঃʑʹ͍Ζ͍Ζͳػೳ͕௥Ճ͞Ε͍ͯͬͨ

    ‣ Go੡ ‣ gRPC, BSON RPC ͰΫϥΠΞϯτͱ௨৴ ‣ PHP, Go, Python, JavaͷެࣜΫϥΠΞϯτ ‣ 2011೥͔Βyoutubeͷຊ൪؀ڥͰ࢖༻ * Youtube Vitess (Cloud Native Platform) * https://github.com/youtube/vitess
  3. > < next previous Vitess͕Ͱ͖Δ͜ͱ ‣ Connection pooling ‣ QueryͷΩϟογϡ

    ‣ Queryղੳ, ةݥͳΫΤϦͷॻ͖׵͑ ‣ ߏ੒֬ೝ / εΩʔϚมߋ༻ͷ web console ‣ DBΠϯελϯεͷϞχλϦϯά ‣ Live Resharding, master failover, etc… * Youtube Vitess (Scaling MySQL with Vitess Kubernetes)
  4. > < next previous Vitess vs MySQL ‣ ܰྔͳconnection (BSON

    vs MySQL) ‣ SQL Parser͕ةݥͳΫΤϦΛ๷ࢭ ‣ ਫฏɺਨ௚෼ׂΛαϙʔτ ‣ Rangeϕʔεͷsharding ‣ master failover΍data backupʹ΋ରԠ * http://vitess.io/overview/
  5. > < next previous Vitess vs NoSQL ‣ ୯७ͳKVSͱ͸ҟͳΓɺwhere, join,

    count, group byͳ Ͳ͕Ͱ͖Δ ‣ VTGate V3Ͱ͸·ͩcount, group byͳͲͷू໿ܥ͕ಈ͔ͳ͍ ‣ Transaction͕࢖͑Δ ‣ cross shardͳTransaction͸·ͩͰ͖ͳ͍ ‣ MySQLΛ࢖͑ΔϢʔβʔͰ͋Ε͹ֶशίετ͕௿͍ ‣ MySQLͰ࢖͑Δindexػೳ͕͢΂ͯ࢖͑Δ * http://vitess.io/overview/
  6. > < next previous app mysql vttablet mysql vttablet mysql

    vttablet * Youtube Vitess (Anatomy of a Distributed Database on Kubernetes) app app vtctl schema؅ཧ / ߏ੒֬ೝ gRPC / BSON RPC gRPC / BSON RPC vtgate ܰྔproxy / routing
  7. > < next previous ߏ੒ʹ͍ͭͯ΋͏ͪΐͬͱ͚ͩ ‣ MySQL 5.6 / MariaDB

    10.0 or higher ʹରԠ ‣ ੲ͸ΦϦδφϧͷMySQLͩͬͨ ‣ etcd or Zookeeper Λ࢖ͬͯɺSchema΍DBߏ੒ͳͲΛ ෼ࢄͯ͠ه࿥͍ͯ͠Δ ‣ Google಺෦Ͱ͸Goolgle ChubbyΛ࢖͍ͬͯΔΒ͍͠ ‣ vttablet, vtctldʹ͸web console͕෇͍͍ͯͯschemaΛ ૢ࡞ͨ͠ΓɺmysqldͷϞχλϦϯά͕Ͱ͖Δ * http://vitess.io/overview/ * https://www.youtube.com/watch?v=midJ6b1LkA0
  8. > < next previous app mysql vttablet mysql vttablet mysql

    vttablet * Youtube Vitess (Anatomy of a Distributed Database on Kubernetes) app app gRPC / BSON RPC vtgate ܰྔproxy / routing
  9. > < next previous A high performance, open source, general

    RPC framework that puts mobile and HTTP/2 first. * http://www.grpc.io
  10. > < next previous gRPCͱ͸ ‣ ͍ΘΏΔRPCϑϨʔϜϫʔΫ ‣ HTTP/2 ඪ४ʹଇ͍ͬͯΔ

    ‣ ίΞ෦෼͸ڞ௨ɺCͰ࣮૷ ‣ 10ݴޠʹରԠ ‣ C, C++, Ruby, NodeJS, Python, PHP, Objective-C, C#, Go, Java ‣ σϑΥϧτͷσʔλߏ଄ͱͯ͠Protocol Buffers * http://www.grpc.io * https://github.com/grpc/grpc
  11. > < next previous Protocol Buffersͱ͸ ‣ ݴޠʹ΋ɺϓϥοτϑΥʔϜʹ΋தཱͳɺߏ଄Խ͞ ΕͨσʔλΛγϦΞϥΠζ͢ΔͨΊͷ֦ுՄೳͳػ ߏ

    (௚༁) ‣ ΑΓγϯϓϧͰߴ଎Ͱখ͍͞XML (௚༁) ‣ ΋ͷ͘͢͝ࡶʹݴ͏ͱɺ࠷ۙ͸΍ΓͷJSON Schema Έ͍ͨͳ΍ͭɺͨͩ͠όΠφϦ ‣ MessagePackͱൺֱ͞ΕΔ͜ͱ͕ଟ͍Ͱ͢ * https://developers.google.com/protocol-buffers/
  12. > < next previous * What is gRPC? (www.grpc.io/docs/#what-is-grpc) Protocol

    Buffersͷྫ (࣮ࡍͷVitessͷ.proto file) Rubyͩͱ͜Μͳײ͡ʹͳΓ·͢
  13. > < next previous gRPC w/ Protocol Buffers ‣ ଞݴޠରԠͯ͠ΔͨΊɺClient΍Mock

    Server·ͰΛ ࣗಈੜ੒͢Δ͜ͱ͕Մೳ ‣ ௨৴ର৅ͷΞϓϦέʔγϣϯͷ۱ʑ·ͰίʔυΛಡ ·ͳͯ͘΋ClientΛ࡞Δ/͔ͭ͏͜ͱ͕Ͱ͖Δ * https://developers.google.com/protocol-buffers/
  14. > < next previous VitessͷRuby ClientΛ࡞Δ্ͰͰਏ͔ͬͨ͜ͱ ‣ ҰԠ·ͩgRPC͕beta൛ɺVitess Client΋৭ʑ଍Γͳ͍ ‣

    Protocol Buffer͔ΒRubyͷίʔυ͕ࣗಈੜ੒Ͱ͖Δ͕ɺੜ੒͞ ΕΔίʔυͷ໊લۭ͕ؒRubyͱ૬ੑ͕ѱ͘ɺࣗಈੜ੒͞Εͨ ίʔυΛ͍͡Γճ͢Ӌ໨ʹ ‣ Mock serverͷΑ͏ͳ΋ͷ΋࡞ΕΔ͕ɺbinaryͷarrayΛ͏·͘ σ/γϦΞϥΠζͰ͖ͳ͍ͷ͔ΤϥʔΛى͜͢ ‣ ͨ·ʹMock server͕segvͰࢮ͵ ‣ ͜ͷลͷ໰୊ͷ੾Γ෼͚͕Ұ൪ਏ͔ͬͨ ‣ ͦ΋ͦ΋RubyͷgRPC gem͕versionʹΑͬͯίϯύΠϧͰ͖ͳ͔ͬͨΓ͢Δ ‣ Railsͷίʔυ(ಛʹActiveRecord)ΛԆʑͱ௥͏Ӌ໨ʹ ‣ ͓͔͛ͰActiveRecordपΓͷίʔυʹ͸ৄ͘͠ͳΕ·ͨ͠^^
  15. > < next previous Rails mysql vttablet mysql vttablet mysql

    vttablet vtctl gRPC / BSON RPC gRPC / BSON RPC vtgate ruby
 client schema༻ mysql Rails w/ Vitess
  16. > < next previous ͜Ε͔Βͷ՝୊ ‣ ·ͩ৭ʑͱݕূத (2016 2݄ݱࡏ) ‣

    ήʔϜͰ࢖ͬͨ৔߹ͷύϑΥʔϚϯεͳͲ ‣ εΩʔϚ؅ཧ͋ͨΓ΋ ‣ ڊେͳΞϓϦέʔγϣϯͳͷͰɺ·ͩ·ͩClientʹ଍Γͳ͍ػ ೳ͕͋Δ ‣ GoogleͷBorgʹ࠷దԽ͞Ε͍ͯΔͷͰɺAWS EC2ɺmonitoring πʔϧ, ߏ੒؅ཧπʔϧͳͲͱͲ͏ંΓ߹͍Λ͚ͭΔ͔ ‣ ӡ༻ϑϩʔ͕ͳΔ΂͘มΘΒͳ͍Α͏ʹ͍ͨ͠