SlideShare a Scribd company logo
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]

More Related Content

What's hot

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
 

What's hot (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
 

Similar to 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
 

Similar to 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
 

More from 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
 

More from 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
 

Recently uploaded

Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
 
Enterprise Security Monitoring, And Log Management.
Enterprise Security Monitoring, And Log Management.Enterprise Security Monitoring, And Log Management.
Enterprise Security Monitoring, And Log Management.Boni Yeamin
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀DianaGray10
 
Intelligent Gimbal FINAL PAPER Engineering.pdf
Intelligent Gimbal FINAL PAPER Engineering.pdfIntelligent Gimbal FINAL PAPER Engineering.pdf
Intelligent Gimbal FINAL PAPER Engineering.pdfAnthony Lucente
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomCzechDreamin
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsExpeed Software
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoTAnalytics
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsPaul Groth
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityScyllaDB
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1DianaGray10
 
The architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdfThe architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdfalexjohnson7307
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxJennifer Lim
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsStefano
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024Stephanie Beckett
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKUXDXConf
 

Recently uploaded (20)

Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Enterprise Security Monitoring, And Log Management.
Enterprise Security Monitoring, And Log Management.Enterprise Security Monitoring, And Log Management.
Enterprise Security Monitoring, And Log Management.
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
Intelligent Gimbal FINAL PAPER Engineering.pdf
Intelligent Gimbal FINAL PAPER Engineering.pdfIntelligent Gimbal FINAL PAPER Engineering.pdf
Intelligent Gimbal FINAL PAPER Engineering.pdf
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
The architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdfThe architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdf
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 

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.