8 Actionable Tips for Improving Drupal Performance

When you build a high-performing website, everyone wins. Your customers enjoy the advantage of a responsive site that loads quickly. Your developers and engineers can focus on tasks like building and deploying new features rather than troubleshooting performance issues. And your business as a whole benefits from a site that drives higher ROI and costs less to host.

Drupal's flexibility and potential for customization makes it an excellent foundation for building a high-performing website. Of course, you need to take steps to ensure that you’re getting the best performance possible from your Drupal site. From hosting to caching and beyond, there’s plenty to address, and this guide is your jumping off point.

1. Hosting

The right hosting provider is the foundation of any performant website. No matter how well-designed your site or how well-optimized your Drupal configuration, a hosting plan that doesn’t meet your performance needs will undermine your entire web operation.

When evaluating a hosting provider, consider the following factors:

  • Scalability: If your host isn’t able to scale along with your growing business, your site’s performance will begin to suffer, and you’ll eventually be forced to switch providers.
  • Reliability: If your hosting provider goes down, your site goes down. Choose a host that delivers uptime guarantees of 99.99 percent or higher, even during unexpected spikes in traffic. And they should provide you with automatic database backups so you can quickly get back and up and running in the event a disaster strikes.
  • Support services: Hosting companies that provide professional support services help guarantee that a problem like a problematic software upgrade or configuration issue doesn't cause performance degradation on your site. Select a host that offers 24/7 support services and knows Drupal inside and out.
  • Compliance: You shouldn't have to compromise compliance priorities in order to optimize performance. Your hosting provider should offer solutions for whichever compliance frameworks you need to meet, from HIPAA to PCI DSS to FedRAMP.

Download Contegix’s comprehensive guide to Drupal hosting for free.

2. Benchmarking

Benchmarking your site is another core part of maximizing performance. You can’t optimize what you can’t measure, after all. By load testing your site at various benchmarks, you can see how well your site performs under different amounts of stress. With that data, you can take steps to address performance bottlenecks and then evaluate the effectiveness of your changes through additional load testing.

A variety of tools are available for Drupal load testing. Apache JMeter and Gatling are popular open source options, but while free to use, they come with a learning curve. Proprietary benchmarking tools, such as LoadRunner and BlazeMeter — which is built on top of JMeter, but provides additional features — come at a cost, but are often easier to deploy.

3. Caching

For most Drupal applications, the primary performance gains are found by applying caching at multiple layers in the technology stack, whether that be at the database layer, the web server layer (proxy caching), the CDN layer (Geocaching), and even in the site visitors’ browsers.  In brief, caching is a strategy where content that is repeatedly assembled can be indexed and stored for reuse, such that the application does not have to continually assemble or retrieve that content.

And to test the effectiveness of the caching strategy, Drupal product owners can work with their provider to conduct load testing. The results will portray how the system behaves during normal, medium or high traffic periods and, combined with an effective monitoring strategy, can uncover where the performance bottlenecks are within the layers of the technology stack.

Database layer caching

In most Drupal applications, the database will be the primary performance bottleneck because, as a relational database, data is stored and retrieved from a single location by default.  In most Drupal installations, it is the only component that you cannot duplicate without significant difficulty.  While Drupal developers have reported in excess of 200 database queries for a single page load, this author has seen an instance of 1,200 database queries for a single complex page.  Drupal maintains a set of core database tables that serve as an internal cache in order to reduce this load; however, the goal should be to remove as much load on the database as possible.

By installing and configuring Memcache or Redis, you can offload that database activity into a middleware application that is designed as a key-value store – an optimal solution for quickly storing and retrieving cachable data, thus removing that load entirely from the database. 

Proxy caching

Where database layer caching allows a Drupal environment to store small units of pre-processed content outside of the database, the goal of reverse proxy caching is to cache entire web pages (urls) such that the Drupal application, and more importantly the underlying database, is entirely bypassed. 

This is effective for unauthenticated (logged out) website visitors that can be served the same content. A user who requests a page that was previously requested by someone else will receive results much faster because the page does not have to be re-assembled.

Authenticated Drupal site visitors also benefit from reverse proxy caching because images, css, javascript, and other “static” resources can similarly be served.   This is where a good hosting provider like BlackMesh can provide real value to Drupal product owners to help configure a reverse web proxy like Varnish to properly identify patterns of logged out – and even logged in – content that can be cached.

Critical Drupal Components eBook

CDN (Geocaching)

Sometimes provided by the hosting provider and sometimes offered separately, the CDN uses the same principles as Proxy Caching but geographically distributes that such that a consumer in New York is served a page from a server in New York and a consumer in Seattle is served that same page from a copy stored in Seattle. A CDN cache can help mitigate slowdowns or even outages by storing page content close to the geographic location of Drupal site visitors. Just like the configuration of the Proxy Cache, fine-tuning the CDN’s caching rules can go a long way toward optimizing Drupal’s performance.

Browser caching

Where all the other types of mentioned so far improve the experience of all site visitors by caching content shared, browser caching focuses on preventing a consumer from having to load the same content twice.  The hosting provider can fine tune the http headers sent back to the consumer’s web browser which instruct the web browser how long each piece of content should be seen as fresh.  Then as a consumer browses your site, instead of requesting a piece of content a second time, whether it be an image, Javascript or CSS file, or even an entire page, that content can be served from the web browser’s built in cache. 

While Drupal’s defaults do a really good job at setting the headers correctly, some modules or customizations interfere with Drupal’s best practices and need custom overrides.  Further, being able to cache authenticated or “logged in” content often needs tuning on the webserver or reverse proxy cache to set the rules correctly.

Other caching

Some modules in Drupal have additional caching capabilities, and Drupal developers can build their own custom caching as well. For example, Views (which in Drupal 8 was moved to Drupal Core instead of being its own module) has custom caching settings which allow subsequent View renderst to deliver cached data from the initial run. 

Additionally, for extremely high performant websites, advanced caching techniques come into play using a combination of edge side includes, html generators like jekyllrb, and even sql query caching. 

Helpful modules

The following Drupal modules are helpful for setting up and managing caching:

4. Databases

Optimizing your Drupal site’s database to complete read and write requests as quickly as possible boosts performance. Drupal supports MySQL and MariaDB by default, while Microsoft SQL Server and Oracle Database require the installation of additional drivers. Any supported database is capable of delivering approximately the same level of performance.

That said, there are steps you can take to optimize the performance of your database. Clearing cached data from databases after it is no longer needed will reduce the overall size of your database and result in faster queries. OptimizeDB is one tool that helps you do this. You should also check your database for split rows, unused tables, and incomplete or corrupt data. Modules like DB Maintenance are useful for this purpose.

Hosting your Drupal database on a separate server from Drupal itself, and connecting the two servers via the network, may also improve performance. This ensures that the exhaustion of resources on the Drupal host server — which could be caused by issues such as a memory leak or sudden spike in traffic — does not also deprive the database server of resources.

5. Theme Optimization

In Drupal, a theme is a set of files that define how information is laid out and presented on your Drupal site. Drupal has to process these files when the site loads, so inefficiencies in them can lead to performance degradation.

To maximize Drupal performance, you want to keep your theme files lean and mean. Avoid unnecessary characters, such as blank spaces and comments, which can slow down file parsing. Optimize CSS code by removing duplicate or redundant sections. Strive to write theme functions that can handle a variety of tasks, rather than writing a different function for each task. All of these steps will help ensure that Drupal processes your theme files as quickly as possible.

Enabling front end caching, as described above, can also improve theme performance by allowing Drupal to cache some of the contents of theme files, like CSS and Javascript code.

Successful Drupal Components eBook

6. Optimizing Images

The larger the images in your Drupal site, the longer pages that contain those images will take to load. To address this, take advantage of these three ways to optimize images.

First, you can simply reduce the size of the image by shrinking its dimensions. This is the simplest method, but because it leads to smaller images, it is not always desirable. You may require your images to be a certain size in order to fit the layout of your site. Consider using Responsive Images, a module that tailors the size of images to the size of the screen on which they are being displayed. It provides smaller images for smaller screens, leading to faster page loading on devices like phones while still allowing users with larger devices to view images at full size.

The second method is to reduce image size by reducing quality. The downside here is that images can become pixelated or lose some of their color contrasts.

The third, and in most cases best, approach is to use lossless compression. Lossless compression reduces image file size without reducing quality. Typically, it does this by converting the image from its original format to a format that is able to store the image data more efficiently while requiring less disk space. Image Optimize and Images Optimizer automatically perform lossless compression.

7. Disable What You Don't Need

In general, the more active components you have in your Drupal environment, the slower the site will perform. To improve performance, you should remove any components that you aren't using.

Modules are an obvious place to start. You can install a module like Unused Modules to list modules that you have installed but that your site is not actually using. You can then disable them under the /admin/modules/administration page.

Along similar lines, consider removing unused themes. And review themes that you’re using for CSS, Javascript, or other code that’s not being called.

Finally, at the server level, look for unused packages and libraries within the operating system that can be uninstalled, which will free more resources for your Drupal site. It's best to run as few applications and services on the Drupal host server as possible. Starting with a lightweight operating system, such as Linux Lite or Tiny Core Linux, can help you avoid unnecessary components from the start. But because extraneous packages can creep in over time, you should periodically review the operating system for components that can be removed.

8. Content Distribution Networks (CDN)

A content distribution network, or CDN, is a network of geographically dispersed servers that host copies of website data. By spreading copies of your website across a large geographic area, you can bring the data closer to different users and decrease the time it takes for data to travel between servers and their devices. CDNs are a powerful tool for optimizing website performance.

CDNs also offer the benefit of enhanced security and reliability. In the event that one of your servers fails or is disrupted by an event like a DDoS attack, the CDN can automatically reroute traffic to other servers that remain available. This ensures that your users can keep accessing your site.

To use a CDN with Drupal, you first need to set up a CDN service with a hosting provider who offers CDNs. You can then use Drupal's CDN module to integrate your site with the CDN by changing file URLs to match those of your CDN network. Your Drupal site will then automatically serve content to each user from the URL that fits best, based on the user's location in relation to the CDN's servers.

Note that the Drupal CDN module supports only "pull" CDNs, where cached content is shared from the primary server to others on the network by creating unique URLs for each server. In contrast, "push" CDNs send cached content from the main server to others without the use of separate URLs for different network locations.

Get Started by Consulting the BlackMesh Drupal Experts

Implementing the methods above is easier said than done. Some require expertise with special tools, like load testing software. Others demand extensive research into hosting and CDN providers. And still others involve installing and deploying third-party modules within Drupal, which takes time and poses some security risks if, for example, you install an outdated module.

On top of this, simply identifying the greatest opportunities for Drupal performance improvement within your site can be a challenge. How do you know which changes will deliver the greatest performance boost? Is database optimization a better use of your resources than setting up a CDN?

If you're struggling to navigate questions like these, the Drupal experts at BlackMesh are here to help. The BlackMesh team knows the ins and outs of Drupal performance optimization, and they’re ready to act as a trusted partner in assessing your Drupal performance needs. Learn more by contacting us today.