Tuning up Drupal performance
Yesterday I was invited to the meeting in office of Gorod.ua, the Ukrainian web portal, to speak about Drupal performance. The way like those guys are using Drupal is good, however there are lack of performance. They are spreading a spirit of their child to the whole of Ukraine, so it is a time to expect more visitors. We spoke a lot and I got better understanding of what is needed. We touched many problems, including non typical ones and theoretically solved them.
In this post I'm going to introduce the effective ways of improving performance in Drupal. I've made a review of most popular caching modules and going to show you Drupal performance best practices table, which will help you to chose best caching module depending on your hosting type and Drupal version.
Pressflow is Drupal distribution that is already configured and patched to improve performance. Features:
- patched/optimized PHP and MySQL code
- caching proxy server (Varnish) support
- db replication support
- allows to rewrite critical parts in code using Java language
- easy to port site from Drupal to Pressflow
- there may be compatibility issues with other nodules
- read more
Pantheon is virtual LAMP stack with Pressflow and Varnish configured. Pantheon is distributed as Project Mercury AMI (Amazon Machine Image) that can be run only in Amazon Elastic Compute Cloud. This is very cheap start and have rally great benefits for some cases. To learn more, click here.
Tunning up performance for anonymous users
Anonymous user in most cases sends only GET query to the server. Any page which is returned by GET query is easy to cache. Caching avoids making lot's of queries to database and running php code, which are often unnecessary. Hence, caching significantly improves response time. There are several modules, which provide caching of static pages for anonymous users on your Drupal site. You could experiment with setting cache lifetime and memory/storage limit.
This module provides integration between your Drupal site and the Varnish HTTP Accelerator, an advanced and very fast reverse-proxy system. Basically, Varnish handles serving static files and anonymous page-views for your site much faster and at higher volumes than Apache, in the neighborhood of 3000 requests per second. You need to install varnish on your server and to patch your D6 installation or to use Pressflow.
When using Boost or Varnish you may also need to configure Ajax Blocks module, which is described below.
Tuning up performance to authenticated users
This is the bottleneck of Drupal. You can feel that experience when many registered users are online. Generally they generate POST queries, which result could not be cached, however there is other approach to handle the performance and several modules which are be described above do this.
Memcache is free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. When used for Drupal it caches results of SQL queries, which significantly improves Drupal Memcache performance. Memcache is widely used in Drupal community to speed up sites. Memcache API and Integration requires:
- PHP 5.1 or greater
- Availability of a memcached daemon
- One of the two PECL memcache packages: memcache PECL package or memcached PECL package (recommended).
The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code. Besides being a opcode cache it provides a user cache for storing application data. This module uses the APC user cache as a cache backend for Drupal. It works only in D7.
Flexible cache tuning
CacheRouter is a caching system for Drupal allowing you to assign individual cache tables to specific cache technology. CacheRouter has an option to utilize the page_fast_cache part of Drupal in order to reduce the amount of resources needed for serving pages to anonymous users. It supports: APC, Database, Cache Router, eAccelerator, File, Memcache, Memcached (Alpha), XCache. It have been released for D6 and D5.
The Authcache module offers page caching for both anonymous users and logged-in authenticated users. This allows Drupal/PHP to only spend 1-2 milliseconds serving pages, greatly reducing server resources. A separate cache is created for each user role as defined by the administrator, so some roles can be excluded if necessary. Authcache can store cache using different caching handlers: Drupal database, Cache Router, Memcache API, etc. It significantly increase performance when used together with Pressflow or Memcache, read more.
Work around dynamic content problem
Sometimes when using full page caching (Boost or Varnish) or caching with a big lifetime you may want to show dynamic content (which is often changed) in blocks. Following modules handles this problem.
Permits to load some blocks by additional AJAX request after loading the whole cached page when the page is viewed by anonymous user. It is suitable for sites which are mostly static, and the page caching for anonymous users is a great benefit, but there are some pieces of information that have to be dynamic.
Alter cache settings per block. Cache settings per block are now set in code, but if you don't like the default - usually none - you can now easily change this. Install this to speed up block rendering for authenticated users. Module works for D7 only.
Playground for ripping the boost expiration code out so other modules can use it. There is now experimental integration with the Varnish module. Support for Node pages, User pages, Comments, Taxonomy, Path Aliases, Front Page Promotion, The Menu Tree, Votingapi, CCK Node Reference, Path Redirects, Domain Access.
This module integrates Drupal with the Apache Solr search platform. Solr search can be used as a replacement for core content search and boasts both extra features and better performance. Among the extra features is the ability to have faceted search on facets ranging from content author to taxonomy to arbitrary CCK fields. There are also many module which extends functionality of Apache Solr Search Integration.
Drupal performance best practices table
|VPS or dedicated server||Shared hosting|
Block Cache Alter.
Block Cache Alter.
Cache Router (file),
To understand if you are succeed with making your website faster, test it's performance before and after tuning. For this kind of job you can use http://jmeter.apache.org/ or special Drupal module called Blazemeter, which allows to record testing script using Selenium and run it on up to 60 dedicated service using website http://blazemeter.com/.