3. ● PHP Apps like WordPress don’t scale =
LIES!
Scaling WordPress
High Performance WordPress by @MikelKing http://jafdip.com
4. ● PHP Apps like WordPress don’t scale = LIES!
● PHP is not JAVA so Big IRON = FAIL
Scaling WordPress
High Performance WordPress by @MikelKing http://jafdip.com
5. ● PHP Apps like WordPress don’t scale = LIES!
● PHP is not JAVA so Big IRON = FAIL
● Caching + DB Clustering + Apache Tuning
= Success!
Scaling WordPress
High Performance WordPress by @MikelKing http://jafdip.com
6. User level --
Files System --
Memory Resident --
Browser
Caching Plugins
Memcache
Realms of Caching
High Performance WordPress by @MikelKing http://jafdip.com
7. ● Is easy to turn on and easier to fail.
● Requires access to Apache conf
&& ! .htaccess
● Requires proper WordPress CSS & JS
registration and enqueuing
Browser Caching
High Performance WordPress by @MikelKing http://jafdip.com
8. Apache Conf Example
# 480 weeks
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=290304000, public"
</FilesMatch>
# 2 DAYS
<FilesMatch ".(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
</FilesMatch>
# 2 HOURS
<FilesMatch ".(html|htm)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
High Performance WordPress by @MikelKing http://jafdip.com
10. ● Easy to setup
● Good for shared hosting
● NOT load balancer friendly
● Plugins are written in PHP
● Does NOT reliably cache DB Objects
● Relies on file system access
File System Caching
High Performance WordPress by @MikelKing http://jafdip.com
20. Example of DB runaway
High Performance WordPress by @MikelKing http://jafdip.com
21. ● Stores PHP code as compiled objects
● Capable of caching DB queries as objects
● May be clustered
● Is load balancer friendly
Memory Based Caching
High Performance WordPress by @MikelKing http://jafdip.com
22. Example of a memcache cluster
define('WP_CACHE', true);
$memcached_servers = array(
'default' => array(
'172.16.1.244:11211',
'172.16.1.229:11211',
'172.16.1.195:11211',
'172.16.1.227:11211',
'172.16.1.218:11211’,
'172.16.1.205:11211’
)
);
High Performance WordPress by @MikelKing http://jafdip.com
24. Example of a DB on memcache
High Performance WordPress by @MikelKing http://jafdip.com
25. Memcache is a separate service to manage
Corruption can spread like a virus
Clearing the cache requires shutting down
the entire cluster
Caveats (It’s NOT all sunshine and rainbows)
High Performance WordPress by @MikelKing http://jafdip.com
26. ● Convert ALL tables to InnoDB
● Convert ALL collation to UTF-8
● Set innodb_buffer_pool_size = 70-80% of
total DB server available RAM
● Set thread_cache_size = 4096
● Increase the mysql ulimits
Clustering with HyperDB
High Performance WordPress by @MikelKing http://jafdip.com
27. Full text search is supported in the InnoDB
engine as of MySql 5.6, prior to this only the
MyISAM engine had this feature.
InnoDB became the default storage engine
in MySql 5.5 and that prior to this version
you must compile it in as an optional item.
Caveats
High Performance WordPress by @MikelKing http://jafdip.com
32. ● Eliminate file reads.
● Reduce the number of server limit
● Increase the allocated RAM
● Install mod_deflate
● Install mod_gzip2
Tuning Apache
High Performance WordPress by @MikelKing http://jafdip.com
33. House Keeping
Use the PHP native filter_var & filter_input in lieu of regex and built-
in WordPress methods
Drop WP & plugin based Search in favor of a search service
• Solr (requires a separate Java based server)
• Sphinx (is a separate service
• Elastisearch (requires a separate Hadoop server)
• GSS ( a.k.a. Google Site Search)
Enterprise Environments
High Performance WordPress by @MikelKing http://jafdip.com
34. General House Keeping
● Cleanout the functions.php
● Turn off unnecessary auto loaded items in wp_options
● Optimize your database with a plug-in like WP Optimize
● Leverage the power of a CDN to eliminate your serving
environment’s latency issues.
These items apply sites of any size even if you are
on shared hosting
High Performance WordPress by @MikelKing http://jafdip.com
The load balancer directs the user’s request for a blue page. Fortunately W1 has a copy of the page in it’s cache.
The load balancer directs the user’s request for a green page. Fortunately W3 has a copy of the page in it’s cache.
The load balancer directs the user’s request for a pink page. Unfortunately W2 does not have a copy of the page in it’s cache, therefore; a page must be completely built from scratch by WordPress before fulfilling the request.
The load balancer directs the user’s request for a blue page. Fortunately M1 is able to access a copy of the page in memcache.
The load balancer directs the user’s request for a blue page. Fortunately M3 is able to access a copy of the page in memcache.
The load balancer directs the user’s request for a blue page. Fortunately M3 is able to access a copy of the page in memcache.
M2 boots up and receives a user request for a pink page. Fortunately M2 is able to access a copy of the page already in memcache.
W4 boots up and receives a user request for a green page. Unfortunately W4 is has no cache and must start from scratch.
----- Meeting Notes (8/4/14 23:18) -----
In this view of our New Relic graphs you see what happens when queries start bottlenecking in the DB system. Once the problem start only HUPing the web services to clear the condition.
If you do not have control of your hosting environment you may not be able to upgrade to the current MySql server. If you do not require full text search in InnoDB then it WILL not be a problem.
Using the internal WordPress search will slow down your systems. These search system index your site and serve the results from that outside index and do not impact the load on your WordPress systems.
The native PHP filter_var and filter_input mthods are only supported in PHP versions 5.2 and later so you may need to upgrade in order to use it. The main benefit is that these methods are written in C and are an order of magnitude faster than anything you could write in PHP to do the same job. Do not use them in code you intend to publish back to the WordPress community like plugins and themes because you can not guarantee another user’s PHP environment.