Cloud Platform

Improving application performance


This page provides a checklist of possible performance optimizations for your Cloud Platform application. Each Drupal application is customized to meet your organization’s business goals, and not every specific recommendation may apply to your application. This list is ordered by priority of impact: the items at the beginning of the list generally provide greater return than those at the end.


Drupal excels at dynamically generating content, serving up different content depending on the user and the context. To dynamically generate the webpage sent to the browser, Drupal runs a series of complex events, 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 surrounding the main content of the webpage

Running these steps on every webpage render can result in slower page loads than serving a static webpage. Effective caching strategies can greatly improve performance by storing webpages, webpage elements, and other resources so 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 resources. By using Drupal’s aggregation settings to combine these resources together, 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 in the current Drupal version

To enable CSS and JavaScript aggregation in the current Drupal version:

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


Enabling in Drupal 7

To enable CSS and JavaScript aggregation in Drupal 7:

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



Acquia recommends testing CSS and JS aggregation settings on non-production environments first. In rare cases, it has been known to cause issues usually because of the order in which they were aggregated.

 PHP memory usage

Each Cloud Platform infrastructure has a fixed amount of PHP memory available for building webpages. Cloud Platform Professional customers can configure the PHP memory limit, as described in Configuring PHP memory limit. Large and complex webpages can consume a lot of memory, and if your infrastructure 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

The following database optimizations can help improve performance:

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 you can review to discover database queries taking an excessive amount of 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 Cloud Platform 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 MySQL slow query logs 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 your application, and seriously degrade the ability to support and maintain it post-launch. Do not hack core! Through the proper use of contributed and custom modules and Drupal’s APIs, you can achieve your application’s goals without hacking Drupal core.

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 modules you don’t need, to prevent PHP from including them at runtime.

Larger, custom modules should use includes in their hook_menu implementation, such as * and *, 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. Every page view generates statistics, and 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.

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 Cloud Platform 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. Cloud Platform compresses HTML, CSS, and JavaScript files by using mod_deflate on each Apache infrastructure:

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:

Extremely large numbers of files

In Cloud Platform, uploaded files are separate from the Drupal database and your code repository. Cloud Platform deployment code creates a symbolic link to your application’s /files directory. For more information, see Understanding files.

Maintaining an extremely large number of files in your application can have a substantial negative effect on performance and stability, especially if the files 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 infrastructure’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 infrastructure 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:

Image optimization

Images often make up a majority of the downloaded data on a webpage, so 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.