High performance in Drupal Part 1: Give your site a boost
Welcome to part 1 of our series on High Performance Drupal.
Why is my Drupal site slow?
Drupal is a highly flexible CMS with great community support (link is external) in the form of drop in add-ons (contrib modules).
All this freedom means it's really easy to create awesome, great looking websites at the expense of some out-of-the-box performance.
Luckily with a few tweaks any performance penalty can be eliminated, making Drupal lightning fast!
Drupal has a few built-in options which can quickly give your site a boost, so let's start there.
Turn off unsused modules
It may seem counterintuitive but any enabled modules take time to run even if they aren't doing anything, so turn off any modules you don't need.
Turn on aggregated CSS
Enabling this option will shrink and cache all of your beautiful CSS and help speed up the site for your users.
Cache pages for anonymous users
This will really speed things up if you get lots of anonymous traffic, but won't have any effect for logged-in users.
Turning this on will speed up some of the common content components on each page by caching them, but it can have a few side effects so test it thoroughly! The Block Cache Alter (link is external) module offers more fine-grained control with this option.
High performance modules
This module adds automatic caching to content, comments, files, categories and even users and if you're only using contrib modules it won't have any side effects on your site.
If you've developed your own modules which update content directly then you may have to do some tweaking to get it to play ball.
Drupal 7 provides a swappable caching architecture. The default is to use a number of `cache_*` tables in your Drupal database, but this has some performance drawbacks as it puts unnecessary stress on your database.
You can offload the cache storage to Memcache or similar modules such as APC (link is external) and Redis (link is external). Because they store everything in memory they're much faster than your database which can now focus on loading and saving all that important content.
Using this module requires a bit of configuration and you must have the corresponding service and PHP library installed on your hosting. Check out the memcache installation guide (link is external) for more info.
Views content cache
The Drupal views module is a really powerful way to pull together all kinds of content and aggregated data.
Unfortunately it comes with an all or nothing approach to caching, which can be problematic if your content changes frequently.
Here's where Views content cache comes in; it caches your views content and lets you specify the conditions for how and when the cache should be cleared, such as when a blog post is updated or a new comment is added.
Content delivery network
Not only will all these requests impact your web server, but as browsers only load a couple of files at a time it can really slow down your pageload times.
A content delivery network is a service which hosts your static content under a different domain name, which has a whole bunch of benefits:
- Users get your files quicker because they can load content from different domains in parallel.
- User requests are smaller (and so even quicker!) because they don't need to send along any of the cookies from the main site.
- Your webservers can focus on serving content as all the static files are coming from somewhere else.
- You can reduce latency by serving content from servers which are geographically close to your customers, this works best if you have a diverse global audience.
Lightning fast code
Part 2 of our High performance drupal series covers best practices and optimisations for making your custom modules lightning fast!
In the meantime get in touch if you're interested in Drupal training or would like us to peer review your code.