Part I: PHP Caching and Connections
Part II: Varnish and Pound
So now that you have your web server tuned up for optimal performance, what about Drupal and WordPress themselves? Here are some basic tactics for making them faster. (We’ll work specifically with Drupal 7 and WordPress 3.6+.)
Drupal Performance
- Enable Drupal’s built-in ability to compress its JavaScript and CSS files. This is a cheap and easy performance enhancement.
- Enable Drupal’s built-in ability to cache blocks.
- Remember to turn off automatic refreshing of the theme registry.
- If you’re running Varnish, install the Drupal Varnish module, configure the plugin, and then configure your site’s settings.php to use it:
// Let Drupal know we're running a reverse proxy $conf['reverse_proxy'] = true; $conf['reverse_proxy_addresses'] = array('127.0.0.1'); // Add Varnish as the page cache handler. $conf['cache_backends'][] = 'sites/all/modules/varnish/varnish.cache.inc'; $conf['cache_class_cache_page'] = 'VarnishCache'; // Drupal 7 does not cache pages when we invoke hooks during bootstrap. // This needs to be disabled. $conf['page_cache_invoke_hooks'] = false; $conf['cache'] = 1; $conf['cache_lifetime'] = 0; $conf['page_cache_maximum_age'] = 21600; $conf['omit_vary_cookie'] = true;
- Install the Boost module. Boost specifically uses the disk to cache pages for anonymous visitors.
Note that if you’ve enabled Drupal’s back-end cache — to run with Varnish as above, for example — Drupal will issue you a warning on your Status page: “Boost will not function properly while Drupal core cache is enabled. Disable Boost or the core cache.” If you’re going to use one or the other, I’d suggest using Varnish. This also keeps the back-end cache enabled for other useful Drupal plugins like APC.
However, it is possible to run Varnish and Boost simultaneously with some simple hacks to the Lullabot Varnish vcl. In this arrangement, Varnish works as a distributor of the existing Boost disk cache.
- Install the Drupal APC module, and configure it in your site’s settings.php:
$conf['cache_backends'][] = 'sites/all/modules/apc/drupal_apc_cache.inc'; $conf['cache_class_cache'] = 'DrupalAPCCache'; $conf['cache_class_cache_bootstrap'] = 'DrupalAPCCache'; //$conf['apc_show_debug'] = true; // Remove the slashes to use debug mode.
- If you’re running the Devel module, disable it on production web sites.
- Consider eliminating the Statistics and Database logging modules. Both require a lot of writes to the database.
- You’re better off using the system cron to run Drupal’s cron jobs instead of the cron setup in Administration » Configuration » System » Cron. You may have noticed that Drupal 7 is slow sometimes when loading the first page you see although it loads all subsequent much faster. That’s because Drupal’s built-in cron is dependent on loading the whole Drupal bootstrap — which only happens when someone visits the site — so the first visitor after cron is queued up gets to wait for Drupal to index content, check for updates, and flush its caches. You also shouldn’t run cron too often, since empty caches equal bad performance. (For some statistics on this, see http://www.metaltoad.com/blog/how-drupals-cron-killing-you-your-sleep-simple-cache-warmer.)
- Since Drupal stores a lot of its caching information in its MySQL database, Memcached can help by pushing the cache information to your server’s memory. Install the Memcached Drupal plugin, and configure it in settings.php:
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc'; $conf['cache_default_class'] = 'MemCacheDrupal'; $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
WordPress Performance
- As with any other PHP-based application, installing an opcode cache is the single best improvement you can make.
You might then install the W3 Total Cache (W3TC) plugin, which can help manage all kinds of things like APC, memcached, Varnish and compression of your JavaScript and CSS. - I’m eliminating W3TC on all my web sites since it’s too bloated to scale effectively and causes massive APC cache fragmentation with all its features enabled. Skip it and use APC for PHP caching, then install Mark Jaquith’s Object Cache Backend. Alternatively you can use APC plus Memcached with a connector like Batcached or the Memcached Object Cache mentioned below for WordPress objects.
- If you’re running Varnish, try the wp-varnish plugin.
- If you’re using a child theme, avoid using @import in your CSS. Imported stylesheets load sequentially, which slows everything down.
- Compress your JavaScript and CSS. Again, if you’re not using W3TC, one easy way to accomplish this is to install the WP Minify plugin.
- The Memcached Object Cache plugin provides a WordPress connector for Memcached.
- It’s a good idea to clean the garbage out of your database periodically. WP Clean Up can help with this, and you can use a plugin like WP Crontrol to schedule cleanup actions. Note that like Drupal cron, the WordPress cron only executes when someone visits your web site.
The post Web Server Part III: WordPress and Drupal Performance appeared first on GeoffStratton.com.