SlideShare a Scribd company logo
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
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 
Browser 
CDN Proxy
CACHE 
SERVER-SIDE 
CACHE 
CLIENT-SIDE
PAGE 
CACHE 
ACTION 
CACHE 
FRAGMENT 
CACHE 
RAILS 
CACHE
PAGE CACHE 
WRITE ON DISK 
BYPASS RAILS APPLICATION ENTIRE 
STATELESS PAGES 
NÃO FUNCIONA NO HEROKU
PAGE CACHE 
class WeblogController < ActionController::Base 
caches_page :show, :new 
def update 
expire_page action: 'show', id: params[:list][:id] 
end 
end
ACTION CACHE 
SIMILAR TO PAGE CACHE 
RUN FILTERS
ACTION CACHE 
class PostsController < ActionController::Base 
caches_action :show, expires_in: 1.hour 
end
DEPRECATED
FRAGMENT CACHE 
HTML CACHE AVAILABLE IN RAILS 4
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
 
 
 
 VIEWS/V1/ATTENDEES/1-20121220141922
 
 

More Related Content

What's hot

Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
The Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsThe Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web apps
John Anderson
 

What's hot (20)

Complex Sites with Silex
Complex Sites with SilexComplex Sites with Silex
Complex Sites with Silex
 
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
Developing apps using Perl
Developing apps using PerlDeveloping apps using Perl
Developing apps using Perl
 
Building Cloud Castles - LRUG
Building Cloud Castles - LRUGBuilding Cloud Castles - LRUG
Building Cloud Castles - LRUG
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Build a bot workshop async primer - php[tek]
Build a bot workshop  async primer - php[tek]Build a bot workshop  async primer - php[tek]
Build a bot workshop async primer - php[tek]
 
Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and others
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
 
Refactorización de aplicaciones PHP/Symfony2
Refactorización de aplicaciones PHP/Symfony2Refactorización de aplicaciones PHP/Symfony2
Refactorización de aplicaciones PHP/Symfony2
 
ZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async PrimerZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async Primer
 
Getting Started with Capistrano
Getting Started with CapistranoGetting Started with Capistrano
Getting Started with Capistrano
 
Capistrano - automate all the things
Capistrano - automate all the thingsCapistrano - automate all the things
Capistrano - automate all the things
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
Wykorzystanie form request przy implementacji API w Laravelu
Wykorzystanie form request przy implementacji API w LaraveluWykorzystanie form request przy implementacji API w Laravelu
Wykorzystanie form request przy implementacji API w Laravelu
 
Laravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php frameworkLaravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php framework
 
Intro to Silex
Intro to SilexIntro to Silex
Intro to Silex
 
The Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web appsThe Peanut Butter Cup of Web-dev: Plack and single page web apps
The Peanut Butter Cup of Web-dev: Plack and single page web apps
 
An introduction to Laravel Passport
An introduction to Laravel PassportAn introduction to Laravel Passport
An introduction to Laravel Passport
 

Viewers also liked

Performance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails Applications
Serge Smetana
 
หน่วยการวัดจริงๆ
หน่วยการวัดจริงๆหน่วยการวัดจริงๆ
หน่วยการวัดจริงๆ
yalay
 
Parts of the computer
Parts of the computerParts of the computer
Parts of the computer
maialen12
 
The Tory Emergency Budget - June 24th 2010
The Tory Emergency Budget - June 24th 2010The Tory Emergency Budget - June 24th 2010
The Tory Emergency Budget - June 24th 2010
UK Labour
 
The three little pigs
The three little pigsThe three little pigs
The three little pigs
guest27dc5af
 
หน่วยการวัดจริงๆ
หน่วยการวัดจริงๆหน่วยการวัดจริงๆ
หน่วยการวัดจริงๆ
yalay
 
หน่วยการวัดจริงๆ
หน่วยการวัดจริงๆหน่วยการวัดจริงๆ
หน่วยการวัดจริงๆ
yalay
 

Viewers also liked (19)

Performance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails Applications
 
Presentsti0n
 Presentsti0n Presentsti0n
Presentsti0n
 
หน่วยการวัดจริงๆ
หน่วยการวัดจริงๆหน่วยการวัดจริงๆ
หน่วยการวัดจริงๆ
 
Pueblosoriginarios y paisaje mmn 2016
Pueblosoriginarios y paisaje mmn 2016Pueblosoriginarios y paisaje mmn 2016
Pueblosoriginarios y paisaje mmn 2016
 
soldier
soldiersoldier
soldier
 
Parts of the computer
Parts of the computerParts of the computer
Parts of the computer
 
The Case Against Doctor Roth: Impact &amp; Implications
The Case Against Doctor Roth: Impact &amp; ImplicationsThe Case Against Doctor Roth: Impact &amp; Implications
The Case Against Doctor Roth: Impact &amp; Implications
 
Portfolio
PortfolioPortfolio
Portfolio
 
r
rr
r
 
Hillcrest power point
Hillcrest power pointHillcrest power point
Hillcrest power point
 
General Election Report 2010 - The organisational lessons
General Election Report 2010 - The organisational lessons General Election Report 2010 - The organisational lessons
General Election Report 2010 - The organisational lessons
 
Hillcrest pp
Hillcrest ppHillcrest pp
Hillcrest pp
 
Jurisdictional Determinations
Jurisdictional DeterminationsJurisdictional Determinations
Jurisdictional Determinations
 
The Tory Emergency Budget - June 24th 2010
The Tory Emergency Budget - June 24th 2010The Tory Emergency Budget - June 24th 2010
The Tory Emergency Budget - June 24th 2010
 
The three little pigs
The three little pigsThe three little pigs
The three little pigs
 
The new world of work: introduction
The new world of work: introductionThe new world of work: introduction
The new world of work: introduction
 
Resensi buku
Resensi bukuResensi buku
Resensi buku
 
หน่วยการวัดจริงๆ
หน่วยการวัดจริงๆหน่วยการวัดจริงๆ
หน่วยการวัดจริงๆ
 
หน่วยการวัดจริงๆ
หน่วยการวัดจริงๆหน่วยการวัดจริงๆ
หน่วยการวัดจริงๆ
 

Similar to Como construir uma Aplicação que consuma e produza updates no Twitter usando Python

RichFaces: rich:* component library
RichFaces: rich:* component libraryRichFaces: rich:* component library
RichFaces: rich:* component library
Max Katz
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
Tatsuhiko Miyagawa
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
Remy Sharp
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application Server
Phil Windley
 

Similar to Como construir uma Aplicação que consuma e produza updates no Twitter usando Python (20)

RichFaces: rich:* component library
RichFaces: rich:* component libraryRichFaces: rich:* component library
RichFaces: rich:* component library
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & sockets
 
What's new in Rails 4
What's new in Rails 4What's new in Rails 4
What's new in Rails 4
 
php & performance
 php & performance php & performance
php & performance
 
QConSP 2015 - Dicas de Performance para Aplicações Web
QConSP 2015 - Dicas de Performance para Aplicações WebQConSP 2015 - Dicas de Performance para Aplicações Web
QConSP 2015 - Dicas de Performance para Aplicações Web
 
Heavy Web Optimization: Backend
Heavy Web Optimization: BackendHeavy Web Optimization: Backend
Heavy Web Optimization: Backend
 
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
 
PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
Building Cloud Castles
Building Cloud CastlesBuilding Cloud Castles
Building Cloud Castles
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
 
Rails Page Caching
Rails Page CachingRails Page Caching
Rails Page Caching
 
Say YES to Premature Optimizations
Say YES to Premature OptimizationsSay YES to Premature Optimizations
Say YES to Premature Optimizations
 
HTML5: huh, what is it good for?
HTML5: huh, what is it good for?HTML5: huh, what is it good for?
HTML5: huh, what is it good for?
 
Cache is King
Cache is KingCache is King
Cache is King
 
Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2Ride on the Fast Track of Web with Ruby on Rails- Part 2
Ride on the Fast Track of Web with Ruby on Rails- Part 2
 
Tdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema RubyTdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema Ruby
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application Server
 
Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortal
 

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 

Como construir uma Aplicação que consuma e produza updates no Twitter usando Python