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

リアルタイム通信をささえるブラナイのサーバー開発と運用(前編)

YuukiARIA
August 04, 2016

 リアルタイム通信をささえるブラナイのサーバー開発と運用(前編)

YuukiARIA

August 04, 2016
Tweet

More Decks by YuukiARIA

Other Decks in Programming

Transcript

  1. 1 8 BA 6 A F 724/3 S &) S

    L S S r & S S n b
  2. & & ®®S r X 3 3 s _ RPGX

    ® S R S S & S R
  3. 4

  4. 1/:3 v DASH rgp iU • 7 26 S •

    http://bks-dash.com , U 5
  5. r

  6. s s ® S Nginx + Unicorn + Rails S

    S MariaDB Memcached S ActiveJob + Sidekiq Photon S Ridgepole S ActiveRecord::Sharding 7
  7. s s Unity _ R s l R ® S

    Nginx + Unicorn + Rails S S MariaDB Memcached S ActiveJob + Sidekiq Photon S Ridgepole S ActiveRecord::Sharding 8
  8. API app cache app database batch game master photon cluster

    Multi-play load balancer game master photon cluster 14
  9. u WRITE a U • S S … • •

    • s • u u t t i v R a bcs k R (sharding) q gp i 17
  10. t np READ/WRITE u a s • S S S

    • S S S S • master_data user_friend_code matching 18
  11. M DHB u q i dra u • user_ids S

    S q S • ActiveRecord::Sharding user shards user sequencer s g ( R user_id s a shards hID S S S s 19
  12. M DHB u q i dra u • user_ids S

    S q S • ActiveRecord::Sharding user shards user sequencer 8DB 4 s S s g ( R 20
  13. 1 uDB v Migration • s S X • h

    s Migration l u _ • q n or _ c … • ALTER h … qv Migration qvscRRidgepole • l h R 21
  14. D BA I Arv D BA I A • https://github.com/winebarrel/ridgepole

    • DB S S S • S S S S _DDL ALTER TABLE u • pR 22
  15. 5DB NDIH PM D BA I A create_table :users, options:

    "ENGINE=InnoDB" do |t| t.string :name, null: false t.integer :rank, null: false, default: 1 t.integer :experience, null: false, default: 0 - t.integer :example1, null: false + t.string :example2, null: false, default: "" : ALTER TABLE `users` ADD `example2` varchar(255) DEFAULT '' NOT NULL AFTER `experience` ALTER TABLE `users` DROP `example1` D BA I A • S Y S × • S × s s _ 24
  16. D BA I Au • W 8 1 gscp •

    S _ DB h • UP/DOWN k × r • UP/DOWN r • a t qb • Migration S _ • r1 u a • schema S × _ • ALTER_ S s schema r _ OK 25
  17. qu D BA I A qv q v b i

    1. schema 2. S DB r 3. commit & push 4. S S DB 5. S S & S 6. ®®S DB i drv gs 26
  18. 1 - R - s db/schemas ├─ master_data │ ├─

    chars_schema.rb │ ├─ items_schema.rb │ : │ └─ ├─ user_shard │ ├─ users_schema.rb │ ├─ user_points_schema.rb │ : │ └─ ├─ : 27
  19. 1 - R - s db/schemas ├─ master_data │ ├─

    chars_schema.rb │ ├─ items_schema.rb │ : │ └─ ├─ user_shard │ ├─ users_schema.rb │ ├─ user_points_schema.rb │ : │ └─ ├─ : DATABASE TABLE 28
  20. 1 D BA I A • A GF D s

    D A c _ • D l10 S D A h dir = ENV["DB"] remove_shard_number!(dir) pattern = File.join(File.dirname(__FILE__), dir, "*_schema.rb") Dir[pattern].each do |schema_file| require File.join(dir, File.basename(schema_file)) end 29
  21. 1 D BA I A • A GF D s

    D A c _ • D l10 S D A h dir = ENV["DB"] remove_shard_number!(dir) pattern = File.join(File.dirname(__FILE__), dir, "*_schema.rb") Dir[pattern].each do |schema_file| require File.join(dir, File.basename(schema_file)) end 30
  22. 1 D BA I A • A GF D s

    D A c _ • D l10 S D A h dir = ENV["DB"] remove_shard_number!(dir) pattern = File.join(File.dirname(__FILE__), dir, "*_schema.rb") Dir[pattern].each do |schema_file| require File.join(dir, File.basename(schema_file)) end 31 user_shard_001, user_shard_002, ... r user_shard ® S ei
  23. 1 D BA I A u DMN HI A •

    10 S _ r s & • ol S A GF 10 32 10 A s 10 r 5A GF R
  24. 8 INIH u S 8 INIH k • S S

    • S all-in-one u • • 41
  25. 8 INIH u g 8 INIH u hosts: - photon1.example.com

    photon1.example.com /matching/hosts photon_server.yml photon cluster photon cluster 42
  26. 8 INIH u ( ( t gp hosts: - photon1.example.com

    - photon2.example.com photon1.example.com /matching/hosts photon_server.yml photon cluster photon2.example.com or photon cluster 43
  27. 8 INIH u ( ( 8 INIH hosts: - photon2.example.com

    photon2.example.com /matching/hosts photon_server.yml photon cluster 45
  28. u8 INIH u • 8 INIH • i G MNA

    MA PA q • t ag i • 28:t a/84 q • s or _ ™ h c mol • DB i c s photon master-server • qu g i 46
  29. r

  30. r • u u • u r to pR q

    gk r u • 8 INIH gk u to pR u t 48