SlideShare uma empresa Scribd logo
1 de 74
Optimize The Obvious By: David Henner
www.ror-e.com drhenner @drhenner drhenner@yahoo.com
What do you think of when your boss asks you to:  Optimize the site?
This talk isn’t  about the fun stuff.
N + 1
When to use  joins and includes
Looking at  the Log File
Bad code that needs Refactoring.
Understanding  your  Bottlenecks
Add some RAM
Upgrade to Ruby 1.9.2
Use Constants WISELY
Optimize Images
Configure your Database
MySQL MyCNF file
Add Indexes
Only index  The First 10  Characters
Name Wisely
STI type. Should be named As short as Possible
Use a CDN for  Js & CSS
Compress Js & CSS
NOW LET’S TALK
N + 1
Who doesn’t know what an N + 1 query is?
Look at your LOG file
Modify your Queries @user = User.find(1) @user.groups.each do |group| group.method end @user = User.find(1, :includes => :groups) or @user = User.includes(:groups).find(1)
When to use  joins and includes
Take a look at the RailsCast http://railscasts.com/episodes/181-include-vs-joins Use includes if you need to use the method on the associated model  Use joins if you need to filter the objects loaded by SQL.
Looking at  the Log File
 N + 1
Deprecation Warnings
SLOW QUERIES Is this acceptable?   ANSWER == Maybe
Bad code that needs Refactoring.
You might not be this bad
Know your API If you are doing something that you think should be part of ruby.  It probably is. inject map join compact uniq DON’T RECREATE THESE METHODS  (maybe inject but….)
INJECT SUCKS when…. object.inject({}) do |h, new_h| new_h[h.id] = h.some_method new_h end new_array = Object.map do |obj|     [obj.id , obj.some_method] end Hash[new_array]
Don’t over-use  Before_filters
Class SomeController < ActionController::Base def edit   	@post = Post.find(id) form_info end def update @post = Post.find(id)     if @post.update_attributes(params[:post]) redirect_to :action => :index 	else form_info 	render :edit 	end     end end private defform_info 	@states = State.find(:all).map{|s| [s.name, s.id]} end end
Understanding  your  Bottlenecks
You don’t need to measure performance on the page that takes 30 seconds to load!!
Add some RAM
It is easy and much cheaper than  10 / 20 or 100 hoursof a developer’s time
Upgrade to Ruby 1.9.2
It is easy and you will do it within the next couple years anyway. http://www.engineyard.com/blog/2011/upgrading-from-ruby-1-8-7-to-1-9-2-on-appcloud/ ,[object Object]
You need to make sure that your Gemfile specifies that the ruby-debug19 gem is available in both the test and development environments by specifying it using group :test, :development in the Gemfile
1.9.2 doesn’t support the use of a : in a when clause of a case statement any more
Hash#key has been removed and replaced with Hash#index
The {:key, :value} format for Hash is no longer allowed,[object Object]
WHAT THE HELL DOES 1 MEAN!!!
WHAT THE HELL DOES 1 MEAN!!! OOPS  that should be true.
Optimize Images
http://www.ror-e.com/posts/6-optimize-your-images Non-optimized Images can add 85% more page weight!!
Configure your Database
MySQL
http://blog.codesherpas.com/on_the_path/2011/03/tuning-mysql.html MyCNF Use INNOdb(transactions)
http://blog.codesherpas.com/on_the_path/2011/03/tuning-mysql.html MyCNF ,[object Object]
innodb_log_buffer_size
innodb_thread_concurrency
innodb_flush_method,[object Object]
your best dollars spent will be on more ram
Set the value to about 2.5Gig less than your system RAM	If you share your DB with memcached or passenger or  	anything else you need to set this value to have less RAM
http://blog.codesherpas.com/on_the_path/2011/03/tuning-mysql.html Innodb_log_buffer_size Start with 4 megabytes and adjust up
http://blog.codesherpas.com/on_the_path/2011/03/tuning-mysql.html innodb_thread_concurrency Set this value to 2x the number of cpu cores your server has
http://blog.codesherpas.com/on_the_path/2011/03/tuning-mysql.html Innodb_flush_method Set to O_DIRECT as long as you aren't running on a storage-area-network Otherwise READ the DOCs: http://dev.mysql.com/doc/refman/5.1/en/innodb-parameters.html#sysvar_innodb_flush_method
Add Indexes
Yeah I know you forgot. ,[object Object]
Don’t forget to index strings
Don’t index the whole string
Index the first 10 charactersexecute('CREATE INDEX users_last_name_ten ON users (last_name(8));') execute('CREATE UNIQUE INDEX users_email_ten ON users (email(10));')
Name Wisely
STI type. Should be named As short as Possible
For Example ,[object Object]
Your Model will be NameSpace::ModelName
Now indexing the first 11 characters has absolutely no effect.,[object Object]

Mais conteúdo relacionado

Mais procurados

Improving PHP Application Performance with APC
Improving PHP Application Performance with APCImproving PHP Application Performance with APC
Improving PHP Application Performance with APCvortexau
 
DevOps Meetup ansible
DevOps Meetup   ansibleDevOps Meetup   ansible
DevOps Meetup ansiblesriram_rajan
 
Compress and decompress
Compress and decompressCompress and decompress
Compress and decompressSon Nguyen
 
DATABASE AUTOMATION with Thousands of database, monitoring and backup
DATABASE AUTOMATION with Thousands of database, monitoring and backupDATABASE AUTOMATION with Thousands of database, monitoring and backup
DATABASE AUTOMATION with Thousands of database, monitoring and backupSaewoong Lee
 
MySQL 5.7 innodb_enhance_partii_20160527
MySQL 5.7 innodb_enhance_partii_20160527MySQL 5.7 innodb_enhance_partii_20160527
MySQL 5.7 innodb_enhance_partii_20160527Saewoong Lee
 
Virtual hosting using nginx
Virtual hosting using nginxVirtual hosting using nginx
Virtual hosting using nginxVmoksha Admin
 
plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerplProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerelliando dias
 
Introduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsIntroduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsPerrin Harkins
 
Apc presentation
Apc presentationApc presentation
Apc presentationguestef8544
 
Production MongoDB in the Cloud
Production MongoDB in the CloudProduction MongoDB in the Cloud
Production MongoDB in the Cloudbridgetkromhout
 
Installation of sap HANA DB system on SUSE Linux
Installation of sap HANA DB system on SUSE LinuxInstallation of sap HANA DB system on SUSE Linux
Installation of sap HANA DB system on SUSE Linuxmehboobhafz
 
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for WindowsFord AntiTrust
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisationgrooverdan
 
Enterprise grade deployment and security with PostgreSQL
Enterprise grade deployment and security with PostgreSQLEnterprise grade deployment and security with PostgreSQL
Enterprise grade deployment and security with PostgreSQLHimanchali -
 
Step by step_linux_guide
Step by step_linux_guideStep by step_linux_guide
Step by step_linux_guidevinod31dec
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Denish Patel
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APCBen Ramsey
 
Recent Updates at Embulk Meetup #3
Recent Updates at Embulk Meetup #3Recent Updates at Embulk Meetup #3
Recent Updates at Embulk Meetup #3Muga Nishizawa
 
Using Embulk at Treasure Data
Using Embulk at Treasure DataUsing Embulk at Treasure Data
Using Embulk at Treasure DataMuga Nishizawa
 

Mais procurados (20)

Improving PHP Application Performance with APC
Improving PHP Application Performance with APCImproving PHP Application Performance with APC
Improving PHP Application Performance with APC
 
DevOps Meetup ansible
DevOps Meetup   ansibleDevOps Meetup   ansible
DevOps Meetup ansible
 
Compress and decompress
Compress and decompressCompress and decompress
Compress and decompress
 
DATABASE AUTOMATION with Thousands of database, monitoring and backup
DATABASE AUTOMATION with Thousands of database, monitoring and backupDATABASE AUTOMATION with Thousands of database, monitoring and backup
DATABASE AUTOMATION with Thousands of database, monitoring and backup
 
MySQL 5.7 innodb_enhance_partii_20160527
MySQL 5.7 innodb_enhance_partii_20160527MySQL 5.7 innodb_enhance_partii_20160527
MySQL 5.7 innodb_enhance_partii_20160527
 
Virtual hosting using nginx
Virtual hosting using nginxVirtual hosting using nginx
Virtual hosting using nginx
 
Performance_Up.ppt
Performance_Up.pptPerformance_Up.ppt
Performance_Up.ppt
 
plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerplProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancer
 
Introduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsIntroduction to performance tuning perl web applications
Introduction to performance tuning perl web applications
 
Apc presentation
Apc presentationApc presentation
Apc presentation
 
Production MongoDB in the Cloud
Production MongoDB in the CloudProduction MongoDB in the Cloud
Production MongoDB in the Cloud
 
Installation of sap HANA DB system on SUSE Linux
Installation of sap HANA DB system on SUSE LinuxInstallation of sap HANA DB system on SUSE Linux
Installation of sap HANA DB system on SUSE Linux
 
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
/* pOrt80BKK */ - PHP Day - PHP Performance with APC + Memcached for Windows
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisation
 
Enterprise grade deployment and security with PostgreSQL
Enterprise grade deployment and security with PostgreSQLEnterprise grade deployment and security with PostgreSQL
Enterprise grade deployment and security with PostgreSQL
 
Step by step_linux_guide
Step by step_linux_guideStep by step_linux_guide
Step by step_linux_guide
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
 
Recent Updates at Embulk Meetup #3
Recent Updates at Embulk Meetup #3Recent Updates at Embulk Meetup #3
Recent Updates at Embulk Meetup #3
 
Using Embulk at Treasure Data
Using Embulk at Treasure DataUsing Embulk at Treasure Data
Using Embulk at Treasure Data
 

Semelhante a Optimize the obvious

Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database DeploymentsMike Willbanks
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindSam Keen
 
MySQL Scaling Presentation
MySQL Scaling PresentationMySQL Scaling Presentation
MySQL Scaling PresentationTommy Falgout
 
Starting with PHP and Web devepolment
Starting with PHP and Web devepolmentStarting with PHP and Web devepolment
Starting with PHP and Web devepolmentRajib Ahmed
 
MagentoECG-UsingRedisasaCacheBackendinMagento
MagentoECG-UsingRedisasaCacheBackendinMagentoMagentoECG-UsingRedisasaCacheBackendinMagento
MagentoECG-UsingRedisasaCacheBackendinMagentoKirill Morozov
 
Preparing for Upgrade to SharePoint 2010 with Joel Oleson Quest Software Webcast
Preparing for Upgrade to SharePoint 2010 with Joel Oleson Quest Software WebcastPreparing for Upgrade to SharePoint 2010 with Joel Oleson Quest Software Webcast
Preparing for Upgrade to SharePoint 2010 with Joel Oleson Quest Software WebcastJoel Oleson
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and ScalabilityMediacurrent
 
Performance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsSerge Smetana
 
Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101Angus Li
 
Designing For Occasionally Connected Apps Slideshare
Designing For Occasionally Connected Apps SlideshareDesigning For Occasionally Connected Apps Slideshare
Designing For Occasionally Connected Apps SlideshareDean Willson
 
Drupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthPhilip Norton
 
70-410 Practice Test
70-410 Practice Test70-410 Practice Test
70-410 Practice Testwrailebo
 
Drupal performance optimization Best Practices
Drupal performance optimization Best PracticesDrupal performance optimization Best Practices
Drupal performance optimization Best PracticesRatnesh kumar, CSM
 
WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019Anam Ahmed
 
70 412 pdf training guides 2018
70 412 pdf training guides 201870 412 pdf training guides 2018
70 412 pdf training guides 2018birhanu atnafu
 
Practical solutions for connections administrators
Practical solutions for connections administratorsPractical solutions for connections administrators
Practical solutions for connections administratorsSharon James
 
Tutorial CentOS 5 untuk Webhosting
Tutorial CentOS 5 untuk WebhostingTutorial CentOS 5 untuk Webhosting
Tutorial CentOS 5 untuk WebhostingBeni Krisbiantoro
 

Semelhante a Optimize the obvious (20)

Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database Deployments
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
MySQL Scaling Presentation
MySQL Scaling PresentationMySQL Scaling Presentation
MySQL Scaling Presentation
 
Starting with PHP and Web devepolment
Starting with PHP and Web devepolmentStarting with PHP and Web devepolment
Starting with PHP and Web devepolment
 
MagentoECG-UsingRedisasaCacheBackendinMagento
MagentoECG-UsingRedisasaCacheBackendinMagentoMagentoECG-UsingRedisasaCacheBackendinMagento
MagentoECG-UsingRedisasaCacheBackendinMagento
 
Preparing for Upgrade to SharePoint 2010 with Joel Oleson Quest Software Webcast
Preparing for Upgrade to SharePoint 2010 with Joel Oleson Quest Software WebcastPreparing for Upgrade to SharePoint 2010 with Joel Oleson Quest Software Webcast
Preparing for Upgrade to SharePoint 2010 with Joel Oleson Quest Software Webcast
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and Scalability
 
Performance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails Applications
 
Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101
 
Designing For Occasionally Connected Apps Slideshare
Designing For Occasionally Connected Apps SlideshareDesigning For Occasionally Connected Apps Slideshare
Designing For Occasionally Connected Apps Slideshare
 
Scaling 101 test
Scaling 101 testScaling 101 test
Scaling 101 test
 
Scaling 101
Scaling 101Scaling 101
Scaling 101
 
Drupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp North
 
70-410 Practice Test
70-410 Practice Test70-410 Practice Test
70-410 Practice Test
 
Scaling PHP apps
Scaling PHP appsScaling PHP apps
Scaling PHP apps
 
Drupal performance optimization Best Practices
Drupal performance optimization Best PracticesDrupal performance optimization Best Practices
Drupal performance optimization Best Practices
 
WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019WordPress At Scale. WordCamp Dhaka 2019
WordPress At Scale. WordCamp Dhaka 2019
 
70 412 pdf training guides 2018
70 412 pdf training guides 201870 412 pdf training guides 2018
70 412 pdf training guides 2018
 
Practical solutions for connections administrators
Practical solutions for connections administratorsPractical solutions for connections administrators
Practical solutions for connections administrators
 
Tutorial CentOS 5 untuk Webhosting
Tutorial CentOS 5 untuk WebhostingTutorial CentOS 5 untuk Webhosting
Tutorial CentOS 5 untuk Webhosting
 

Último

Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...JeylaisaManabat1
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证kbdhl05e
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxJackieSparrow3
 
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan
 
(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)oannq
 
Inspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxInspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxShubham Rawat
 

Último (6)

Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptx
 
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
 
(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)
 
Inspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxInspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptx
 

Optimize the obvious

Notas do Editor

  1. My name is David Henner, and today I’ll talk about optimizing the obvious.
  2. This is my web site, twitter, github, and you can contact me at drhenner@rorecommerce.com
  3. Ask question and listen. Memcached, noSQL, memprof.Tell them about a project manager you had that thought it was adding a lot more functionality to one page. More glitter, and bells and whistles.
  4. Paperclip does no optimize images after they are re-sized. Make sure your images are optimized for each size.
  5. This is my web site, twitter, github, and you can contact me at drhenner@rorecommerce.com