Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
R/W Splitting in Rails
Search
Kohei Suzuki
September 19, 2014
Programming
2
1.4k
R/W Splitting in Rails
RubyKaigi 2014 LT
https://github.com/eagletmt/switch_point
Kohei Suzuki
September 19, 2014
Tweet
Share
More Decks by Kohei Suzuki
See All by Kohei Suzuki
少人数でも運用できるインフラ作り / Operating infrastructure with less effort
eagletmt
1
2.9k
Cookpad Lounge #4 SRE 座談会 コンテナ中心の構成からサーバーレスへの展望 / From containers to serverless
eagletmt
0
640
Cookpad Tech Kitchen #20 Amazon ECS の安定運用 / Building a steady ECS infrastructure
eagletmt
1
3k
クックパッドでの Webアプリケーション開発 2017 / Web application development in Cookpad 2017
eagletmt
20
10k
ECS を利用したデプロイ環境
eagletmt
12
6.7k
ActiveRecord 3.2 -> 4.1
eagletmt
3
1.8k
クックパッドにおける Rubyの活用
eagletmt
0
490
複数DBとRails
eagletmt
14
7k
Other Decks in Programming
See All in Programming
nekko cloudにおけるProxmox VE利用事例
irumaru
3
420
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
200
Go の GC の不得意な部分を克服したい
taiyow
2
770
42 best practices for Symfony, a decade later
tucksaun
1
180
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
300
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
930
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
180
testcontainers のススメ
sgash708
1
120
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
今からはじめるAndroidアプリ開発 2024 / DevFest 2024
star_zero
0
1k
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
330
Refactor your code - refactor yourself
xosofox
1
260
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Docker and Python
trallard
42
3.1k
Practical Orchestrator
shlominoach
186
10k
How STYLIGHT went responsive
nonsquared
95
5.2k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Transcript
384QMJUUJOHJO3BJMT ,PIFJ4V[VLJ
4FMGJOUSPEVDUJPO ,PIFJ4V[VLJ !FBHMFUNU 5XJUUFS (JU)VC ʜ ! $PPLQBE*OD
3BJMTBOENVMUJQMF%#T 3BJMTTVQQPSUTUPFTUBCMJTIDPOOFDUJPOTUPEJ⒎FSFOU EBUBCBTFTGPSFBDINPEFMT class BlogBase < ActiveRecord::Base self.abstract_class = true
establish_connection :production_blog end ! class Article < BlogBase; end class Category < BlogBase; end ! class Comment < ActiveRecord::Base establish_connection :production_comment end
3BJMTBOENVMUJQMF%#T 38TQMJUUJOHJT/05TVQQPSUFE XSJUFUPUIFNBTUFS SFBEGSPNUIFTMBWF 5IFSF`TTFWFSBMHFNTUPEP38TQMJUUJOHJO3BJMT PDUPQVT ECDIBSNFS NVMUJ@EC BDUT@BT@SFBEPOMZBCMF
PDUPQVT IUUQTHJUIVCDPNUDIBOEZPDUPQVT 4IBSEJOHBOE38TQMJUUJOHBSFTVQQPSUFE .JHSBUJPOJTBMTPTVQQPSUFE "DUJWFMZNBJOUBJOFE *UXPSLTXJUI3BJMT .BOZGFBUVSFT MBSHFDPEFCBTF
BDUT@BT@SFBEPOMZBCMF IUUQTSVCZHFNTPSHHFNTBDUT@BT@SFBEPOMZBCMF 0MEHFN MBTUVQMPBE $PPLQBEVTFEJUVOUJMSFDFOUUJNFT )FBWJMZNPEJpFEUPTVQQPSU3BJMT %P38TQMJUUJOHPOMZ +VTU-0$ BTPGPVS3BJMTTVQQPSUFE
WFSTJPO
38TQMJUUJOH 8FOFFE38TQMJUUJOHPOMZ BDUT@BT@SFBEPOMZBCMFJTUPPPMEBOEGSBHJMFUP BHHSFTTJWFDIBOHFTPG3BJMT *SFJOWFOUFEBOFXHFNMJLFBDUT@BT@SFBEPOMZBCMF IUUQTHJUIVCDPNFBHMFUNUTXJUDI@QPJOU
TXJUDI@QPJOU %P38TQMJUUJOHPOMZ /PTIBSEJOH /PNJHSBUJPOT 'FXFSNPOLFZQBUDIFT JOBXFMMPSEFSFE NBOOFS IUUQTXXXqJDLSDPNQIPUPTFMMSCSPXO
$POpHVSBUJPO EBUBCBTFZNM production_blog_master: adapter: mysql2 database: blog username: blog_writable host:
db-blog-master ! production_blog_slave: adapter: mysql2 database: blog username: blog_readonly host: db-blog-slave
$POpHVSBUJPO *OJUJBMJ[FS SwitchPoint.configure do |config| config.define_switch_point :blog, readonly: :"#{Rails.env}_blog_slave", writable:
:"#{Rails.env}_blog_master" end
$POpHVSBUJPO .PEFMT class Article < ActiveRecord::Base use_switch_point :blog end !
class Category < ActiveRecord::Base use_switch_point :blog end ! class Comment < ActiveRecord::Base use_switch_point :comment end
1SPYZ 5IFSF`TBQSPYZCFUXFFONPEFMTBOEEBUBCBTFT BOEJUEPFT38TQMJUUJOH Article Category Comment blog comment db-blog-master db-blog-slave
db-comment-master db-comment-slave .PEFM 1SPYZ TXJUDIQPJOU %BUBCBTF
4XJUDIJOH Model.with_readonly {}$POOFDUUPUIFTMBWF Model.with_writable {}$POOFDUUPUIFNBTUFS with_readonlyBOEwith_writableDBOCFOFTUFE "MNPTUUIFTBNFTFNBOUJDTXJUIfrom_slaveBOE from_masterPGBDUT@BT@SFBEPOMZBCMF
5ZQJDBMVTBHF 6TFwith_readonlyJOBSPVOE@BDUJPOPG(&5 SFRVFTU 6TFwith_writableGPSXSJUJOHPS4&-&$5GSPN UIFNBTUFS 6TFwith_readonlyGPSTPNFCMPDLTFOEQPJOUT UIBUFYFDVUFTIFBWZRVFSZ
*OQSPEVDUJPO $PPLQBEJTVTJOHTXJUDI@QPJOUGPSUIFNBJO BQQMJDBUJPO -PUTPG"DUJWF3FDPSENPEFMT JOUPUBM .VMUJQMFNBTUFSTMBWFEBUBCBTFT 5IPVTBOETPGEBUBCBTFDPOOFDUJPOT
1PMJDZ ,FFQGFXFSEFQFOEFODJFTPO3BJMTJNQMFNFOUBUJPO /PCSBODIJOHEFQFOEJOHPO ActiveRecord::VERSION 6TFDPNNPOMZVTFEGFBUVSFTBOECFIBWJPST %PPOFKPC38TQMJUUJOH %PJUBUUIFSJHIUMBZFS
$PODMVTJPO *DSFBUFEBTJNQMFHFNUIBUFOBCMFT38TQMJUUJOH JO3BJMT IUUQTHJUIVCDPNFBHMFUNUTXJUDI@QPJOU