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
Estratégias para tunar sua aplicação rails
Search
Cirdes
November 29, 2014
Programming
1
67
Estratégias para tunar sua aplicação rails
Palestra na RuPy 2014
Cirdes
November 29, 2014
Tweet
Share
More Decks by Cirdes
See All by Cirdes
Testando aplicações Rails com Playwright
cirdes
0
61
Ferramentas para CTO`s
cirdes
0
57
Aumentando O Poder Do Seu HTML Com AngularJS
cirdes
0
86
Getting Started with Angular.JS
cirdes
2
470
Como desenvolver um produto escalável com uma linguagem: Nova, lente e insegura
cirdes
0
170
Boas práticas usando RSpec
cirdes
0
290
Como construir uma Aplicação que consuma e produza updates no Twitter usando Python.
cirdes
0
37
Other Decks in Programming
See All in Programming
アプリを起動せずにアプリを開発して品質と生産性を上げる
ishkawa
0
2.7k
Dissecting and Reconstructing Ruby Syntactic Structures
ydah
0
490
Building Scalable Mobile Projects: Fast Builds, High Reusability and Clear Ownership
cyrilmottier
2
270
Qiita Bash
mercury_dev0517
1
190
SQL Server ベクトル検索
odashinsuke
0
170
Devin入門と最近のアップデートから見るDevinの進化 / Introduction to Devin and the Evolution of Devin as Seen in Recent Update
rkaga
9
4.9k
Optimizing JRuby 10
headius
0
270
RuboCop: Modularity and AST Insights
koic
1
220
マルチアカウント環境での、そこまでがんばらない RI/SP 運用設計
wa6sn
0
720
MCP世界への招待: AIエンジニアが創る次世代エージェント連携の世界
gunta
4
900
Do Dumb Things
mitsuhiko
0
430
Building a macOS screen saver with Kotlin (Android Makers 2025)
zsmb
1
150
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
52
7.5k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
13
670
The MySQL Ecosystem @ GitHub 2015
samlambert
251
12k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.4k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
13
1.4k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Thoughts on Productivity
jonyablonski
69
4.6k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Building an army of robots
kneath
304
45k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
4 Signs Your Business is Dying
shpigford
183
22k
Automating Front-end Workflow
addyosmani
1369
200k
Transcript
ESTRATÉGIASDE CACHE PARA TUNAR SUA APLICAÇÃO RAILS
CIRDES HENRIQUE ENGENHEIRO DA COMPUTAÇÃO - UFPE ORGANIZADOR DO ABRIL
PRO RUBY C0-FUNDADOR E DEV DO EVENTICK
None
335 MIL TICKETS EMITIDOS 3600 ORGANIZADORES 1200 EVENTOS FUTUROS
RECIFE
RECIFE
O EVENTICK FICOU FORA DO AR POR 30 MINUTOS
ANTES DA SOLUÇÃO, UM PASSO ATRÁS: MONITORAR A APLICAÇÃO
NewRelic Nazar.io HoneyBadger Logentries Inspectlet The Informant
SOA?
SINGLE RAILS APP LIKE SHOPIFY
70% DAS REQUISIÇÕES BATEM NA CACHE
O QUE É CACHE?
Cache é um componente que guarda informações de forma TRANSPARENTE
para que futuras requisições sejam mais RÁPIDAS
QUAL A CARACTERÍSTICA DA CACHE?
O QUE USA CACHE?
DO QUE É CONSTITUÍDA UMA CACHE?
CACHE = CASH
ARQUITETURA DE MEMÓRIA
CACHE HIT / CACHE MISS / CACHE RATIO
COMO MAXIMIZAR O CACHE HIT?
BÉLÁDY’S ALGORITHM
RANDOM REPLACEMENT (RR)
LEAST-FREQUENTLY USED (LFU)
LEAST-RECENTLY USED (LRU)
O QUE É WEBCACHING?
REQUISIÇÃO Rails App Reverse Proxy CDN Proxy Browser
CACHE SERVER-SIDE CACHE CLIENT-SIDE
PAGE CACHE ACTION CACHE FRAGMENT CACHE RAILS CACHE
WRITE ON DISK BYPASS RAILS APPLICATION ENTIRE STATELESS PAGES NÃO
FUNCIONA NO HEROKU PAGE CACHE
PAGE CACHE class WeblogController < ActionController::Base caches_page :show, :new def
update expire_page action: 'show', id: params[:list][:id] end end
SIMILAR TO PAGE CACHE RUN FILTERS ACTION CACHE
ACTION CACHE class PostsController < ActionController::Base caches_action :show, expires_in: 1.hour
end
DEPRECATED
HTML CACHE AVAILABLE IN RAILS 4 FRAGMENT CACHE
RAILS CACHE FRAGMENT AND ACTION CACHE BUILD ON RAILS.CACHE CONFIG.ACTION_CONTROLLER.PERFORM_CACHING
= TRUE
ActiveSupport::Cache::Store FileStore MemoryStore NullStore MemCacheStore
HOW TO USE IT Rails.cache.write 'foo', 'bar' Rails.cache.fetch 'foo' Rails.cache.write
:foo, {a: 'b'}
FRAGMENT CACHING Rais.cache.fetch 'key', expires_in: 5.minutes, race_condition_ttl: 10.seconds do #code
end
FRAGMENT CACHING <% cache "event-#{event.id}" do %> <%= render event
%> <% end %>
FRAGMENT CACHING <% cache “event-#{event.id}”, expires_in: 1.year do %> <%=
render event %> <% end %>
FRAGMENT CACHING def update expire_fragment("event-#{event.id}") end
FRAGMENT CACHING <% cache [:recent, event] do %> <%= render
event %> <% end %>
FRAGMENT CACHING ACTIVESUPPORT::CACHE.EXPAND_CACHE_KEY [:RECENT, EVENT] => "RECENT/EVENTS/12510-20141128131506743910000"
FRAGMENT CACHING <% cache :recent_attendees, expires_in: 5.minutes do %> <%=
render partial: 'recent', collection: Attendees.recent %> <% end %>
FRAGMENT CACHING <% cache(cache_key_for_attendees) do %> <%= render partial: 'recent',
collection: Attendees.recent %> <% end %>
FRAGMENT CACHING module AttendeesHelper def cache_key_for_attendees count = Attendee.count max_updated_at
= Attendee.maximum(:updated_at).try(:utc).try(:to_s, :number) "attendees/all-#{count}-#{max_updated_at}" end end
FRAGMENT CACHING <% cache(cache_key_for_attendees) do %> <%= render partial: 'recent',
collection: Attendees.recent %> <% end %>
PROBLEMA COM TEMPLATE
CACHE Digests <!-- app/views/events/show.html.erb --> <% cache ["v1", @event] do%>
<h1>Team: <%= @event.title %></h1> <%= render @event.attendees %> <% end %> <!-- app/views/attendees/_attendee.html.erb --> <% cache ["v1", attendee] do %> <span><%= attendee.name %></span> <span><%= attendee.email %></span> <% end %>
CACHE Digests
CACHE Digests
RUSSIAN DOLL
Russian Doll
Russian Doll <% cache(cache_key_for_attendees) do %> All available attendees: <%
Attendee.all.each do |a| %> <% cache(a) do %> <p><%= a.name %></p> <% end %> <% end %> <% end %>
KNOWING IS NOT ENOUGH WE MUST APPLY
WILLING IS NOT ENOUGH WE MUST DO