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
610
Cookpad Tech Kitchen #20 Amazon ECS の安定運用 / Building a steady ECS infrastructure
eagletmt
1
2.9k
クックパッドでの Webアプリケーション開発 2017 / Web application development in Cookpad 2017
eagletmt
20
10k
ECS を利用したデプロイ環境
eagletmt
12
6.6k
ActiveRecord 3.2 -> 4.1
eagletmt
3
1.7k
クックパッドにおける Rubyの活用
eagletmt
0
480
複数DBとRails
eagletmt
14
6.9k
Other Decks in Programming
See All in Programming
Micro Frontends for Java Microservices - dev2next 2024
mraible
PRO
0
160
Rails 8 Frontend: 10 commandments & 7 deadly sins in 2025
yshmarov
1
570
AWS Lambda Web Adapterを活用する新しいサーバーレスの実装パターン
tmokmss
6
5.2k
Frontend Magic mit CSS Houdini
joergneumann
0
420
ビット演算の話 / Let's play with bit operations
kaityo256
PRO
3
140
PHPを書く理由、PHPを書いていて良い理由 / Reasons to write PHP and why it is good to write PHP
seike460
PRO
5
270
Kubernetes上でOracle_Databaseの運用を楽にするOraOperatorの紹介
nnaka2992
0
140
なぜアジャイルがうまくいかないのか?
yum3
2
140
Kotlin Multiplatform at Stable and Beyond (Kotlin Vienna, October 2024)
zsmb
2
300
モジュラモノリス、その前に / Modular monolith, before that
euglena1215
3
360
AWS CDKを用いたセキュアなCI/CDパイプラインの構築 / Build a secure CI/CD pipeline using AWS CDK
seike460
PRO
3
490
M5Stackボードの選び方
tanakamasayuki
0
200
Featured
See All Featured
It's Worth the Effort
3n
182
27k
How to name files
jennybc
76
98k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
41
6.5k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
3
80
KATA
mclloyd
27
13k
Gamification - CAS2011
davidbonilla
79
5k
Embracing the Ebb and Flow
colly
83
4.4k
The Cost Of JavaScript in 2023
addyosmani
43
5.8k
Practical Orchestrator
shlominoach
185
10k
Building a Modern Day E-commerce SEO Strategy
aleyda
36
6.8k
Robots, Beer and Maslow
schacon
PRO
157
8.2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
23
1.7k
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