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
- PHP memory usage
- Database optimization
- Drupal core and modules
- Third-party scripts and styles
- Gzip compression
- Very large numbers of files
- Image optimization
Acquia Insight provides real-time analysis of your application's code and configuration settings to help you optimize performance and security. It checks dozens of aspects of your application, including many of the ones described in this topic, and offers advice about fixing any problems it finds. For more information, see Acquia 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, 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 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
- PHP opcode
For information about these different caching techniques, see Caching overview.
Drupal's core search performs queries against the MySQL database. For high-traffic applications, 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.
Enabling on Drupal 8
- Go to
[server_URL]is your application's URL address.
- In the Bandwidth Optimization section, select the check boxes for the following options:
- Aggregate CSS files
- Click Save configuration.
Enabling on Drupal 7
- Go to
[server_URL]is your application's URL address.
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 Configuring PHP settings. 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.
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 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, which is available to all Acquia subscribers at no additional cost. For more information, see Using New Relic to troubleshoot site issues.
Drupal core and modules
You can identify where your web application diverges from Drupal core using Acquia Insight:
- Enable the Acquia Connector module.
- On the Configuration page for Acquia Settings, under Allow collection and examination of the following items, enable Source code.
Then, each time Acquia Insight checks your application, it analyzes and reports any points in your code that diverge from Drupal core. You can see 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, like
*.pages.inc 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 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 which logs to the operating system logs instead. Enable the Syslog module and 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 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 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 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 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 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
mod_deflate on each Apache server:
To compress other file types your application 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 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 2500 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 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.
For more information, see Proactively organizing files in subfolders, Optimizing file paths: Organizing files in subfolders, and Using external storage for files.
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.