SlideShare a Scribd company logo
1 of 19
SITE SPEED = SUCCESS!
 Optimizing WordPress from the server up


           Anthony Somerset
ABOUT
•   Anthony Somerset – Infrastructure Engineer, W3 EDGE
     • Manage W3 EDGE servers day to day
     • Build out Servers and infrastructure for new clients primarily on Amazon Web
       Services
     • Supporting existing users of W3 Total Cache plugin
     • Some work on the W3 Total Cache plugin
     • Motorsport Nut (the 4 wheel variety!)
ROADMAP
•   Configuring & Optimizing MySQL (Including general WP based optimizations)
•   Configuring PHP for efficient memory usage
•   Installing & Configuring APC – Common Caveats
•   W3 Total Cache recommended configuration
•   Questions?
OR
ROOT ACCESS REQUIRED!
•   You need a dedicated server or VPS to do 90% of the following stuff and root level access
•   I’m assuming you already have the Web Stack built whether that be LEMP, LAMP etc.
•   I’m assuming Linux is the OS being used! – Sorry no WAMP here please!
•   I’m assuming you are comfortable with SSH, command line, Vi/Nano etc.
•   Recommended Resources (just some of many)
     • http://www.if-not-true-then-false.com/2011/nginx-and-php-fpm-configuration-and-
       optimizing-tips-and-tricks/
     • https://www.digitalocean.com/community/articles/how-to-install-linux-nginx-mysql-
       php-lemp-stack-on-ubuntu-12-04
     • http://wiki.nginx.org/Wordpress
     • http://codex.wordpress.org/Nginx
MYSQL TUNING
•   The DB is often the first bottleneck in WordPress
•   Config file most commonly located in /etc/my.cnf
     • Debian/Ubuntu symlinks this to /etc/mysql/my.cnf
•   Most config options often don’t need a restart (they will have a matching set @@global.
    Query)
•   /etc/init.d/mysql reload does not work reliably on all systems – restart is safer


•   Useful Tools (direct download links to latest version):
     • Mysqltuner - http://sts.io/mysqltuner
     • Tuning-primer - http://sts.io/tuningprimer
MYSQL TUNING
•   Convert MyISAM tables to InnoDB
     • You lose default WP search (which was never that great)
     • Some alternative search plugins:
           • http://wordpress.org/extend/plugins/wordpress-sphinx-plugin/ - you need sphinx
             installed and running – the plugin can do this though
           • http://wordpress.org/extend/plugins/google-custom-search/ - requires no extra
             running software, but does need signing up for at Google
•   InnoDB scales better because it does row level locking instead of table level locking
     • This has greater impact for busier sites, lots of wp-admin traffic or lots of comments
     • InnoDB has better memory caching support than MyISAM – whole DB can be stored
       in RAM (if you have it available)
MYSQL TUNING
•   max_connections – make sure its set to the max number of DB connections you see at
    peak time + 20%
•   skip_name_resolve – can save up to 20% time on initial connection performance
     • Caveat – you cannot use hostnames in MySQL user permissions only IP’s
     • Doesn’t have any effect if you are using MySQL sockets (e.g. localhost) – which are
       faster than TCP anyway!
•   query_cache_size – don’t set to more than 128M the cost to clear it above that generally
    is worse than the performance gained by the larger cache
•   tmp_table_size, max_heap_table_size – set both to at least size of your largest table (if
    you have the ram)
•   innodb_buffer_pool_size – set this to the overall size of your InnoDB tables + 15%
MYSQL TUNING
•   innodb_file_per_table – great on multi disk Hardware RAID arrays (note, avoid RAID 5 or
    RAID 6 and variants for MySQL if you can RAID 10 is still fastest with least problems in
    event of a disk failure)
•   innodb_flush_method = O_DIRECT – great if you have Hardware raid and Battery backup
•   innodb_log_file_size = 1024M – stop MySQL before you make this change! Saves file
    descriptors being used for too many log files
•   innodb_log_buffer_size = 32M – set this adequately to avoid writing to disk too much but
    not so high that you could lose a large amount of data in the event of failure
•   Only enable the Slow log if you are actively debugging – leave it disabled otherwise
MYSQL TUNING - WORDPRESS
•   Delete Spam comments – don’t just leave them hanging around
•   Clear out old post/page revisions and limit number of created revisions -
    http://codex.wordpress.org/Editing_wp-config.php#Post_Revisions
•   Limit the auto-save interval, useful if you have lots of editors -
    http://codex.wordpress.org/Editing_wp-config.php#Modify_AutoSave_Interval
•   Clear out trash posts, can even be automated via wp_cron -
    http://codex.wordpress.org/Editing_wp-config.php#Empty_Trash
•   Use an alternative comment system – e.g. Disqus
•   If a single DB server cant cope then look at DB caching (W3TC) or DB replication
    (HyperDB or W3TC Enterprise)
TUNING PHP
•   Config files in various locations depending on the OS and may or may not use an included
    files based system
     • Debian/Ubuntu /etc/php5/…. And users/etc/php5/conf.d/
     • Red Hat/CentOS /etc/php.ini /etc/php.d/
•   Generally need to restart PHP service to activate changes (except when using
    apache/mod_php)
•   Using an Opcode Cache (like APC) is often where biggest gains are had.
•   Only enable/compile the minimum modules needed to run your site
•   Only do the required tasks in WordPress/PHP – e.g. don’t use WP plugins to do site
    backups – use a proper DB/File backup tool – if you use VaultPress – use the (S)FTP and
    MySQL connection options to reduce impact on the site code
TUNING PHP
•   Watch your memory usage – if you consistently need more than 128M memory_limit then
    look at what parts of your site/code is using large amounts of memory
•   Don’t extend max_execution_time – if something takes more than 30 seconds to process
    then something is wrong or should be done outside of the webserver process
•   Disable WP_Cron and switch it to a system cron task – wp-config.php:
    define('DISABLE_WP_CRON', true); - reduces number of PHP calls quite a bit and
    prevents race conditions in PHP on some busier sites – running it at regular defined
    intervals is more reliable and often more efficient
•   Remember to set post_max_size and upload_max_filesize for your uploads
•   Set date.timezone – it will save a warning in your logs which could cause slow downs
    because of disk writes on busy servers (I have seen this happen!)
•   If using multiple webservers – then set session.save_handler to use Memcached or
    similar
INSTALLING APC
•   APC will generally give biggest gains in PHP (or any other opcode cache)
•   Debian (assuming using the DotDeb repositories)
     • apt-get install php5-apc
•   Red Hat/Centos (use EPEL/Remi for most up to date)
     • yum install php-pecl-apc
•   cPanel – use WHM or:
     • pecl install APC
CONFIGURING APC
extension = apc.so          apc.mmap_file_mask = "/tmp/apc.XXXXXX”
apc.enabled = 1             apc.slam_defense = 0
apc.shm_segments = 1        apc.file_update_protection = 2
apc.shm_size = 128M         apc.enable_cli = 0
apc.optimization = 0        apc.max_file_size = 10M
apc.num_files_hint = 4096   apc.stat = 0
apc.ttl = 3600              apc.write_lock = 1
apc.user_ttl = 3600         apc.report_autofilter = 0
apc.gc_ttl = 3600           apc.include_once_override = 0
apc.cache_by_default = 1    apc.coredump_unmap = 0
apc.filters = "”            apc.stat_ctime = 0
CONFIGURING APC - CAVEATS
•   apc.stat = setting to 0 means it wont check for file changes
     • Means you have to manually clear APC caches
     • But gives much much more scale to servers by saving on many file system calls
•   Make sure apc.shm_size is large enough for your cache
     • APC is known to show nasty errors or just plain white screen a site when it runs out
       of memory
•   In rare cases apc.mmap_file_mask set to the /tmp directory can cause an abnormally high
    number of disk writes setting it to /dev/zero tends to solve the issue
•   Set TTL’s too low and things don’t get cached for long enough – too high and you might
    hit a cache full error – setting it to zero means caches get flushed as soon as cache gets
    full (this is bad)
W3 TOTAL CACHE
•   The Defaults are only a fail safe – they will not give you the best overall performance
•   Best config for a single server is not the best for a multi server setup
•   Page Cache – Use Disk Enhanced for single servers, Memcached for multiple –
    Nginx/Apache Rewrites are generally much faster than PHP or Memcached but
    consistency needed when multiple servers in play
•   Minify – same applies here, Disk for single server, Memcached for multiple
•   DB – Avoid Disk if you can. Memcached works very well here for both single and multiple
    server setups – APC is better than file if you don’t have Memcached if you use Disk make
    sure your Disks are fast – and prefer no caching if your DB is faster than File caching
•   Object – APC is fastest here, use Memcached if you have to for multiple servers
•   CDN – Enable it! – origin pull is generally easiest and simplest to manage – make use of
    any available API’s if we support it (e.g. MaxCDN/NetDNA, Amazon CloudFront)
W3 TOTAL CACHE – BROWSER CACHE
•   Enable all the options under Browser Cache.
•   Do Not Process 404s – make sure that any plugins that require WordPress for static files
    have there files whitelisted – e.g. WordPress SEO by Yoast – sitemap feature requires
    whitelisting
•   Prevent caching of objects after settings change – this appends a query string to all static
    file URL’s allowing you to set very long expires times (the default in W3TC if expires
    enabled)
•   If using CDN, make sure to enable the set cookie domain option to make sure new users
    cant send cookies in requests to your CDN resources
•   eTags are often not needed for sites using single servers – leave them disabled unless
    you know they are needed, it reduces the http header response size.
W3 TOTAL CACHE – PAGE CACHE
•   Enabling cache 404 pages in page cache – this returns a 200 error which can have an
    adverse effect on SEO use at your peril! Better to make sure your 404 page is efficient in
    its WP calls and that you generally have no 404’s in the first place
•   Don't cache pages for logged in users – if you disable this beware of the admin bar
    appearing for logged out users – with a logged in users username! A good idea to disable
    the admin bar on the front end when you do this
•   Cache Feeds if you can – even if you redirect to FeedBurner or similar services, w3tc will
    purge the feed from its cache every time you update/publish a post
•   Use a sitemap plugin and prime your cache with the sitemap
QUESTIONS?

More Related Content

Viewers also liked

Rules of composition
Rules of compositionRules of composition
Rules of compositionmattyryan11
 
Energy brochures
Energy brochuresEnergy brochures
Energy brochuresmattyryan11
 
Into energy drinks
Into energy drinksInto energy drinks
Into energy drinksmattyryan11
 
Positioneren ga 7feb2014.key
Positioneren ga 7feb2014.keyPositioneren ga 7feb2014.key
Positioneren ga 7feb2014.keyBas Douma
 
Techzim Surge: Important Considerations for Hosting Web or Mobile Apps
Techzim Surge: Important Considerations for Hosting Web or Mobile AppsTechzim Surge: Important Considerations for Hosting Web or Mobile Apps
Techzim Surge: Important Considerations for Hosting Web or Mobile AppsAnthony Somerset
 
WordCamp Harare 2016 - Site Speed = Success
WordCamp Harare 2016 - Site Speed = SuccessWordCamp Harare 2016 - Site Speed = Success
WordCamp Harare 2016 - Site Speed = SuccessAnthony Somerset
 
Target audience research
Target audience researchTarget audience research
Target audience researchmattyryan11
 

Viewers also liked (10)

Rules of composition
Rules of compositionRules of composition
Rules of composition
 
Tsarevets, rumen krastanov, 9b
Tsarevets, rumen krastanov, 9bTsarevets, rumen krastanov, 9b
Tsarevets, rumen krastanov, 9b
 
Energy brochures
Energy brochuresEnergy brochures
Energy brochures
 
Shutter speed
Shutter speedShutter speed
Shutter speed
 
Tsarevets, rumen krastanov, 9b
Tsarevets, rumen krastanov, 9bTsarevets, rumen krastanov, 9b
Tsarevets, rumen krastanov, 9b
 
Into energy drinks
Into energy drinksInto energy drinks
Into energy drinks
 
Positioneren ga 7feb2014.key
Positioneren ga 7feb2014.keyPositioneren ga 7feb2014.key
Positioneren ga 7feb2014.key
 
Techzim Surge: Important Considerations for Hosting Web or Mobile Apps
Techzim Surge: Important Considerations for Hosting Web or Mobile AppsTechzim Surge: Important Considerations for Hosting Web or Mobile Apps
Techzim Surge: Important Considerations for Hosting Web or Mobile Apps
 
WordCamp Harare 2016 - Site Speed = Success
WordCamp Harare 2016 - Site Speed = SuccessWordCamp Harare 2016 - Site Speed = Success
WordCamp Harare 2016 - Site Speed = Success
 
Target audience research
Target audience researchTarget audience research
Target audience research
 

Recently uploaded

H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

Site Speed = Success! - WordPress WordCamp Cape Town 2012

  • 1. SITE SPEED = SUCCESS! Optimizing WordPress from the server up Anthony Somerset
  • 2. ABOUT • Anthony Somerset – Infrastructure Engineer, W3 EDGE • Manage W3 EDGE servers day to day • Build out Servers and infrastructure for new clients primarily on Amazon Web Services • Supporting existing users of W3 Total Cache plugin • Some work on the W3 Total Cache plugin • Motorsport Nut (the 4 wheel variety!)
  • 3. ROADMAP • Configuring & Optimizing MySQL (Including general WP based optimizations) • Configuring PHP for efficient memory usage • Installing & Configuring APC – Common Caveats • W3 Total Cache recommended configuration • Questions?
  • 4. OR
  • 5. ROOT ACCESS REQUIRED! • You need a dedicated server or VPS to do 90% of the following stuff and root level access • I’m assuming you already have the Web Stack built whether that be LEMP, LAMP etc. • I’m assuming Linux is the OS being used! – Sorry no WAMP here please! • I’m assuming you are comfortable with SSH, command line, Vi/Nano etc. • Recommended Resources (just some of many) • http://www.if-not-true-then-false.com/2011/nginx-and-php-fpm-configuration-and- optimizing-tips-and-tricks/ • https://www.digitalocean.com/community/articles/how-to-install-linux-nginx-mysql- php-lemp-stack-on-ubuntu-12-04 • http://wiki.nginx.org/Wordpress • http://codex.wordpress.org/Nginx
  • 6. MYSQL TUNING • The DB is often the first bottleneck in WordPress • Config file most commonly located in /etc/my.cnf • Debian/Ubuntu symlinks this to /etc/mysql/my.cnf • Most config options often don’t need a restart (they will have a matching set @@global. Query) • /etc/init.d/mysql reload does not work reliably on all systems – restart is safer • Useful Tools (direct download links to latest version): • Mysqltuner - http://sts.io/mysqltuner • Tuning-primer - http://sts.io/tuningprimer
  • 7. MYSQL TUNING • Convert MyISAM tables to InnoDB • You lose default WP search (which was never that great) • Some alternative search plugins: • http://wordpress.org/extend/plugins/wordpress-sphinx-plugin/ - you need sphinx installed and running – the plugin can do this though • http://wordpress.org/extend/plugins/google-custom-search/ - requires no extra running software, but does need signing up for at Google • InnoDB scales better because it does row level locking instead of table level locking • This has greater impact for busier sites, lots of wp-admin traffic or lots of comments • InnoDB has better memory caching support than MyISAM – whole DB can be stored in RAM (if you have it available)
  • 8. MYSQL TUNING • max_connections – make sure its set to the max number of DB connections you see at peak time + 20% • skip_name_resolve – can save up to 20% time on initial connection performance • Caveat – you cannot use hostnames in MySQL user permissions only IP’s • Doesn’t have any effect if you are using MySQL sockets (e.g. localhost) – which are faster than TCP anyway! • query_cache_size – don’t set to more than 128M the cost to clear it above that generally is worse than the performance gained by the larger cache • tmp_table_size, max_heap_table_size – set both to at least size of your largest table (if you have the ram) • innodb_buffer_pool_size – set this to the overall size of your InnoDB tables + 15%
  • 9. MYSQL TUNING • innodb_file_per_table – great on multi disk Hardware RAID arrays (note, avoid RAID 5 or RAID 6 and variants for MySQL if you can RAID 10 is still fastest with least problems in event of a disk failure) • innodb_flush_method = O_DIRECT – great if you have Hardware raid and Battery backup • innodb_log_file_size = 1024M – stop MySQL before you make this change! Saves file descriptors being used for too many log files • innodb_log_buffer_size = 32M – set this adequately to avoid writing to disk too much but not so high that you could lose a large amount of data in the event of failure • Only enable the Slow log if you are actively debugging – leave it disabled otherwise
  • 10. MYSQL TUNING - WORDPRESS • Delete Spam comments – don’t just leave them hanging around • Clear out old post/page revisions and limit number of created revisions - http://codex.wordpress.org/Editing_wp-config.php#Post_Revisions • Limit the auto-save interval, useful if you have lots of editors - http://codex.wordpress.org/Editing_wp-config.php#Modify_AutoSave_Interval • Clear out trash posts, can even be automated via wp_cron - http://codex.wordpress.org/Editing_wp-config.php#Empty_Trash • Use an alternative comment system – e.g. Disqus • If a single DB server cant cope then look at DB caching (W3TC) or DB replication (HyperDB or W3TC Enterprise)
  • 11. TUNING PHP • Config files in various locations depending on the OS and may or may not use an included files based system • Debian/Ubuntu /etc/php5/…. And users/etc/php5/conf.d/ • Red Hat/CentOS /etc/php.ini /etc/php.d/ • Generally need to restart PHP service to activate changes (except when using apache/mod_php) • Using an Opcode Cache (like APC) is often where biggest gains are had. • Only enable/compile the minimum modules needed to run your site • Only do the required tasks in WordPress/PHP – e.g. don’t use WP plugins to do site backups – use a proper DB/File backup tool – if you use VaultPress – use the (S)FTP and MySQL connection options to reduce impact on the site code
  • 12. TUNING PHP • Watch your memory usage – if you consistently need more than 128M memory_limit then look at what parts of your site/code is using large amounts of memory • Don’t extend max_execution_time – if something takes more than 30 seconds to process then something is wrong or should be done outside of the webserver process • Disable WP_Cron and switch it to a system cron task – wp-config.php: define('DISABLE_WP_CRON', true); - reduces number of PHP calls quite a bit and prevents race conditions in PHP on some busier sites – running it at regular defined intervals is more reliable and often more efficient • Remember to set post_max_size and upload_max_filesize for your uploads • Set date.timezone – it will save a warning in your logs which could cause slow downs because of disk writes on busy servers (I have seen this happen!) • If using multiple webservers – then set session.save_handler to use Memcached or similar
  • 13. INSTALLING APC • APC will generally give biggest gains in PHP (or any other opcode cache) • Debian (assuming using the DotDeb repositories) • apt-get install php5-apc • Red Hat/Centos (use EPEL/Remi for most up to date) • yum install php-pecl-apc • cPanel – use WHM or: • pecl install APC
  • 14. CONFIGURING APC extension = apc.so apc.mmap_file_mask = "/tmp/apc.XXXXXX” apc.enabled = 1 apc.slam_defense = 0 apc.shm_segments = 1 apc.file_update_protection = 2 apc.shm_size = 128M apc.enable_cli = 0 apc.optimization = 0 apc.max_file_size = 10M apc.num_files_hint = 4096 apc.stat = 0 apc.ttl = 3600 apc.write_lock = 1 apc.user_ttl = 3600 apc.report_autofilter = 0 apc.gc_ttl = 3600 apc.include_once_override = 0 apc.cache_by_default = 1 apc.coredump_unmap = 0 apc.filters = "” apc.stat_ctime = 0
  • 15. CONFIGURING APC - CAVEATS • apc.stat = setting to 0 means it wont check for file changes • Means you have to manually clear APC caches • But gives much much more scale to servers by saving on many file system calls • Make sure apc.shm_size is large enough for your cache • APC is known to show nasty errors or just plain white screen a site when it runs out of memory • In rare cases apc.mmap_file_mask set to the /tmp directory can cause an abnormally high number of disk writes setting it to /dev/zero tends to solve the issue • Set TTL’s too low and things don’t get cached for long enough – too high and you might hit a cache full error – setting it to zero means caches get flushed as soon as cache gets full (this is bad)
  • 16. W3 TOTAL CACHE • The Defaults are only a fail safe – they will not give you the best overall performance • Best config for a single server is not the best for a multi server setup • Page Cache – Use Disk Enhanced for single servers, Memcached for multiple – Nginx/Apache Rewrites are generally much faster than PHP or Memcached but consistency needed when multiple servers in play • Minify – same applies here, Disk for single server, Memcached for multiple • DB – Avoid Disk if you can. Memcached works very well here for both single and multiple server setups – APC is better than file if you don’t have Memcached if you use Disk make sure your Disks are fast – and prefer no caching if your DB is faster than File caching • Object – APC is fastest here, use Memcached if you have to for multiple servers • CDN – Enable it! – origin pull is generally easiest and simplest to manage – make use of any available API’s if we support it (e.g. MaxCDN/NetDNA, Amazon CloudFront)
  • 17. W3 TOTAL CACHE – BROWSER CACHE • Enable all the options under Browser Cache. • Do Not Process 404s – make sure that any plugins that require WordPress for static files have there files whitelisted – e.g. WordPress SEO by Yoast – sitemap feature requires whitelisting • Prevent caching of objects after settings change – this appends a query string to all static file URL’s allowing you to set very long expires times (the default in W3TC if expires enabled) • If using CDN, make sure to enable the set cookie domain option to make sure new users cant send cookies in requests to your CDN resources • eTags are often not needed for sites using single servers – leave them disabled unless you know they are needed, it reduces the http header response size.
  • 18. W3 TOTAL CACHE – PAGE CACHE • Enabling cache 404 pages in page cache – this returns a 200 error which can have an adverse effect on SEO use at your peril! Better to make sure your 404 page is efficient in its WP calls and that you generally have no 404’s in the first place • Don't cache pages for logged in users – if you disable this beware of the admin bar appearing for logged out users – with a logged in users username! A good idea to disable the admin bar on the front end when you do this • Cache Feeds if you can – even if you redirect to FeedBurner or similar services, w3tc will purge the feed from its cache every time you update/publish a post • Use a sitemap plugin and prime your cache with the sitemap