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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Cirdes
November 29, 2014
Programming
72
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Estratégias para tunar sua aplicação rails
Palestra na RuPy 2014
Cirdes
November 29, 2014
More Decks by Cirdes
See All by Cirdes
Testando aplicações Rails com Playwright
cirdes
0
65
Ferramentas para CTO`s
cirdes
0
62
Aumentando O Poder Do Seu HTML Com AngularJS
cirdes
0
94
Getting Started with Angular.JS
cirdes
2
500
Como desenvolver um produto escalável com uma linguagem: Nova, lente e insegura
cirdes
0
180
Boas práticas usando RSpec
cirdes
0
300
Como construir uma Aplicação que consuma e produza updates no Twitter usando Python.
cirdes
0
47
Other Decks in Programming
See All in Programming
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
0
100
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
220
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
490
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
170
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
8
4.1k
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
130
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
240
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
160
Contextとはなにか
chiroruxx
1
390
act1-costs.pdf
sumedhbala
0
210
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
180
Featured
See All Featured
Marketing to machines
jonoalderson
1
5.6k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
410
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
180
Six Lessons from altMBA
skipperchong
29
4.3k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
940
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
330
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
600
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
250
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