Improving website performance
This topic 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
- PHP memory usage
- Database optimization
- Drupal core and modules
- Third-party scripts and styles
- Gzip compression
- Very large numbers of files
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 site, 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
- 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 sites, 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 7
- Go to
http://[server_URL]/admin/config/development/performance, where [server_URL] is your website's URL address.
Enabling on Drupal 6
- Go to
http://[server_URL]/admin/settings/performance, where [server_URL] is your website'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 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.
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
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 collection and examination. Note: For this setting to function, you must also enable Enhanced SSL security.
Then each time Acquia Insight checks your site, 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
*.pages.inc so that they aren't 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 sites, this can have a negative effect on performance. Instead, use the Drupal 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 site's Modules administration page.
Don't 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 sites, 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 site 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
mod_deflate on each Apache server:
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 site requires a large number of files, maintain them in multiple directories. If your site 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.