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
RailsのCacheつかってますか?@表参道.rb #44
Search
YABOO JAPAN
March 07, 2019
0
710
RailsのCacheつかってますか?@表参道.rb #44
YABOO JAPAN
March 07, 2019
Tweet
Share
More Decks by YABOO JAPAN
See All by YABOO JAPAN
RubyKaigiでもらった熱量がOSSに変換された話@AFTER RubyKaigi 2019
yaboojp
0
2.4k
RailsでViewModel導入に 挫折しかけてる話@表参道.rb #44
yaboojp
1
820
サービス開発する平成の君に 昭和の僕から伝えたい7つのこと@平成.rb #2
yaboojp
0
750
夏休みの宿題 8/31にやらない話 @Otemachi.rb #14
yaboojp
0
310
ぼくが考える最強のApplicationModel @表参道.rb #43
yaboojp
0
660
大掃除 on Rails @Otemachi.rb #12
yaboojp
1
33
使わない機能の倒し方 @s-dev talks 〜サービス開発勉強会〜 大忘年LT大会
yaboojp
0
88
Featured
See All Featured
How GitHub (no longer) Works
holman
311
140k
Building Your Own Lightsaber
phodgson
103
6.1k
Side Projects
sachag
452
42k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Rails Girls Zürich Keynote
gr2m
94
13k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Visualization
eitanlees
145
15k
Gamification - CAS2011
davidbonilla
80
5.1k
Music & Morning Musume
bryan
46
6.2k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
440
Transcript
RailsͷCache͔ͭͬͯ·͔͢ʁ @yaboojp on දࢀಓ.rb #44 2019/3/7
Self • Name: େ༅ Ӭ / @yaboojp • Jobs: •
22Inc. Co-Founder & CTO • ex NTTdata • Location: ژ -> ౦ژ • Favorites: ΫϥϑτϏʔϧ, Իָ, όΠΫ, JALϚΠ ϧ
None
Cacheͱ͍ͬͯ৭ʑ $MJFOU /HJOY 6OJDPSO 3%#.4 )UUQ)FBEFS &YQJSFT &5BH $BDIF$POUSPM
-BTU .PEJpFEͳͲ 1BHF$BDIF 'SBHNFOU$BDIF "DUJPO$BDIF .JEEMFXBSF 7BSOJTI 4RVJEͳͲ $%/ $MPVE'MPOUͳͲ 42-$BDIF ϨϕϧΩϟογϡ %/4 -#
on Railsͳͱ͚ͩ͜
PageCacheͱ • Rails3·Ͱඪ४උ͕ͩͬͨɺࠓGem • ॳճΞΫηε࣌Ҏ֎Rubyʹࣄͤ͞ͳ͍
PageCache ࣮ݧ • ྫ͑͜ΜͳϖʔδʹΔͱͲ͏͔ʁ
PageCache ݁Ռ • ݁Ռɿ 173ms => 170ms • 1.7%ߴԽ... ͱ͍͏͔ɺ΄΅มΘΒͳ͍
• ಈతίϯςϯπ͕গͳ͍ViewͰΔҙຯ͋·Γͳ ͍ • ͨͩɺunicornͳͲͷAppαʔόͷෛՙܰݮɺো࣌ ͰฦͤΔͱ͍ͬͨϝϦοτ͋Δ
͡Ό͋ɺ ಈతίϯςϯπ͕ଟ͍ϖʔδ ͰPageCacheͬͯΈΑ͏
PageCache ҙ • Railsͷaction͕Ұ࣮ߦ͞Εͳ͍ͨΊɺ֤छ ϩδοΫͪΖΜɺೝূ͢Β͢Γൈ͚Δ Ϣʔβຖͷ ίϯςϯπΤϦΞ ͕͜͜ॳճʹΞΫηεͨ͠Ϣʔβͷใͱͯ͠Ϩϯμ Ϧϯά͞Εͨ)5.-Λৗʹฦ͢ ˞෦తʹ"KBYߋ৽͢Δઃܭ͋Γ
͍ॴ͕ͳ͔ͬͨ
PageCache ΦϚέ • ͠ΐ͏͕ͳ͍ͷͰɺ͜͏͍͏࣮ݧ • ݁Ռɿ 1100ms => 100ms ͙Β͍
PageCache ·ͱΊ • Railsʹ౸ୡ͠ͳ͍ͷڧ͍ • ίϯςϯπͷग़͚͠ͳͲʹ͑ͳ͍ͳͲ ͍ॴ͕ݶఆ͞ΕΔ • ಋೖίετΊͬͪΌ͍
ݟ!!...??
࣍ʂʂ
FragmentCacheͱ • ҰϨϯμϦϯάͨ͠ViewϑΝΠϧΛϑϥά ϝϯτͱ͍͏୯ҐͰCacheStoreʹอଘ Ωϟογϡ͍ͨ͠ ΤϦΞ 'SBHNFOU
FragmentCache ઃఆ • อଘઌࣗ༝ʹઃఆ
FragmentCache ͍ํ • key id + updated_at ͱ͔ҰҙʹͳΔΑ͏ʹ
ϩγΞϯυʔϧΩϟογϡ
FragmentCache σόοά • ։ൃڥઃఆೖΕͱ͘ͱ • ͜ΜͳΩϟογϡͷར༻ঢ়گ͕֬ೝͰ͖Δ
FragmentCache #1 • ͋Γ;Εͨใϖʔδ • 800ms -> 720ms 10%ߴԽ
FragmentCache #2 • ΊͬͪΌॏ͍ϖʔδ • 9925ms -> 805ms 1240%ߴԽ ͳΜ͔ΞϗΈ͍ͨ
ʹॏ͍ϖʔδ ʢ/ ؚΉʣ
దʹExpireͤ͞Δ keyʹҙ • id + updated_at ͱ͔͕ϕετϓϥΫςΟε • ϛεͬͨΒେࣄނʹͳΔ͜ͱ
ΩϟογϡͰૣͯ͘͠Α Ωϟογϡͳ͍ͱ͍ ͬͱΩϟογϡΛ ͍ʂʂ ੑೳ Ωϟογϡ ผͷՕॴ͕͘ͳΔͱ Ωϟογϡ
༻๏ɾ༻ྔΛकͬͯ ਖ਼͓͍͍ͩ͘͘͠͞
None
We Are Hiring
Thanks