SlideShare une entreprise Scribd logo
1  sur  56
Télécharger pour lire hors ligne
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
 
 

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

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
 

En vedette (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
 
หน่วยการวัดจริงๆ
หน่วยการวัดจริงๆหน่วยการวัดจริงๆ
หน่วยการวัดจริงๆ
 
หน่วยการวัดจริงๆ
หน่วยการวัดจริงๆหน่วยการวัดจริงๆ
หน่วยการวัดจริงๆ
 

Similaire à 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
 

Similaire à 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
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

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