Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRails)

John McCaffrey
John McCaffreysoftware developer at Independent Consultant
Rails Performance John McCaffrey Railsperformance.blogspot.com
John McCaffrey: Its all about me ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],     @J_McCaffrey [email_address] (the slides will be available, with tons of extra references)
What are we gonna cover? ,[object Object],[object Object]
Measuring Page Load Fixing page load problems Analyzing Server Performance Database issues Ruby issues  Q&A Starting off on the right foot
It all started... def   organization_branches    get_organizations .flatten.uniq.select{|org| org.children.size > 0} end def   organization_leaves    get_organizations .flatten.uniq.select{|org| org.children.size == 0} end def   load_organizations      branches =  current_user .organization_branches      leaves =  current_user .organization_leaves      @branches  = branches.to_json(: only  => [:id, :name])      @leaves  = leaves.to_json(: only  => [:id, :name])      @organizations  =  @criteria .branch ?           leaves.collect {|o| [ o.name.titleize, o.id ] }.sort :           branches.collect {|o| [ o.name.titleize, o.id ] }.sort   end
def   organization_branches    get_organizations .flatten.uniq.select{|org| org.children.size > 0} end def   organization_leaves    get_organizations .flatten.uniq.select{|org| org.children.size == 0} end def   load_organizations      branches =  current_user .organization_branches      leaves =  current_user .organization_leaves      @branches  = branches.to_json(: only  => [:id, :name])      @leaves  = leaves.to_json(: only  => [:id, :name])      @organizations  =  @criteria .branch ?           leaves.collect {|o| [ o.name.titleize, o.id ] }.sort :           branches.collect {|o| [ o.name.titleize, o.id ] }.sort   end It all started... 2811 queries! Down to 17!!
And then... Invoicing issue:      If a customer resubmits an order with 2 years, they should be charged $9 but were only being charged $4.50 Do people ever calculate the ROI on software projects? 53626 * $4.50 = $241,317   (just in the last year)
Our theme of the day: Leverage Multiplying the power of your efforts,  to achieve the greatest value
Performance and Business metrics: Bing.com Slower site = revenue drop                            1 sec = 2.8%                2 sec = 4.3%               
Performance and Business metrics: Shopzilla.com http://www.phpied.com/the-performance-business-pitch/ Went from 6 sec down to 1.2sec
Fred Wilson: Speed is the most important feature ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
OK, so where do we begin?
Give yourself a fighting chance, make a plan  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Video on wiki.parleys.com
Premature optimization  "Premature optimization is the root of all evil" -Donald Knuth
Premature optimization  Some people really like Donald Knuth
Premature optimization, with DJ DK  like, really, really like him
Premature optimization  "Premature optimization is the root of all evil' -Donald Knuth "Quoting Knuth, as a way to avoid planning for performance issues, is a cop-out" @J_McCaffrey "Don't waste time on making optimization changes until you KNOW they are necessary"
If you can not measure it,  you can not improve it. — Lord Kelvin
Let's do this the right way ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Terminology Response time (avg)   ==   Latency Requests per second   ==  Throughput   Load : How much work is there?   Utilization : How much of the resources are in use?    Scalability : How well can we handle the load?   Throughput : How many tasks can be done per unit of time?    Concurrency : How many tasks can we do at once?    Capacity : How big can our throughput go before things fall apart?
Terminology ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Performance != Scalability
Terminology Let's say:           1 worker that can compute a job in .5 sec      Throughput    = 2 jobs per sec                Latency     = .5 sec per job Performance != Scalability Adding more workers will not improve the latency But not having enough workers can increase the response time, due to Queuing and delay
Resources: Things that we want to measure System Business Time Cpu Memory Network  Disk  Money  Development time QA and testing time User time
There are performance opportunities at each layer
Waterfall: Twitter.com Waterfall Total time: 3815 ms  Dynamic generation: 250 ms (~7%)  Static: 3369 ms (~89%)  * Will not add to 100% 
Waterfall When the backend is actually doing work
Walmart: Waterfall Waterfall Total time: 5520 ms  Dynamic generation: 388 ms (~7%)                                       Static: 4580 ms (~82%)
Firebug Netpanel Simple and repeatable way to measure page load Usually, less than 20% of the time is spent in fetching the HTML So how do we optimize the other 80%?
YSlow ,[object Object],[object Object],[object Object],[object Object],[object Object]
YSlow ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Yslow: Created by Steve Souders http://stevesouders.com/cuzillion/
Google Page speed ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Google Page speed
Google Page speed
Make it repeatable ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object]
Measuring Page Load Fixing page load problems Analyzing Server Performance Database issues Ruby issues  Q&A Starting off on the right foot
Isn't everyone already doing this? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Compress with Gzip ,[object Object],[object Object],[object Object],[object Object],Probably the simplest and smartest thing you can do for your app!
Combine and minify javascript and css ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Expires and Browser Caching Setting a far future expires tells the browser not to ask for the file Using the query string lets us break the caching by having the browser ask for a new file There is a problem with using a URL query string this way http://blog.eliotsykes.com/2010/05/06/why-rails-asset-caching-is-broken/
Rails Caching ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Measuring Page Load Fixing page load problems Analyzing Server Performance Database issues Ruby issues  Q&A Starting off on the right foot
The Stack You are here
Request-log-analyzer •  http://github.com/wvanbergen/request-log-analyzer •  Request distribution per hour •  Most requested •  HTTP methods •  HTTP statuses returned •  Rails action cache hits •  Request duration •  View rendering time •  Database time •  Process blockers •  Failed requests
Rack::Bug
Rack::Bug
Commercial tools ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Testing tools Apache bench   ab -n 10 -c 2 http://www.somewhere.com/  Httperf httperf --server localhost --port 3000 --uri / --num-conns 10000 Jmeter yes, its ugly, but its powerful
Measuring Page Load Fixing page load problems Analyzing Server Performance Database issues Ruby issues  Q&A Starting off on the right foot
Database issues ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Query_reviewer ,[object Object],[object Object],[object Object],[object Object],[object Object]
Rails_indexes http://github.com/eladmeidar/rails_indexes Foreign key indexs •  Columns that need to be sorted •  Lookup fields •  Columns that are used in a GROUP BY •  Rake tasks to find missing indexes. New one I haven’t tried yet http:// github.com/samdanavia/ambitious_query_indexer
Bullet plugin Bullet plugin •  http://github.com/flyerhzm/bullet Help you reduce the number of queries with alerts (and growl).
Slim_scrooge ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Ruby Issues ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Ruby issues: Faster Ruby Libraries C Extension++ •  XML parser  http://nokogiri.org/ •  JSON parser http://github.com/brianmario/yajl-ruby/ •  CSV parser http://www.toastyapps.com/excelsior/ •  HTTP client  http://github.com/pauldix/typhoeus Date http:// github.com/jeremyevans/home_run
Take home points ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Links: great info on performance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Links Questions? @j_mccaffrey [email_address]
Beyond ySlow: improving page performance outside the initial load MySql and Postgres Database tuning Heroku: Building Scalable apps from the start Tuning performance for Mobile devices Performance Improvements coming in Rails 3, and 3.1 Speeding up your tests
Wait, I made it through that? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Wait, I made it through that? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Questions for you ,[object Object],[object Object],[object Object],[object Object]
1 of 64

Recommended

PDF Generation in Rails with Prawn and Prawn-to: John McCaffrey by
PDF Generation in Rails with Prawn and Prawn-to: John McCaffreyPDF Generation in Rails with Prawn and Prawn-to: John McCaffrey
PDF Generation in Rails with Prawn and Prawn-to: John McCaffreyJohn McCaffrey
15.2K views51 slides
Web Performance Madness - brightonSEO 2018 by
Web Performance Madness - brightonSEO 2018Web Performance Madness - brightonSEO 2018
Web Performance Madness - brightonSEO 2018Bastian Grimm
17.7K views45 slides
Super speed around the globe - SearchLeeds 2018 by
Super speed around the globe - SearchLeeds 2018Super speed around the globe - SearchLeeds 2018
Super speed around the globe - SearchLeeds 2018Bastian Grimm
7.8K views86 slides
Optimizing the critical rendering path meta refresh 2015 by
Optimizing the critical rendering path   meta refresh 2015Optimizing the critical rendering path   meta refresh 2015
Optimizing the critical rendering path meta refresh 2015Brameshmadhav S
503 views30 slides
The need for Speed: Advanced #webperf - SEOday 2018 by
The need for Speed: Advanced #webperf - SEOday 2018The need for Speed: Advanced #webperf - SEOday 2018
The need for Speed: Advanced #webperf - SEOday 2018Bastian Grimm
3.4K views84 slides
M is for modernization by
M is for modernizationM is for modernization
M is for modernizationRed Pill Now
710 views153 slides

More Related Content

What's hot

TechSEO Boost 2018: Implementing Hreflang on Legacy Tech Stacks Using Service... by
TechSEO Boost 2018: Implementing Hreflang on Legacy Tech Stacks Using Service...TechSEO Boost 2018: Implementing Hreflang on Legacy Tech Stacks Using Service...
TechSEO Boost 2018: Implementing Hreflang on Legacy Tech Stacks Using Service...Catalyst
1.3K views23 slides
Optimizing web performance (Fronteers edition) by
Optimizing web performance (Fronteers edition)Optimizing web performance (Fronteers edition)
Optimizing web performance (Fronteers edition)Dave Olsen
7.4K views67 slides
The PRPL Pattern by
The PRPL PatternThe PRPL Pattern
The PRPL PatternRed Pill Now
927 views79 slides
Frappe Open Day - September 2018 by
Frappe Open Day - September 2018Frappe Open Day - September 2018
Frappe Open Day - September 2018Frappe Technologies Pvt. Ltd.
407 views176 slides
Performance in business terms by
Performance in business termsPerformance in business terms
Performance in business termsStrangeloop
1.1K views122 slides
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup by
Web Performance, Scalability, and Testing Techniques - Boston PHP MeetupWeb Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP MeetupJonathan Klein
2.6K views81 slides

What's hot(20)

TechSEO Boost 2018: Implementing Hreflang on Legacy Tech Stacks Using Service... by Catalyst
TechSEO Boost 2018: Implementing Hreflang on Legacy Tech Stacks Using Service...TechSEO Boost 2018: Implementing Hreflang on Legacy Tech Stacks Using Service...
TechSEO Boost 2018: Implementing Hreflang on Legacy Tech Stacks Using Service...
Catalyst1.3K views
Optimizing web performance (Fronteers edition) by Dave Olsen
Optimizing web performance (Fronteers edition)Optimizing web performance (Fronteers edition)
Optimizing web performance (Fronteers edition)
Dave Olsen7.4K views
Performance in business terms by Strangeloop
Performance in business termsPerformance in business terms
Performance in business terms
Strangeloop1.1K views
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup by Jonathan Klein
Web Performance, Scalability, and Testing Techniques - Boston PHP MeetupWeb Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Jonathan Klein2.6K views
Cache is keeping you from reaching the full potential as a developer (word ca... by Thomas Audunhus
Cache is keeping you from reaching the full potential as a developer (word ca...Cache is keeping you from reaching the full potential as a developer (word ca...
Cache is keeping you from reaching the full potential as a developer (word ca...
Thomas Audunhus333 views
Speed kills by Josh Ward
Speed killsSpeed kills
Speed kills
Josh Ward913 views
Optimus XPages: An Explosion of Techniques and Best Practices by Teamstudio
Optimus XPages: An Explosion of Techniques and Best PracticesOptimus XPages: An Explosion of Techniques and Best Practices
Optimus XPages: An Explosion of Techniques and Best Practices
Teamstudio3.4K views
WordPress&映像配信セミナー+さぶみっと!オフ会- 第2回 さぶみっと! WEB制作セミナー Supported by NTTスマートコネクト by Hiromichi Koga
WordPress&映像配信セミナー+さぶみっと!オフ会- 第2回 さぶみっと! WEB制作セミナー Supported by NTTスマートコネクトWordPress&映像配信セミナー+さぶみっと!オフ会- 第2回 さぶみっと! WEB制作セミナー Supported by NTTスマートコネクト
WordPress&映像配信セミナー+さぶみっと!オフ会- 第2回 さぶみっと! WEB制作セミナー Supported by NTTスマートコネクト
Hiromichi Koga868 views
An Introduction to Web Components by Red Pill Now
An Introduction to Web ComponentsAn Introduction to Web Components
An Introduction to Web Components
Red Pill Now1.4K views
[@IndeedEng] Redundant Array of Inexpensive Datacenters by indeedeng
[@IndeedEng] Redundant Array of Inexpensive Datacenters[@IndeedEng] Redundant Array of Inexpensive Datacenters
[@IndeedEng] Redundant Array of Inexpensive Datacenters
indeedeng5.3K views
How webpage loading takes place? by Abhishek Mitra
How webpage loading takes place?How webpage loading takes place?
How webpage loading takes place?
Abhishek Mitra94 views
[@IndeedEng] Boxcar: A self-balancing distributed services protocol by indeedeng
[@IndeedEng] Boxcar: A self-balancing distributed services protocol [@IndeedEng] Boxcar: A self-balancing distributed services protocol
[@IndeedEng] Boxcar: A self-balancing distributed services protocol
indeedeng14.9K views

Similar to Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRails)

Cvcc performance tuning by
Cvcc performance tuningCvcc performance tuning
Cvcc performance tuningJohn McCaffrey
951 views65 slides
Csdn Drdobbs Tenni Theurer Yahoo by
Csdn Drdobbs Tenni Theurer YahooCsdn Drdobbs Tenni Theurer Yahoo
Csdn Drdobbs Tenni Theurer Yahooguestb1b95b
4.3K views65 slides
Make Drupal Run Fast - increase page load speed by
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedAndy Kucharski
14.5K views45 slides
Magento performancenbs by
Magento performancenbsMagento performancenbs
Magento performancenbsvarien
432 views23 slides
Applying a Methodical Approach to Website Performance by
Applying a Methodical Approach to Website PerformanceApplying a Methodical Approach to Website Performance
Applying a Methodical Approach to Website PerformancePostSharp Technologies
539 views25 slides
2019 StartIT - Boosting your performance with Blackfire by
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with BlackfireMarko Mitranić
26 views79 slides

Similar to Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRails)(20)

Csdn Drdobbs Tenni Theurer Yahoo by guestb1b95b
Csdn Drdobbs Tenni Theurer YahooCsdn Drdobbs Tenni Theurer Yahoo
Csdn Drdobbs Tenni Theurer Yahoo
guestb1b95b4.3K views
Make Drupal Run Fast - increase page load speed by Andy Kucharski
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speed
Andy Kucharski14.5K views
Magento performancenbs by varien
Magento performancenbsMagento performancenbs
Magento performancenbs
varien432 views
2019 StartIT - Boosting your performance with Blackfire by Marko Mitranić
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire
Marko Mitranić26 views
MeasureWorks - Why people hate to wait for your website to load (and how to f... by MeasureWorks
MeasureWorks - Why people hate to wait for your website to load (and how to f...MeasureWorks - Why people hate to wait for your website to load (and how to f...
MeasureWorks - Why people hate to wait for your website to load (and how to f...
MeasureWorks2.3K views
Shopzilla - Performance By Design by Tim Morrow
Shopzilla - Performance By DesignShopzilla - Performance By Design
Shopzilla - Performance By Design
Tim Morrow11.6K views
Drupal Performance : DrupalCamp North by Philip Norton
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp North
Philip Norton1.7K views
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines by Tikal Knowledge
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
Tikal Knowledge4.7K views
Web Performance & You - HighEdWeb Arkansas Version by Dave Olsen
Web Performance & You - HighEdWeb Arkansas VersionWeb Performance & You - HighEdWeb Arkansas Version
Web Performance & You - HighEdWeb Arkansas Version
Dave Olsen16.8K views
Intro To Django by Udi Bauman
Intro To DjangoIntro To Django
Intro To Django
Udi Bauman2.6K views
High Performance Websites By Souders Steve by w3guru
High Performance Websites By Souders SteveHigh Performance Websites By Souders Steve
High Performance Websites By Souders Steve
w3guru3.7K views
Plop by oakleaf
PlopPlop
Plop
oakleaf1.2K views
High Performance Web Sites by Páris Neto
High Performance Web SitesHigh Performance Web Sites
High Performance Web Sites
Páris Neto1.5K views
Mobile User Experience: Auto Drive through Performance Metrics by Andreas Grabner
Mobile User Experience:Auto Drive through Performance MetricsMobile User Experience:Auto Drive through Performance Metrics
Mobile User Experience: Auto Drive through Performance Metrics
Andreas Grabner1.3K views
Os Souders by oscon2007
Os SoudersOs Souders
Os Souders
oscon2007544 views

More from John McCaffrey

John's Sample by
John's SampleJohn's Sample
John's SampleJohn McCaffrey
390 views4 slides
A Taste of TDD: The basics of TDD, why it is hard and how to do it better by
A Taste of TDD: The basics of TDD, why it is hard and how to do it betterA Taste of TDD: The basics of TDD, why it is hard and how to do it better
A Taste of TDD: The basics of TDD, why it is hard and how to do it betterJohn McCaffrey
926 views60 slides
Becoming a more Productive Rails Developer by
Becoming a more Productive Rails DeveloperBecoming a more Productive Rails Developer
Becoming a more Productive Rails DeveloperJohn McCaffrey
4.6K views54 slides
LeanStartup:Research is cheaper than development by
LeanStartup:Research is cheaper than developmentLeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than developmentJohn McCaffrey
1K views43 slides
Becoming a more productive Rails Developer by
Becoming a more productive Rails DeveloperBecoming a more productive Rails Developer
Becoming a more productive Rails DeveloperJohn McCaffrey
794 views54 slides
Cloud tools by
Cloud toolsCloud tools
Cloud toolsJohn McCaffrey
1.1K views25 slides

More from John McCaffrey(11)

A Taste of TDD: The basics of TDD, why it is hard and how to do it better by John McCaffrey
A Taste of TDD: The basics of TDD, why it is hard and how to do it betterA Taste of TDD: The basics of TDD, why it is hard and how to do it better
A Taste of TDD: The basics of TDD, why it is hard and how to do it better
John McCaffrey926 views
Becoming a more Productive Rails Developer by John McCaffrey
Becoming a more Productive Rails DeveloperBecoming a more Productive Rails Developer
Becoming a more Productive Rails Developer
John McCaffrey4.6K views
LeanStartup:Research is cheaper than development by John McCaffrey
LeanStartup:Research is cheaper than developmentLeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than development
John McCaffrey1K views
Becoming a more productive Rails Developer by John McCaffrey
Becoming a more productive Rails DeveloperBecoming a more productive Rails Developer
Becoming a more productive Rails Developer
John McCaffrey794 views
Windycityrails page performance by John McCaffrey
Windycityrails page performanceWindycityrails page performance
Windycityrails page performance
John McCaffrey2.9K views
Freelancing and side-projects on Rails by John McCaffrey
Freelancing and side-projects on RailsFreelancing and side-projects on Rails
Freelancing and side-projects on Rails
John McCaffrey1.4K views
Windy cityrails performance_tuning by John McCaffrey
Windy cityrails performance_tuningWindy cityrails performance_tuning
Windy cityrails performance_tuning
John McCaffrey1.7K views
improving the performance of Rails web Applications by John McCaffrey
improving the performance of Rails web Applicationsimproving the performance of Rails web Applications
improving the performance of Rails web Applications
John McCaffrey1.6K views

Recently uploaded

Democratising digital commerce in India-Report by
Democratising digital commerce in India-ReportDemocratising digital commerce in India-Report
Democratising digital commerce in India-ReportKapil Khandelwal (KK)
15 views161 slides
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...Jasper Oosterveld
18 views49 slides
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensorssugiuralab
19 views15 slides
Special_edition_innovator_2023.pdf by
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdfWillDavies22
17 views6 slides
Network Source of Truth and Infrastructure as Code revisited by
Network Source of Truth and Infrastructure as Code revisitedNetwork Source of Truth and Infrastructure as Code revisited
Network Source of Truth and Infrastructure as Code revisitedNetwork Automation Forum
26 views45 slides

Recently uploaded(20)

ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2217 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker37 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri16 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi127 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software263 views
Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada136 views
handbook for web 3 adoption.pdf by Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex22 views
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 views

Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRails)

  • 1. Rails Performance John McCaffrey Railsperformance.blogspot.com
  • 2.
  • 3.
  • 4. Measuring Page Load Fixing page load problems Analyzing Server Performance Database issues Ruby issues  Q&A Starting off on the right foot
  • 5. It all started... def organization_branches    get_organizations .flatten.uniq.select{|org| org.children.size > 0} end def organization_leaves    get_organizations .flatten.uniq.select{|org| org.children.size == 0} end def load_organizations      branches = current_user .organization_branches      leaves = current_user .organization_leaves      @branches = branches.to_json(: only => [:id, :name])      @leaves = leaves.to_json(: only => [:id, :name])      @organizations = @criteria .branch ?           leaves.collect {|o| [ o.name.titleize, o.id ] }.sort :           branches.collect {|o| [ o.name.titleize, o.id ] }.sort   end
  • 6. def organization_branches    get_organizations .flatten.uniq.select{|org| org.children.size > 0} end def organization_leaves    get_organizations .flatten.uniq.select{|org| org.children.size == 0} end def load_organizations      branches = current_user .organization_branches      leaves = current_user .organization_leaves      @branches = branches.to_json(: only => [:id, :name])      @leaves = leaves.to_json(: only => [:id, :name])      @organizations = @criteria .branch ?           leaves.collect {|o| [ o.name.titleize, o.id ] }.sort :           branches.collect {|o| [ o.name.titleize, o.id ] }.sort   end It all started... 2811 queries! Down to 17!!
  • 7. And then... Invoicing issue:      If a customer resubmits an order with 2 years, they should be charged $9 but were only being charged $4.50 Do people ever calculate the ROI on software projects? 53626 * $4.50 = $241,317   (just in the last year)
  • 8. Our theme of the day: Leverage Multiplying the power of your efforts,  to achieve the greatest value
  • 9. Performance and Business metrics: Bing.com Slower site = revenue drop                            1 sec = 2.8%                2 sec = 4.3%               
  • 10. Performance and Business metrics: Shopzilla.com http://www.phpied.com/the-performance-business-pitch/ Went from 6 sec down to 1.2sec
  • 11.
  • 12. OK, so where do we begin?
  • 13.
  • 14. Premature optimization "Premature optimization is the root of all evil" -Donald Knuth
  • 15. Premature optimization Some people really like Donald Knuth
  • 16. Premature optimization, with DJ DK like, really, really like him
  • 17. Premature optimization "Premature optimization is the root of all evil' -Donald Knuth "Quoting Knuth, as a way to avoid planning for performance issues, is a cop-out" @J_McCaffrey "Don't waste time on making optimization changes until you KNOW they are necessary"
  • 18. If you can not measure it,  you can not improve it. — Lord Kelvin
  • 19.
  • 20. Terminology Response time (avg)   ==   Latency Requests per second   ==  Throughput   Load : How much work is there?   Utilization : How much of the resources are in use?   Scalability : How well can we handle the load?   Throughput : How many tasks can be done per unit of time?   Concurrency : How many tasks can we do at once?   Capacity : How big can our throughput go before things fall apart?
  • 21.
  • 22. Terminology Let's say:           1 worker that can compute a job in .5 sec      Throughput    = 2 jobs per sec               Latency     = .5 sec per job Performance != Scalability Adding more workers will not improve the latency But not having enough workers can increase the response time, due to Queuing and delay
  • 23. Resources: Things that we want to measure System Business Time Cpu Memory Network  Disk Money Development time QA and testing time User time
  • 24. There are performance opportunities at each layer
  • 25. Waterfall: Twitter.com Waterfall Total time: 3815 ms Dynamic generation: 250 ms (~7%) Static: 3369 ms (~89%) * Will not add to 100% 
  • 26. Waterfall When the backend is actually doing work
  • 27. Walmart: Waterfall Waterfall Total time: 5520 ms Dynamic generation: 388 ms (~7%)                                       Static: 4580 ms (~82%)
  • 28. Firebug Netpanel Simple and repeatable way to measure page load Usually, less than 20% of the time is spent in fetching the HTML So how do we optimize the other 80%?
  • 29.
  • 30.
  • 31. Yslow: Created by Steve Souders http://stevesouders.com/cuzillion/
  • 32.
  • 35.
  • 36.
  • 37. Measuring Page Load Fixing page load problems Analyzing Server Performance Database issues Ruby issues  Q&A Starting off on the right foot
  • 38.
  • 39.
  • 40.
  • 41. Expires and Browser Caching Setting a far future expires tells the browser not to ask for the file Using the query string lets us break the caching by having the browser ask for a new file There is a problem with using a URL query string this way http://blog.eliotsykes.com/2010/05/06/why-rails-asset-caching-is-broken/
  • 42.
  • 43. Measuring Page Load Fixing page load problems Analyzing Server Performance Database issues Ruby issues  Q&A Starting off on the right foot
  • 44. The Stack You are here
  • 45. Request-log-analyzer • http://github.com/wvanbergen/request-log-analyzer • Request distribution per hour • Most requested • HTTP methods • HTTP statuses returned • Rails action cache hits • Request duration • View rendering time • Database time • Process blockers • Failed requests
  • 48.
  • 49. Testing tools Apache bench   ab -n 10 -c 2 http://www.somewhere.com/ Httperf httperf --server localhost --port 3000 --uri / --num-conns 10000 Jmeter yes, its ugly, but its powerful
  • 50. Measuring Page Load Fixing page load problems Analyzing Server Performance Database issues Ruby issues  Q&A Starting off on the right foot
  • 51.
  • 52.
  • 53. Rails_indexes http://github.com/eladmeidar/rails_indexes Foreign key indexs • Columns that need to be sorted • Lookup fields • Columns that are used in a GROUP BY • Rake tasks to find missing indexes. New one I haven’t tried yet http:// github.com/samdanavia/ambitious_query_indexer
  • 54. Bullet plugin Bullet plugin • http://github.com/flyerhzm/bullet Help you reduce the number of queries with alerts (and growl).
  • 55.
  • 56.
  • 57. Ruby issues: Faster Ruby Libraries C Extension++ • XML parser http://nokogiri.org/ • JSON parser http://github.com/brianmario/yajl-ruby/ • CSV parser http://www.toastyapps.com/excelsior/ • HTTP client http://github.com/pauldix/typhoeus Date http:// github.com/jeremyevans/home_run
  • 58.
  • 59.
  • 60. Links Questions? @j_mccaffrey [email_address]
  • 61. Beyond ySlow: improving page performance outside the initial load MySql and Postgres Database tuning Heroku: Building Scalable apps from the start Tuning performance for Mobile devices Performance Improvements coming in Rails 3, and 3.1 Speeding up your tests
  • 62.
  • 63.
  • 64.