Background Back when I got my GL-AR150 mini router, I was blown away by the powerful capabilities of this $25 OpenWRT router,...
Mark Jaquith: Next Generation WordPress Hosting Stack – Summary and highlightsStanislav Khromov
Mark Jaquith gave an interesting talk on the future of the WordPress hosting stack at WordCamp Europe 2014 last week. Let’s see what the future holds!
WordPress is dynamic, and that’s both a strength and a weakness
WordPress has little cache built-in by default. There is only a non-persistent, in-memory Object Cache. Most data is fetched from database and processed on every request.
“Old-style” hosts can’t deliver the performance modern sites need
Old “cPanel-style” hosting isn’t equipped to handle high-performance WordPress. Specialized stacks do a much better job.
People don’t like slow sites
Reducing your TTFB is crucial.
Guidelines for page generation speed:
- 3+ seconds = emergency, loss of visitors imminent
- 1-3 seconds = feels annoying to end users, reduces interaction
- 500ms – 1000ms = fast, but user engagement still not perfect, users perceive the site as not responsive
- <100ms – feels like there is no delay at all
WordPress Managed Hosting
Managed Hosting – a new breed of hosting providers tailored to WordPress.
- WP Engine
In addition, you can purchase a VPS where you can customize the stack yourself. When choosing a VPS, use a reputable company, as many are fly-by-night and may disappear at any time.
Some reputable VPS providers:
Basics of a high performance WordPress stack
nginx is a fast web server that uses little resources. It support SPDY, which improves loading sites with many assets (css, js, images) through pipelining. nginx also supports load-balancing and caching.
php-fpm or HHVM
nginx does not have php baked into it. this is good, since it reduces memory usage for static requests as compared to Apache with mod_php. Always use the latest PHP version – newer PHP versions have increased performance and built-on opcache.
An alternative is HHVM – a PHP implementation created by Facebook, which aims to improve performance. (up to 5x faster than regular PHP!) It’s fully compatible with WordPress core, but may not support all third party plugins.
Caching is about doing as little as possible for as many users as possible without visibly affecting how dynamic the site feels to users.
Full page caching
Most cache plugins use full page caching, showing a pre-saved version to anonymous visitors.
Full page caching may be utilized at different levels of the stack:
- Plugins (W3 Total Cache, et al)
Marks own cache settings using Nginx and php-fpm:
Persistent caches include:
Redis (Marks favourite)*
*Network-based, works across multiple servers. *
Object caching is used extensively in core and is also available to plugins.
MySQL is usually not the bottleneck – PHP performance is.
mysqltuner.pl – Gives you tips on improving MySQL performance!
HyperDB – replaces the built-in WordPress database layer. Can talk to multiple MySQL servers, has failover, sharding and much more! WordPress.org uses this.
But make sure you enable the MySQL query cache.
There are drop-in alternatives to MySQL like Percona and MariaDB, which can improve performance for some sites.
Making a stack
Mark presented a few stacks that build on the basic stack.
Nginx + PHP
Static files are served by Nginx and PHP requests go through to php-fpm or hhvm. The easiest stack.
Nginx + Varnish + Nginx + PHP
Nicknamed the “nginx sandwich”. This variant uses Varnish for caching. nginx is used at the front because Varnish does not support SSL. It’s also possible to add HAProxy to the mix to load balance between multiple servers.
And finally, the big reveal:
The future hosting stack
The combo of choice is nginx + hhvm + mysql + redis.
This stack allows you to scale horizontally when required and has high performance.
Other useful stuff
Mark showed off a few useful functions that he had built.
- TLC Transients – a library built by mark that improves on the Transient API. Support soft expiration, meaning we can do background loading of data in transients without affecting frontend performance, through function callbacks.
- “Fragment cache” – Caching existing PHP code with minimal modification through “fragment cache”: