Improving website performance

This article provides a checklist of possible performance optimizations for your Acquia Cloud website. Each Drupal website is customized to meet your organization's business goals; therefore, not every specific recommendation may apply to your website. The checklist is ordered by priority of impact; generally speaking, you'll get a greater return from items at the beginning of the list than from those at the end.

Acquia Insight

Acquia Insight provides real-time analysis of your website's code and configuration settings to help you optimize performance and security. It checks dozens of aspects of your website, including many of the ones described in this topic and offers advice about fixing any problems it finds. For more information, see Getting started with Insight.


One of Drupal’s key strengths is the ability to dynamically generate content, serving up different content depending on the user and the context. In order to dynamically generate the page that is sent to the browser, there can be a series of complex events that must be executed, such as the following:

  • Establishing a database connection
  • Loading settings and modules
  • Initializing a user session
  • Mapping the URL to a PHP page callback function to run the application’s business logic
  • Collecting the fringe elements that surround the main content of the page

Most of these steps are executed every time a page is rendered and can take more time than it would take a simple web server to serve a static page. An effective caching strategy can greatly improve performance by storing pages, page elements, and other resources, so that a cached version, rather than a newly generated version, can be served. Caching can come into play at several different levels in a Drupal web application:

  • Drupal caches
  • Varnish
  • Memcache
  • PHP opcode
  • CDNs

For information about these different caching techniques, see Caching overview.

Drupal's core search performs queries against the MySQL database. For high traffic websites, this can put enormous stress on the database server. Instead, use Acquia Search, which removes search load from the database and offers many feature and usability improvements. For more information, see Acquia Search.

CSS and JavaScript aggregation

A single Drupal page might invoke a large number of different CSS and JavaScript pages. By using Drupal's aggregation settings, you can reduce the number of HTTP requests for each page. You can see the HTTP requests each page is making with a web development tool like Firebug or YSlow.

Enabling on Drupal 8

To enable CSS and JavaScript aggregation in Drupal 8.x:

  1. Go to http://[server_URL]/admin/config/development/performance, where [server_URL] is your website's URL address.
  2. In the Bandwidth Optimization section, select the check boxes for the following options:
    • Aggregate CSS files
    • Aggregate JavaScript files
  3. Click Save configuration.

Enable CSS and JS aggregation

Enabling on Drupal 7

To enable CSS and JavaScript aggregation in Drupal 7.x:

  1. Go to http://[server_URL]/admin/config/development/performance, where [server_URL] is your website's URL address.
  2. Under Bandwidth Optimization, select Aggregate and compress CSS files and Aggregate JavaScript files.

Enable CSS and JS aggregation

Enabling on Drupal 6

To enable CSS and JavaScript aggregation in Drupal 6.x:

  1. Go to http://[server_URL]/admin/settings/performance, where [server_URL] is your website's URL address.
  2. Under Bandwidth optimizations, select Enabled for Optimize CSS files and Optimize JavaScript files.

Enable CSS and JS aggregation

PHP memory usage

Each Acquia Cloud server has a fixed amount of PHP memory available for building pages. Acquia Cloud Professional customers can configure the PHP memory limit, as described in Managing your servers. Large and complex pages can consume a lot of memory, and if your server runs out of memory, it can fail. However, the higher the amount of memory available for each PHP process, the fewer processes can run simultaneously.

Database optimization

MySQL queries per page

Overly complex pages can generate an enormous number of MySQL queries, which can slow page building and limit scalability. Even if each individual query is fast, the cumulative load of database queries can greatly slow down page load time. To address this issue, you can decrease page complexity, optimize queries, and use Drupal's cache API to store custom data for faster reuse.

Identify slow database queries

MySQL provides a slow query log that you can review to discover database queries that are taking excessive time to complete. A slow query can indicate improper SQL query construction or PHP code.

You can download your website's MySQL slow query log from the Cloud > Logs page. You can examine the slow query log using tools like Percona Tools pt-query-digest and the MySQL EXPLAIN statement. For more information, see Downloading your slow query log and Tools for parsing a slow query log.

For another approach to identifying resource consumption issues and bottlenecks, consider using New Relic, which is available to all Acquia subscribers at no additional cost. Read more about using New Relic.

Drupal core and modules

Core hacked

Changes to Drupal's core PHP, JavaScript, and CSS files can adversely affect the performance and behavior of the website and seriously degrade the ability to support and maintain the website post-launch. Do not hack core! Through the proper use of contributed and custom modules and Drupal's APIs, you can achieve your web application's goals without hacking core.

You can identify where your web application diverges from Drupal core using Acquia Insight:

  1. Enable the Acquia Connector module.
  2. On the Configuration page for Acquia Settings, under Allow collection and examination of the following items, enable source code collection and examination. Note: For this setting to function, you must also enable Enhanced SSL security.

Then each time Acquia Insight checks your website, it analyzes and reports any points in your code that diverge from Drupal core. You can see alerts for this status on the Insight > Overview > Code tab.

Module selection and activation

If you have Drupal modules installed and enabled on your website, they can still adversely affect your website's performance even if you don't use them. Disable unneeded modules to prevent inclusion by PHP at run time.

Larger custom modules should use includes in their hook_menu implementation, like * and * so that they are not loaded on every page.

Use the Fast 404 module

Use a module like Fast 404 to serve static 404s for image, icon, CSS, or other static files, rather than bootstrapping Drupal. Drupal 7 core includes a basic version of this functionality, but the Fast 404 module provides additional enhancements.

Use syslog instead of logging to the Drupal database

By default, Drupal logs to the main database. On high traffic websites, this can have a negative effect on performance. Instead, use the core Syslog module, which is included in Drupal core and which logs to the operating system logs instead. Just enable the Syslog module and disable the Database logging module in the Core section of your website's Modules administration page.

Do not use the Drupal core statistics module

The Drupal core statistics module saves data to the main database, and since every page view generates statistics, it can make a large number of writes to the database. On high traffic websites, this can have a negative effect on performance. Instead, use another statistics service, such as Google Analytics or the Cloud > Statistics page.

Disable theme registry rebuilding

Some Drupal themes (such as the Zen theme and the Fusion theme) have an option to rebuild the theme registry on every page load. This is great during development, but can have a severely negative effect on performance. Disable the Rebuild theme registry on every page setting for the theme on your production website before you go live.

Profile your code with XHProf

In order to evaluate the performance of your Acquia Cloud website, you can use XHProf, a hierarchical profiler for PHP. Using XHProf, you can see each PHP function called by a page, with data about the resources used by each function. After you identify functions that may be using an excessive amount of CPU time or memory, you can investigate how to improve the code's efficiency. For more information, read Using XHProf to evaluate code performance.

Third-party scripts and styles

The right way to use third-party CSS and JavaScript is to use Drupal's drupal_add_css and drupal_add_js APIs. Failing to do so can lead to extra HTTP requests and can cause inconsistent behavior of user interface elements. After you enable CSS and JavaScript aggregation, check your website with tools like Firebug or YSlow. Identify any CSS or JavaScript that is being included directly from themes or modules using HTML. Modify your code to add them using the proper hooks.

Gzip compression

Using file compression reduces bandwidth use and improves user perception of website performance. Acquia Cloud compresses HTML, CSS, and JavaScript files, using mod_deflate on each Apache server:

AddOutputFilterByType DEFLATE text/css application/javascript application/x-javascript text/html

To compress other file types your website might output, you can add a AddOutputFilterByType directive to your .htaccess file to configure it for the appropriate MIME types. For more information, see the Apache documentation about:

Very large numbers of files

In Acquia Cloud, uploaded files are separate from the Drupal database and your code repository. Acquia Cloud deployment code creates a symbolic link to your website's /files directory. For more information, see About files.

If you maintain a very large number of files on your website, it can have a substantial negative effect on performance and stability, especially if they are all contained in the same directory. We have found that over 2500 files in any single directory in the files structure can seriously impact your server's performance and potentially, its stability. If your website requires a large number of files, maintain them in multiple directories. If your website requires a greater number of files and you are concerned about performance, we will be glad to work with you to use CDNs or other best practices that can act to mitigate this risk.

These thresholds have some variability, because larger servers may have more resources available to handle the files, and this can reduce the impact. Your Development and Staging environments may be more vulnerable to this issue, since they most commonly share resources.

To avoid this problem, you should split the files into subfolders that are identified by some characteristic of the files. You can use dates as tokens for these directories. The File (Field) Paths and File Entity Paths modules allow you to use node tokens to select the directory where the images or other uploaded files should reside. Select the paths for files attached either through file fields or by way of the Drupal core upload module.

If you already have large numbers of files in a single folder, you can use a Drush script to migrate your files into subdirectories in your file system. See Optimizing file paths: Organizing files in subfolders.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
By submitting this form, you accept the Mollom privacy policy.

Contact supportStill need assistance? Contact Acquia Support