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
720
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
840
サービス開発する平成の君に 昭和の僕から伝えたい7つのこと@平成.rb #2
yaboojp
0
760
夏休みの宿題 8/31にやらない話 @Otemachi.rb #14
yaboojp
0
320
ぼくが考える最強のApplicationModel @表参道.rb #43
yaboojp
0
660
大掃除 on Rails @Otemachi.rb #12
yaboojp
1
37
使わない機能の倒し方 @s-dev talks 〜サービス開発勉強会〜 大忘年LT大会
yaboojp
0
90
Featured
See All Featured
Designing for Performance
lara
604
68k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
It's Worth the Effort
3n
183
28k
Documentation Writing (for coders)
carmenintech
67
4.5k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.7k
A designer walks into a library…
pauljervisheath
205
24k
Speed Design
sergeychernyshev
25
730
Rails Girls Zürich Keynote
gr2m
94
13k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
2
160
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
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