Drupal 7 Performance Optimization Options and Checklist

Topics: 

As great as Drupal 7 core can be, it doesn't scale well for Web sites with a lot of content and/or a lot of users. To make it perform better under these scenarios, it's necessary to make use of several strategies, tools and techniques.

Although some of items mentioned here can simply be enabled on all Drupal sites to increase performance, I would instead recommend that folks target problematic areas that will be different for each and every situation. Take a holistic perspective, and whittle down problem areas to reach a specific performance target. Basically, it's essential to take measurements before and after making changes. Otherwise, you could be increasing complexity unnecessarily and targeting the wrong areas, thereby missing opportunities for larger gains.

I've split this article into several categories listed below. Click on any of these to jump directly to the respective section.

  1. Configuration Best Practices
  2. Views Caching
  3. System Administration
  4. Cache Replacements
  5. Cache and Optimize Specific Components
  6. External Caching
  7. Cache Warming / Priming
  8. Services
  9. Drupal-Specific Hosting
  10. Tools
  11. Useful References

Configuration Best Practices

Views Caching

As the Views module is the most popular contributed module, most of us are using it to display content is various ways. Views instances should be cached so that when accessed, a cached copy is returned instead of having to rebuild each view every time it's loaded. There are two (2) options here.

  • Time-based caching for each view display (ships with Views)
  • Views Content Cache: Update each view only when its constituent element have been updated.

If you've got a lot of content and are using Views paging, you may want to consider using Views Litepager. It will work around slow COUNT queries on InnoDB tables, those using the default table-engine type in MySQL.

System Administration

  • Alternative PHP Cache (APC) for PHP < 5.5. (This is part of core PHP in newer versions.)
  • PHP-FPM (a FastCGI implementation) instead of mod_php.
  • Nginx: An alternative to the ubiquitous Apache Web server.
  • Syslog: OS-integrated logging: Send logs to your operating system instead of writing to your database.
  • Solid state drives (SSDs): These cost more, but if you can afford it, use them instead of classic hard disk drives (HDDs) in your server hardware.
  • Disable automatic cron & run a proper cron job: Ensure that users aren't running periodic tasks before they see content. It's usually not necessary to run it more than once per day, but if more granular control (over which tasks are run when) is necessary, one can set up the Elysia Cron module.

Cache Replacements

The default Drupal-site caching is not very efficient. As a result, alternative mechanisms have sprung up to fill the void.

Cache and Optimize Specific Components

If there are specific components of your site that need a performance boost, the following list will help you target certain areas in specific ways.

External Caching

It's possible to place another application in front of yours that will serve cached copies of your Web pages. This is called "HTTP acceleration" or "reverse proxy caching". There's really only one game in town, but it has some helpful add-ons.

If you don't have access to Varnish (usually because of shared hosting), then you can run Boost instead.

Cache Warming / Priming

If caching systems are used heavily (for a lot of content), it may take quite a while for cached data to get rebuilt whenever caches are cleared. If this is the case, it's worth considering a tool to rebuild these after any clearing happens. Otherwise, the first users hitting the site afterwards will experience slow page-load times.

Services

There are several services that can be used in conjunction with your Drupal site to monitor and/or increase performance.

Drupal-Specific Hosting

There are some fine folks out there that will manage the infrastructure for you. If you don't need to be managing your own software stack, it's probably best to let others do it. The options below generally include infrastructural features mentioned in this post.

Tools

There are several tools available for tracking your performance.

Useful References

Some great tips can be found at the following links.

Comments

great article!!

Hey Colan,

Just stumbling upon this now. Great write up. Couple comments:

- at the very beginning you mention: "it's essential to take measurements". Yes, fully agree, benchmarking is key to any successful optimization plan. Perhaps in a spin-off article you can suggest techniques to do this. :)

- you mention Drupal specific hosting as an improvement. What is it about these that makes them "better"? I have a CentOS dev server that I host all my development work on that runs me just over $100/mo. We recently moved one of the sites we developed for a large US university to an Acquia hosted solution. I think the site runs about roughly 1/2 the speed there that it does on my $100/mo server (at I am sure significantly greater cost).

- re: disabling modules you don't need on Production. Yes, great.. but kinda bites that Drupal (afaik) has no way to enable/disable modules via settings.php or similar. Without this, if you disabled a pile of "dev" modules, you are stuck manually re-enabling them on your dev environment every time you grab a db snapshot from your production site. ugh!!

Thanks for the great write-up.

Is there typical reason for very long FIRST HITS?

Hello, for me first hit on a drupal site always seems to lag. Now I am developing on a multisite remote installation that takes a long as 30 seconds to respond if I haven't worked on it for a few hours. That first hit takes for ever and the consecutive hits are much better. I know that's totally crazy. When it's this bad, what would you first check? Like what are the most likely culprits. I am a relative newbie.

Very good points

Thanks for sharing, this is indeed nicely compiled list.

You might want to add using amazon s3 buckets for storage of files with Storage API.

Add new comment