SlideShare une entreprise Scribd logo
1  sur  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]

Contenu connexe

Tendances

plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerplProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancer
elliando dias
 
Step by step_linux_guide
Step by step_linux_guideStep by step_linux_guide
Step by step_linux_guide
vinod31dec
 

Tendances (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
 

Similaire à Optimize the obvious

MySQL Scaling Presentation
MySQL Scaling PresentationMySQL Scaling Presentation
MySQL Scaling Presentation
Tommy Falgout
 
MagentoECG-UsingRedisasaCacheBackendinMagento
MagentoECG-UsingRedisasaCacheBackendinMagentoMagentoECG-UsingRedisasaCacheBackendinMagento
MagentoECG-UsingRedisasaCacheBackendinMagento
Kirill Morozov
 
Performance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails Applications
Serge Smetana
 
Tutorial CentOS 5 untuk Webhosting
Tutorial CentOS 5 untuk WebhostingTutorial CentOS 5 untuk Webhosting
Tutorial CentOS 5 untuk Webhosting
Beni Krisbiantoro
 

Similaire à 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
 

Dernier

the Husband rolesBrown Aesthetic Cute Group Project Presentation
the Husband rolesBrown Aesthetic Cute Group Project Presentationthe Husband rolesBrown Aesthetic Cute Group Project Presentation
the Husband rolesBrown Aesthetic Cute Group Project Presentation
brynpueblos04
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morcall Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
vikas rana
 
KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...
KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...
KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...
Cara Menggugurkan Kandungan 087776558899
 

Dernier (14)

(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
 
Pokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy TheoryPokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy Theory
 
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
 
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
WOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptxWOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptx
 
the Husband rolesBrown Aesthetic Cute Group Project Presentation
the Husband rolesBrown Aesthetic Cute Group Project Presentationthe Husband rolesBrown Aesthetic Cute Group Project Presentation
the Husband rolesBrown Aesthetic Cute Group Project Presentation
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdf
 
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
 
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morcall Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
 
KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...
KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...
KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...
 
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
 
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
 

Optimize the obvious

Notes de l'éditeur

  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