SlideShare una empresa de Scribd logo
1 de 43
Rails Performance
Tricks and Treats
     Marshall Yount
      Yount Labs
Everything I
really need to
 know about
     code
optimization I
  learned by
playing Quake
The Big Picture

• What is Performance?
• How do we know we’re performant?
• What tools do we use?
• How do we fix problems?
• Demonstration
Different ways of
looking at performance

• Client perceived
• Server
Client

                                                      • slow loading
                                                        web page
                                                        (latency)
                                                      • slow executing
                                                        webpage
                                                        (javascript/css)


http://www.flickr.com/photos/7423510@N06/2984486385/
The Enemy




 Latency: It’s a bitch
The Enemy




http://www.flickr.com/photos/peterhaza/3492771467/



           Latency: It’s a bitch
Diagnostic Tools
         (Client)
• Firebug
• YSlow
• PageSpeed
• UserTime
Diagnostic Tools
         (Client)
• Firebug
• YSlow
• PageSpeed
• UserTime
Diagnostic Tools
        (Client)
• Firebug
• YSlow
• PageSpeed
• UserTime
Diagnostic Tools
        (Client)
• Firebug
• YSlow
• PageSpeed
• UserTime
Reducing Roundtrips

• CSS Sprites
• CSS Data URIs
  • Jammit
• Rails *_link_tag

                     http://www.flickr.com/photos/mezzoblue/3217540317/
Reducing Roundtrips

• CSS Sprites        ul.checklist li.complete { margin-left: 20px; background:


• CSS Data URIs       url('data:image/
                     png;base64,AAAAFGGFyjOXZtQAAAAAElFT...')

  • Jammit            top left no-repeat; }

• Rails *_link_tag
Reducing Roundtrips

                     <%= stylesheet_link_tag "main", "nav",
•   CSS Sprites
                     "blog", :cache => “pagename_all” %>
•   CSS Data URIs
                     <link href="/stylesheets/
    •   Jammit       pagename_all.css?1234567890"
                     media="screen" rel="stylesheet"
• Rails *_link_tag   type="text/css" />
HTTP Hacking for Fun
     and Profit
• Off with her <HEAD>
• Expires:
• Last-Modified:
• ETag:
• Content-Encoding:
Server
• registers
• memory
• network
• database
• disk
• APIs
                 http://www.flickr.com/photos/buro9/298998011/
Infrastructure

• squid 2.7
• varnish
• memcached
• redis / resque
Top Clones

• top
• htop
• mytop
• memcache-top
Top Clones

• top
• htop
• mytop
• memcache-top
Top Clones

• top
• htop
• mytop
• memcache-top
Top Clones

• top
• htop
• mytop
• memcache-top
Monitoring -- free

• nagios
• cacti
• zabbix
• zenoss (core)
Monitoring -- free

• nagios
• cacti
• zabbix
• zenoss (core)
Monitoring -- free

• nagios
• cacti
• zabbix
• zenoss (core)
Monitoring -- free

• nagios
• cacti
• zabbix
• zenoss (core)
Monitoring -- paid

• Pingdom    Text
• NewRelic
• Scout
Monitoring -- paid

• Pingdom
• NewRelic
• Scout
Monitoring -- paid

• Pingdom
• NewRelic
• Scout
Fixing Problems

• Performance is a
  moving target!
• Horizontal/
  Vertical scaling


                     http://www.flickr.com/photos/tpapi/2765541278/
NewRelic Workflow
• Web Transactions
 • Most Time
    Consuming
 • Slowest
    Average
    Response Time
• Database
And the Number One
    Ruby on Rails
Performance Problem
        Is ...
And the Number One
    Ruby on Rails
Performance Problem
        Is ...
    N+1 Select
N+1 Select
   photos.each do |photo|
      puts photo.rating.id
      puts photo.user.email
      puts photo.camera.name
   end


How many queries does this execute?
N+1 Select
photos = Photo.find(:all, :include => [:rating, :user, :email])
              photos.each do |photo|
                 puts photo.rating.id
                 puts photo.user.email
                 puts photo.camera.name
              end


          How many queries does this execute?
Plugins/Gems

• bullet
• slim_scrooge
• query_reviewer
• ambitious_query_indexer
• ActiveRecord::Extensions
Still not fast enough for
            ya?
• ruby-prof
• memprof - where are objects being created
• change interpreters
 • ree -- gc.enable stats
 • jruby
 • ruby 1.9
Readings

•   Mark Nottingham’s HTTP caching tutorial

•              http://www.mnot.net/cache_docs/

•                    YSlow Best Practices

•      http://developer.yahoo.com/performance/rules.html

• http://delicious.com/marshall.yount/performance
Tools

• http://documentcloud.github.com/jammit/
• http://jeremy.zawodny.com/mysql/mytop/
• http://htop.sourceforge.net/
• http://code.google.com/p/memcache-top/
Appendix

• The following incomplete slides were
  suggested by audience members at the
  Dallas Ruby Brigade. I’ll be fleshing these
  out and adding them to a future version of
  the presentation.
Rails caching model
Template rendering
       pain
Database Model Fields

• wasteful data types
 • varchars
 •
Evented API calls

Más contenido relacionado

La actualidad más candente

Performance and scalability with drupal
Performance and scalability with drupalPerformance and scalability with drupal
Performance and scalability with drupal
Ronan Berder
 
jQuery Conference 2012 keynote
jQuery Conference 2012 keynotejQuery Conference 2012 keynote
jQuery Conference 2012 keynote
dmethvin
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
Avi Kedar
 

La actualidad más candente (20)

Performance and scalability with drupal
Performance and scalability with drupalPerformance and scalability with drupal
Performance and scalability with drupal
 
How NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscapeHow NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscape
 
Hadoop Demystified + Automation Smackdown! Austin JUG June 24 2014
Hadoop Demystified + Automation Smackdown!  Austin JUG June 24 2014Hadoop Demystified + Automation Smackdown!  Austin JUG June 24 2014
Hadoop Demystified + Automation Smackdown! Austin JUG June 24 2014
 
Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"
Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"
Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"
 
Modern javascript
Modern javascriptModern javascript
Modern javascript
 
Write Once, Run Everywhere - Ember.js Munich
Write Once, Run Everywhere - Ember.js MunichWrite Once, Run Everywhere - Ember.js Munich
Write Once, Run Everywhere - Ember.js Munich
 
Smooth Animations for Web & Hybrid
Smooth Animations for Web & HybridSmooth Animations for Web & Hybrid
Smooth Animations for Web & Hybrid
 
Flash And Dom
Flash And DomFlash And Dom
Flash And Dom
 
ClubAJAX Basics - Server Communication
ClubAJAX Basics - Server CommunicationClubAJAX Basics - Server Communication
ClubAJAX Basics - Server Communication
 
Webcomponents are your frameworks best friend
Webcomponents are your frameworks best friendWebcomponents are your frameworks best friend
Webcomponents are your frameworks best friend
 
Frameworks and webcomponents
Frameworks and webcomponentsFrameworks and webcomponents
Frameworks and webcomponents
 
Drupal8 + AngularJS
Drupal8 + AngularJSDrupal8 + AngularJS
Drupal8 + AngularJS
 
Irb Tips and Tricks
Irb Tips and TricksIrb Tips and Tricks
Irb Tips and Tricks
 
jQuery Conference 2012 keynote
jQuery Conference 2012 keynotejQuery Conference 2012 keynote
jQuery Conference 2012 keynote
 
Flexible UI Components for a Multi-Framework World
Flexible UI Components for a Multi-Framework WorldFlexible UI Components for a Multi-Framework World
Flexible UI Components for a Multi-Framework World
 
Becoming a more productive Rails Developer
Becoming a more productive Rails DeveloperBecoming a more productive Rails Developer
Becoming a more productive Rails Developer
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
 
In-house web automation?
In-house web automation?In-house web automation?
In-house web automation?
 
HTML5 History & Features
HTML5 History & FeaturesHTML5 History & Features
HTML5 History & Features
 
Testing your Single Page Application
Testing your Single Page ApplicationTesting your Single Page Application
Testing your Single Page Application
 

Similar a Rails Performance Tricks and Treats

Java scriptwidgetdevelopmentjstanbul2012
Java scriptwidgetdevelopmentjstanbul2012Java scriptwidgetdevelopmentjstanbul2012
Java scriptwidgetdevelopmentjstanbul2012
Volkan Özçelik
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your Website
Acquia
 
My site is slow
My site is slowMy site is slow
My site is slow
hernanibf
 
Inside Of Mbga Open Platform
Inside Of Mbga Open PlatformInside Of Mbga Open Platform
Inside Of Mbga Open Platform
Hideo Kimura
 

Similar a Rails Performance Tricks and Treats (20)

EscConf - Deep Dive Frontend Optimization
EscConf - Deep Dive Frontend OptimizationEscConf - Deep Dive Frontend Optimization
EscConf - Deep Dive Frontend Optimization
 
Rapid development with Rails
Rapid development with RailsRapid development with Rails
Rapid development with Rails
 
performance.ppt
performance.pptperformance.ppt
performance.ppt
 
Continuous Integration, the minimum viable product
Continuous Integration, the minimum viable productContinuous Integration, the minimum viable product
Continuous Integration, the minimum viable product
 
淺談 Startup 公司的軟體開發流程 v2
淺談 Startup 公司的軟體開發流程 v2淺談 Startup 公司的軟體開發流程 v2
淺談 Startup 公司的軟體開發流程 v2
 
Agile startup company management and operation
Agile startup company management and operationAgile startup company management and operation
Agile startup company management and operation
 
Java scriptwidgetdevelopmentjstanbul2012
Java scriptwidgetdevelopmentjstanbul2012Java scriptwidgetdevelopmentjstanbul2012
Java scriptwidgetdevelopmentjstanbul2012
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your Website
 
External JavaScript Widget Development Best Practices
External JavaScript Widget Development Best PracticesExternal JavaScript Widget Development Best Practices
External JavaScript Widget Development Best Practices
 
Choosing a JavaScript Framework
Choosing a JavaScript FrameworkChoosing a JavaScript Framework
Choosing a JavaScript Framework
 
Mobile web performance dwx13
Mobile web performance dwx13Mobile web performance dwx13
Mobile web performance dwx13
 
My Site is slow - Drupal Camp London 2013
My Site is slow - Drupal Camp London 2013My Site is slow - Drupal Camp London 2013
My Site is slow - Drupal Camp London 2013
 
Ship It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails EcosystemShip It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails Ecosystem
 
External JavaScript Widget Development Best Practices (updated) (v.1.1)
External JavaScript Widget Development Best Practices (updated) (v.1.1) External JavaScript Widget Development Best Practices (updated) (v.1.1)
External JavaScript Widget Development Best Practices (updated) (v.1.1)
 
My site is slow
My site is slowMy site is slow
My site is slow
 
Drupalmonitor.com - Drupal User Group Meetup Basel
Drupalmonitor.com - Drupal User Group Meetup BaselDrupalmonitor.com - Drupal User Group Meetup Basel
Drupalmonitor.com - Drupal User Group Meetup Basel
 
SCALE 10x Build a Cloud Day
SCALE 10x Build a Cloud DaySCALE 10x Build a Cloud Day
SCALE 10x Build a Cloud Day
 
Contributing to rails
Contributing to railsContributing to rails
Contributing to rails
 
DrupalSouth 2015 - Performance: Not an Afterthought
DrupalSouth 2015 - Performance: Not an AfterthoughtDrupalSouth 2015 - Performance: Not an Afterthought
DrupalSouth 2015 - Performance: Not an Afterthought
 
Inside Of Mbga Open Platform
Inside Of Mbga Open PlatformInside Of Mbga Open Platform
Inside Of Mbga Open Platform
 

Último

+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@
 

Último (20)

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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...
 
+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...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Rails Performance Tricks and Treats

Notas del editor

  1. Tell a nice little story about how I got into optimizations
  2. ASK: What is performance: take a survey group items on board between client and server metrics
  3. ASK: What are your favorite client tools
  4. ASK: What are your favorite server tools?
  5. ASK: What are some other infrastructure tools more tools here than you can shake a stick at.
  6. http://jeremy.zawodny.com/mysql/mytop/ http://htop.sourceforge.net/ http://code.google.com/p/memcache-top/
  7. http://jeremy.zawodny.com/mysql/mytop/ http://htop.sourceforge.net/ http://code.google.com/p/memcache-top/
  8. http://jeremy.zawodny.com/mysql/mytop/ http://htop.sourceforge.net/ http://code.google.com/p/memcache-top/
  9. Rack-a-mole
  10. check 37signals twitter and others for publicly posted gc settings