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
630
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.6k
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
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.5k
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
200
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Ethereum_.pdf
nekomatu
0
460
Remix on Hono on Cloudflare Workers
yusukebe
1
280
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
初めてDefinitelyTypedにPRを出した話
syumai
0
400
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
CSC509 Lecture 09
javiergs
PRO
0
140
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
280
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
How to Ace a Technical Interview
jacobian
276
23k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Fireside Chat
paigeccino
34
3k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Producing Creativity
orderedlist
PRO
341
39k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Facilitating Awesome Meetings
lara
50
6.1k
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