(reposting with clearer title)
Performance tuning presentation from WindyCityRails 2010.
Why performance matters
The right way to approach it
Front end testing tools
Automated testing tools
Common problems and the ways to solve them in Rails
Rails specific tools
bullet
slim_scrooge
rack bug
request log analyzer
rails indexes
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
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
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%?
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
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
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