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
68
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
64
Ferramentas para CTO`s
cirdes
0
59
Aumentando O Poder Do Seu HTML Com AngularJS
cirdes
0
90
Getting Started with Angular.JS
cirdes
2
480
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
40
Other Decks in Programming
See All in Programming
競馬で学ぶ機械学習の基本と実践 / Machine Learning with Horse Racing
shoheimitani
14
14k
Full-Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
140
データファイルをAWSのDWHサービスに格納する / 20251115jawsug-tochigi
kasacchiful
2
100
AIを駆使して新しい技術を効率的に理解する方法
nogu66
1
670
Evolving NEWT’s TypeScript Backend for the AI-Driven Era
xpromx
0
200
[SF Ruby Conf 2025] Rails X
palkan
0
370
開発15年のAIネイティブでない 巨大サービスのAI最適化
rapicro
0
110
AIエージェントでのJava開発がはかどるMCPをAIを使って開発してみた / java mcp for jjug
kishida
4
800
海外登壇の心構え - コワクナイヨ - / how to prepare for a presentation abroad
kishida
2
100
しっかり学ぶ java.lang.*
nagise
1
460
AIと協働し、イベントソーシングとアクターモデルで作る後悔しないアーキテクチャ Regret-Free Architecture with AI, Event Sourcing, and Actors
tomohisa
2
10k
イベントストーミングのはじめかた / Getting Started with Event Storming
nrslib
1
750
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
Done Done
chrislema
186
16k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
Into the Great Unknown - MozCon
thekraken
40
2.2k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Mobile First: as difficult as doing things right
swwweet
225
10k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.6k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
350
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