Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Estratégias para tunar sua aplicação rails
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Cirdes
November 29, 2014
Programming
76
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
Transcript
56 slides
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
More Decks by Cirdes
See All by Cirdes
Testando aplicações Rails com Playwright
cirdes
0
70
Ferramentas para CTO`s
cirdes
0
68
Aumentando O Poder Do Seu HTML Com AngularJS
cirdes
0
99
Getting Started with Angular.JS
cirdes
2
510
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
55
Other Decks in Programming
See All in Programming
DroidKnights 2026 Android A2UI Jetpack Compose 기반의 안전한 AI UI 렌더링 - 박제창
itsmedreamwalker
1
230
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
180
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
130
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
570
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
160
AI時代のFlutter品質設計 — アプリ品質を守るQuality Layers
omatty198
0
380
エラーチャンネルのボールを拾い続けて鍛えるエンジニアの地力 / phpcon-niigata2026
meihei3
1
100
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
190
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
310
Getting Started with Vibe Coding
miccheng
0
220
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
310
ビジネスロジックを堅牢に~Scala 3のドメインプリミティブ~
j5ik2o
0
160
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.7k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Building an army of robots
kneath
307
47k
Crafting Experiences
bethany
1
440
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Highjacked: Video Game Concept Design
rkendrick25
PRO
2
570
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
300
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
460
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
A designer walks into a library…
pauljervisheath
211
25k
Building Adaptive Systems
keathley
44
3.3k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
121
130k