9 Tips for Improving Drupal Performance

December 9th, 2009

As anyone who has developed a Drupal site with devel module‘s query logging on can tell you, a Drupal implementation can quickly get out of control when it comes to hammering the database. Personally, I’ve seen Drupal run well over 300 queries to render a single page. In a hosting setup where the bottlenecks exist at the memory usage and MySQL levels (which refers to nearly all non-dedicated hosting packages), this can quickly become a problem. I’ve summarized a series of simple setup and configuration tips behind the jump that can help any site running Drupal 6.x improve performance and the subsequent user experience as a result.

1 – Disable Re-Building of Theme Registry

When a Drupal implementation is under development, themers and/or developers will often enable an option that forces Drupal to rebuild the theme registry on every page load. This registry tells Drupal what template files and overrides exist in the theme’s directory. This is a very costly operation and would cause noticeable slow down on any production website. It is important to disable this option upon going live. Under Administer > Appearance choose the Configure option for your theme and scroll to the bottom of the page. Make sure the option named “Rebuild theme registry on every page.” is disabled.

2 – Enable Page and Block Cache

Another simple option to enable is Drupal’s caching engine (Administer > Configuration > Performance). When enabled, Drupal will render the page and associated blocks once, and then save that result in the database. This can drastically reduce the number of database calls run on a page since the results are pre-rendered. A point to consider about caching is that the more interactive the site is, the less effective the cache may be. Especially if complex permissions are at play, Drupal won’t be able to effectively cache since most of the page content may change depending on the permissions of the currently logged in user. Drupal’s caching engine is most effective for anonymous visitors – if your site is mostly “read only” and doesn’t have visitors logging in, caching can make a dramatic improvement in site load speed.

3 – Increase Cache Lifetime

An option for some sites may be to increase the cache lifetime. This determines how long Drupal will hold onto a cached result before it will re-generate the page. If you have frequently changing content, you may want to set the cache lifetime to only 5 minutes, but if your content doesn’t change often, an acceptable value may be several hours. On high-traffic sites, the less often Drupal has to re-generate pages, the better.

4 – Optimize JavaScript and CSS Files

Also in the Performance settings is an option to optimize both JavaScript and CSS files. When enabled, Drupal will consolidate all CSS and JS files included on each page into a single file, and compress the code by removing whitespace. This will reduce the overall file size and improve page load speeds.

5 – Disable Un-used Modules

Due to the staggering array of available contrib modules listed on Drupal.org, it’s common to download and install dozens of modules to test out and see if they meet your site’s needs. In the process of doing this, it’s easy to forget to uninstall the modules you don’t end up using. Additionally, the default install of Drupal comes with a minimum number of modules pre-enabled. Again, if your site isn’t using it, there’s no reason to keep it enabled. Drupal will fire callbacks for all enabled modules which may come with their own database queries. Be sure to take the time to clean out your enabled modules list before going live with a site.

6 – Configure Cron to Run

One thing that’s easy to overlook is setting up Drupal’s cron tasks to run. Most web hosts provide a way to configure “scheduled tasks” or “cron jobs” in the hosting panel. Drupal’s cron.php fires updates for RSS aggregators, launches the search indexer, and any tasks defined in installed modules. In addition, it will perform some basic maintenance tasks like deleting temporary files and clearing logs. The Drupal installation guide covers cron in detail with several methods for configuring it.

7 – Disable CCK Content Permissions

While this tip technically falls under tip 5, I figure it’s important enough to be explicitly outlined. The CCK module comes with several sub-modules. One of which is “Content Permissions”. This enables site administrators to set permissions on a per-field basis. Unless your site absolutely needs per-field permissions, this is a no-brainer to disable. The less permission checks your site has to run the better!

8 – Disable Database Logging

Again, another one that technically falls under tip 5, but I feel is especially important is disabling the database logging module. This module will log a wide variety of actions performed on the site to the database. If you’re the only administrator, this module’s usefulness is greatly reduced and should be turned off. Alternatively, you can enable the syslog module which ships with core instead. This will write the more technical log entries to the server’s standard log on the file system and save the database queries.

9 – Use a Third Party Comment System

This one isn’t necessarily Drupal specific, but an easy way to off-load quite a bit of processing on a popular site. Since Drupal’s caching system is far more effective when only serving to anonymous users, if the only reason you have user registration enabled is to allow them to write comments, you may consider off-loading that task to a free third party service like Intense Debate or Disqus. A small clip of javascript is all you need to include into your template (or include it via a block), to embed a robust comment system into your site. Also, if your visitors read other sites that use Intense Debate or Disqus and already have an account (or use OpenID), they’ll already have an account to comment on your site. As of this writing, there is a published module to add Disqus support as well.