Improving application performance

This page provides a checklist of possible performance optimizations for your Acquia Cloud application. Each Drupal application is customized to meet your organization’s business goals; therefore, not every specific recommendation may apply to your application. 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 application’s code and configuration settings to help you optimize performance and security. It evaluates your application by examining many by reviewing several of its aspects and attributes, including many of the ones described in this topic, and then offers advice about fixing any problems it discovers. For more information, see Acquia Insight.

Caching

One of Drupal’s key strengths is the ability to dynamically generate content, serving up different content depending on the user and the context. To dynamically generate the webpage that is sent to the browser, a series of complex events can 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 webpage

Most of these steps are executed every time a webpage is rendered and can take more time than it would take a simple web server to serve a static webpage. An effective caching strategy can greatly improve performance by storing webpages, webpage 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.

CSS and JavaScript aggregation

A single Drupal webpage may invoke many different CSS and JavaScript webpages. By using Drupal’s aggregation settings, you can reduce the number of HTTP requests for each webpage. You can examine the HTTP requests each webpage is making with a web development tool, such as Firebug or YSlow.

Enabling on Drupal 8

To enable CSS and JavaScript aggregation in Drupal 8, complete the following steps:

  1. Go to http://[server_URL]/admin/config/development/performance, where [server_URL] is your application’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, complete the following steps:

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

Enable CSS and JS aggregation D7

PHP memory usage

Each Acquia Cloud server has a fixed amount of PHP memory available for building webpages. Acquia Cloud Professional customers can configure the PHP memory limit, as described in Configuring PHP settings. Large and complex webpages 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 webpage

Overly complex webpages can generate an enormous number of MySQL queries, which can slow webpage building and limit scalability. Even if each individual query is fast, the cumulative load of database queries can greatly slow down webpage load time. To address this issue, you can decrease webpage 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 application’s MySQL slow query log from the Logs page for an environment in the Acquia Cloud interface. 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. For more information, see Using New Relic to troubleshoot site issues.

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 application and seriously degrade the ability to support and maintain the application 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 by using the following steps:

  1. Install and enable the Acquia Connector module.

  2. On the Configuration page for Acquia Settings, in the Allow collection and examination of the following items section, select the Source code check box.

    Enable code checks

Each time Acquia Insight examines your application, it analyzes and reports any points in your code that diverge from Drupal core. You can view alerts for this status on the Insight page for an environment in the Acquia Cloud interface.

Module selection and activation

If you have Drupal modules installed and enabled in your application, they can still adversely affect your application’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, such as *.admin.inc and *.pages.inc, which causes them to not be loaded for every webpage.

Use the Fast 404 module

Use a module such as Fast 404 to serve static 404s for image, icon, CSS, or other static files, rather than bootstrapping Drupal. Drupal 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 applications, this can have a negative effect on performance. Instead, use the core Syslog module, which is included in Drupal core and logs to the operating system logs instead. Enable the Syslog module, and then disable the Database logging module in the Core section of your Drupal application’s Modules administration page.

Do not use the Drupal core statistics module

The statistics module in Drupal core saves data to the main database. Because every page view generates statistics, this behavior can make a large number of writes to the database. On high traffic applications this can have a negative effect on performance. Instead, use another statistics service, such as Google Analytics.

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 webpage 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 environment before you go live.

Profile your code with XHProf

In order to evaluate the performance of your Acquia Cloud application, you can use XHProf, a hierarchical profiler for PHP. Using XHProf, you can see each PHP function called by a webpage, 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

When using third-party CSS and JavaScript, best practices would have you 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, examine your application with tools such as Firebug or YSlow. Identify any CSS or JavaScript that is being included directly from themes or modules using HTML, and modify your code to add CSS and JavaScript by using the proper hooks.

Gzip compression

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

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

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

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 application’s /files directory. For more information, see Understanding files.

If you maintain a very large number of files in your application, 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 2,500 files in any single directory in the files structure can seriously impact your server’s performance and potentially, its stability. If your application requires a large number of files, maintain them in multiple directories. If your application requires a greater number of files and you are concerned about performance, we will be glad to work with you to use external storage, 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 non-production environments may be more vulnerable to this issue, because they 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.

For more information, see Proactively organizing files in subfolders, Optimizing file paths: Organizing files in subfolders, and Using external storage for files.

Image optimization

Because images often make up a majority of the downloaded data on a webpage, excessively large images can impact your application’s performance. Optimizing images can help alleviate this issue. For more information about how to optimize images, see Scoping the impact of image processing.

Contact supportStill need assistance? Contact Acquia Support

Acquia: Think Ahead

53 State Street, 10th Floor
Boston, MA 02109
United States
Phone: 888-922-7842

Map: Google Maps
View other locations