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

Contenu connexe

Tendances

Untangling spring week11
Untangling spring week11Untangling spring week11
Untangling spring week11Derek Jacoby
 
Modern javascript
Modern javascriptModern javascript
Modern javascriptKevin Ball
 
Recipes for the Perfect PI v2.0
Recipes for the Perfect PI v2.0Recipes for the Perfect PI v2.0
Recipes for the Perfect PI v2.0Sascha Wenninger
 
A Look at the Performance of SAP's Modern UIs
A Look at the Performance of SAP's Modern UIsA Look at the Performance of SAP's Modern UIs
A Look at the Performance of SAP's Modern UIsSascha Wenninger
 
My Website Can Vote - The Challenges of Maintaining a 20-year-old Website
My Website Can Vote - The Challenges of Maintaining a 20-year-old WebsiteMy Website Can Vote - The Challenges of Maintaining a 20-year-old Website
My Website Can Vote - The Challenges of Maintaining a 20-year-old WebsiteKristine Howard
 
10 Things You Can Do to Speed Up Your Web App Today
10 Things You Can Do to Speed Up Your Web App Today10 Things You Can Do to Speed Up Your Web App Today
10 Things You Can Do to Speed Up Your Web App TodayChris Love
 
Scalability vs. Performance
Scalability vs. PerformanceScalability vs. Performance
Scalability vs. PerformanceSergeyChernyshev
 
Rails Performance Tricks and Treats
Rails Performance Tricks and TreatsRails Performance Tricks and Treats
Rails Performance Tricks and TreatsMarshall Yount
 
The Dawson Way of Doing Things: A Study of Our Path Using WordPress
The Dawson Way of Doing Things: A Study of Our Path Using WordPressThe Dawson Way of Doing Things: A Study of Our Path Using WordPress
The Dawson Way of Doing Things: A Study of Our Path Using WordPressJonathan Perlman
 
Single page applications the basics
Single page applications the basicsSingle page applications the basics
Single page applications the basicsChris Love
 
Ruby performance - The low hanging fruit
Ruby performance - The low hanging fruitRuby performance - The low hanging fruit
Ruby performance - The low hanging fruitBruce Werdschinski
 
Web Cache Deception Attack
Web Cache Deception AttackWeb Cache Deception Attack
Web Cache Deception AttackOmer Gil
 
Untangling - fall2017 - week 8
Untangling - fall2017 - week 8Untangling - fall2017 - week 8
Untangling - fall2017 - week 8Derek Jacoby
 
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 WorldKevin Ball
 
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...Geoff Varosky
 
Avoiding integration hell
Avoiding integration hellAvoiding integration hell
Avoiding integration hellaaronbassett
 
In-house web automation?
In-house web automation?In-house web automation?
In-house web automation?Adam Christian
 
WordPress APIs
WordPress APIsWordPress APIs
WordPress APIsmdawaffe
 
Untangling spring week6
Untangling spring week6Untangling spring week6
Untangling spring week6Derek Jacoby
 

Tendances (20)

Untangling spring week11
Untangling spring week11Untangling spring week11
Untangling spring week11
 
Modern javascript
Modern javascriptModern javascript
Modern javascript
 
Recipes for the Perfect PI v2.0
Recipes for the Perfect PI v2.0Recipes for the Perfect PI v2.0
Recipes for the Perfect PI v2.0
 
A Look at the Performance of SAP's Modern UIs
A Look at the Performance of SAP's Modern UIsA Look at the Performance of SAP's Modern UIs
A Look at the Performance of SAP's Modern UIs
 
My Website Can Vote - The Challenges of Maintaining a 20-year-old Website
My Website Can Vote - The Challenges of Maintaining a 20-year-old WebsiteMy Website Can Vote - The Challenges of Maintaining a 20-year-old Website
My Website Can Vote - The Challenges of Maintaining a 20-year-old Website
 
10 Things You Can Do to Speed Up Your Web App Today
10 Things You Can Do to Speed Up Your Web App Today10 Things You Can Do to Speed Up Your Web App Today
10 Things You Can Do to Speed Up Your Web App Today
 
Scalability vs. Performance
Scalability vs. PerformanceScalability vs. Performance
Scalability vs. Performance
 
Rails Performance Tricks and Treats
Rails Performance Tricks and TreatsRails Performance Tricks and Treats
Rails Performance Tricks and Treats
 
The Dawson Way of Doing Things: A Study of Our Path Using WordPress
The Dawson Way of Doing Things: A Study of Our Path Using WordPressThe Dawson Way of Doing Things: A Study of Our Path Using WordPress
The Dawson Way of Doing Things: A Study of Our Path Using WordPress
 
Single page applications the basics
Single page applications the basicsSingle page applications the basics
Single page applications the basics
 
Ruby performance - The low hanging fruit
Ruby performance - The low hanging fruitRuby performance - The low hanging fruit
Ruby performance - The low hanging fruit
 
Web Cache Deception Attack
Web Cache Deception AttackWeb Cache Deception Attack
Web Cache Deception Attack
 
Untangling - fall2017 - week 8
Untangling - fall2017 - week 8Untangling - fall2017 - week 8
Untangling - fall2017 - week 8
 
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
 
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
Best Practices in SharePoint Development - Just Freakin Work! Overcoming Hurd...
 
Avoiding integration hell
Avoiding integration hellAvoiding integration hell
Avoiding integration hell
 
A Day of REST
A Day of RESTA Day of REST
A Day of REST
 
In-house web automation?
In-house web automation?In-house web automation?
In-house web automation?
 
WordPress APIs
WordPress APIsWordPress APIs
WordPress APIs
 
Untangling spring week6
Untangling spring week6Untangling spring week6
Untangling spring week6
 

Similaire à Windy cityrails performance_tuning

Csdn Drdobbs Tenni Theurer Yahoo
Csdn Drdobbs Tenni Theurer YahooCsdn Drdobbs Tenni Theurer Yahoo
Csdn Drdobbs Tenni Theurer Yahooguestb1b95b
 
Make Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedAndy Kucharski
 
Magento performancenbs
Magento performancenbsMagento performancenbs
Magento performancenbsvarien
 
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
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
 
Applying a Methodical Approach to Website Performance
Applying a Methodical Approach to Website PerformanceApplying a Methodical Approach to Website Performance
Applying a Methodical Approach to Website PerformancePostSharp Technologies
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with BlackfireMarko Mitranić
 
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...
MeasureWorks - Why people hate to wait for your website to load (and how to f...MeasureWorks
 
Shopzilla - Performance By Design
Shopzilla - Performance By DesignShopzilla - Performance By Design
Shopzilla - Performance By DesignTim Morrow
 
Drupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthPhilip Norton
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
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 DeadlinesTikal Knowledge
 
Web Performance & You - HighEdWeb Arkansas Version
Web Performance & You - HighEdWeb Arkansas VersionWeb Performance & You - HighEdWeb Arkansas Version
Web Performance & You - HighEdWeb Arkansas VersionDave Olsen
 
Intro To Django
Intro To DjangoIntro To Django
Intro To DjangoUdi Bauman
 
High Performance Web Sites
High Performance Web SitesHigh Performance Web Sites
High Performance Web SitesPáris Neto
 
High Performance Websites By Souders Steve
High Performance Websites By Souders SteveHigh Performance Websites By Souders Steve
High Performance Websites By Souders Stevew3guru
 
Mobile User Experience: Auto Drive through Performance Metrics
Mobile User Experience:Auto Drive through Performance MetricsMobile User Experience:Auto Drive through Performance Metrics
Mobile User Experience: Auto Drive through Performance MetricsAndreas Grabner
 
Our application got popular and now it breaks
Our application got popular and now it breaksOur application got popular and now it breaks
Our application got popular and now it breaksColdFusionConference
 

Similaire à Windy cityrails performance_tuning (20)

Csdn Drdobbs Tenni Theurer Yahoo
Csdn Drdobbs Tenni Theurer YahooCsdn Drdobbs Tenni Theurer Yahoo
Csdn Drdobbs Tenni Theurer Yahoo
 
Make Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speed
 
Magento performancenbs
Magento performancenbsMagento performancenbs
Magento performancenbs
 
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
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
 
Applying a Methodical Approach to Website Performance
Applying a Methodical Approach to Website PerformanceApplying a Methodical Approach to Website Performance
Applying a Methodical Approach to Website Performance
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire
 
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...
MeasureWorks - Why people hate to wait for your website to load (and how to f...
 
Web Performance Optimization (WPO)
Web Performance Optimization (WPO)Web Performance Optimization (WPO)
Web Performance Optimization (WPO)
 
Shopzilla - Performance By Design
Shopzilla - Performance By DesignShopzilla - Performance By Design
Shopzilla - Performance By Design
 
Drupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp North
 
SEO for Large Websites
SEO for Large WebsitesSEO for Large Websites
SEO for Large Websites
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
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
 
Web Performance & You - HighEdWeb Arkansas Version
Web Performance & You - HighEdWeb Arkansas VersionWeb Performance & You - HighEdWeb Arkansas Version
Web Performance & You - HighEdWeb Arkansas Version
 
Intro To Django
Intro To DjangoIntro To Django
Intro To Django
 
High Performance Web Sites
High Performance Web SitesHigh Performance Web Sites
High Performance Web Sites
 
High Performance Websites By Souders Steve
High Performance Websites By Souders SteveHigh Performance Websites By Souders Steve
High Performance Websites By Souders Steve
 
Plop
PlopPlop
Plop
 
Mobile User Experience: Auto Drive through Performance Metrics
Mobile User Experience:Auto Drive through Performance MetricsMobile User Experience:Auto Drive through Performance Metrics
Mobile User Experience: Auto Drive through Performance Metrics
 
Os Souders
Os SoudersOs Souders
Os Souders
 
Our application got popular and now it breaks
Our application got popular and now it breaksOur application got popular and now it breaks
Our application got popular and now it breaks
 

Plus de John McCaffrey

A 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 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
 
Becoming a more Productive Rails Developer
Becoming a more Productive Rails DeveloperBecoming a more Productive Rails Developer
Becoming a more Productive Rails DeveloperJohn McCaffrey
 
LeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than developmentLeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than developmentJohn McCaffrey
 
Becoming a more productive Rails Developer
Becoming a more productive Rails DeveloperBecoming a more productive Rails Developer
Becoming a more productive Rails DeveloperJohn McCaffrey
 
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...John McCaffrey
 
PDF Generation in Rails with Prawn and Prawn-to: John McCaffrey
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
 

Plus de John McCaffrey (8)

John's Sample
John's SampleJohn's Sample
John's Sample
 
A 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 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
 
Becoming a more Productive Rails Developer
Becoming a more Productive Rails DeveloperBecoming a more Productive Rails Developer
Becoming a more Productive Rails Developer
 
LeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than developmentLeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than development
 
Becoming a more productive Rails Developer
Becoming a more productive Rails DeveloperBecoming a more productive Rails Developer
Becoming a more productive Rails Developer
 
Irb Tips and Tricks
Irb Tips and TricksIrb Tips and Tricks
Irb Tips and Tricks
 
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
 
PDF Generation in Rails with Prawn and Prawn-to: John McCaffrey
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 McCaffrey
 

Dernier

Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 

Dernier (20)

Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 

Windy cityrails performance_tuning

  • 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.