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
620
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.7k
クックパッドにおける Rubyの活用
eagletmt
0
490
複数DBとRails
eagletmt
14
7k
Other Decks in Programming
See All in Programming
Vue3の一歩踏み込んだパフォーマンスチューニング2024
hal_spidernight
3
3.1k
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
260
RailsのPull requestsのレビューの時に私が考えていること
yahonda
5
1.7k
プロジェクト新規参入者のリードタイム短縮の観点から見る、品質の高いコードとアーキテクチャを保つメリット
d_endo
1
1k
EventSourcingの理想と現実
wenas
6
2.1k
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
3
400
OpenTelemetryでRailsのパフォーマンス分析を始めてみよう(KoR2024)
ymtdzzz
4
1.6k
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
110
Pinia Colada が実現するスマートな非同期処理
naokihaba
2
160
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
230
VR HMDとしてのVision Pro+ゲーム開発について
yasei_no_otoko
0
100
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
270
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
790
The Cult of Friendly URLs
andyhume
78
6k
Optimizing for Happiness
mojombo
376
69k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
How GitHub (no longer) Works
holman
311
140k
The Art of Programming - Codeland 2020
erikaheidi
51
13k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
The Invisible Side of Design
smashingmag
297
50k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
For a Future-Friendly Web
brad_frost
175
9.4k
Designing on Purpose - Digital PM Summit 2013
jponch
115
6.9k
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