Menu icon
RedCrackle
Menu icon
Services
01Design Transformation
About UsCase StudiesBlogContact Us

<

Blog post

Drupal Performance Optimization Checklist

Neerav Mehta

Founder & CEO

You must have read plenty of articles on how to tweak your Drupal site to improve its page load times. This post assembles an exhaustive list of all the configuration changes you can do that help in Drupal performance tuning.

Caching

  1. Enable block cache. Blocks that don't change from one user to another can be cached and served.

  2. Enable Drupal cache for anonymous users. Use this if you are not using any other caching solution such as front-end cache (Varnish) or Boost.

  3. Cache views. There are plenty of options:Use this patch if you want to cache filtered results based on exposed filter selections as well.

    1. Time-based (built into core). Use this if you want to expire the Views cache after a specific period of time and if you are fine serving stale content for some period of time.
    2. Content cache. Use this if you want to expire the Views every time a content is inserted, updated or deleted. Use this if you expect content changes to happen rather infrequently on your site.
    3. Row cache. This caches the rendered output of each row separately but the query is not cached. Row results from the query are converted into a hash to store the rendered output of each row. If the row result changes, then the result is rendered again otherwise it is fetched from cache. Use this if you expect content changes to happen frequently on your site.
  4. Cache panels. There are plenty of options:

    1. Content cache. Use this if you want to expire the Panel cache whenever content is inserted, updated or deleted. Use this if you expect content changes to happen rather infrequently on your site.
    2. Page cache. Use this if you want to cache panel based on Drupal path and URL.
    3. Hash cache. Use this if you want panel to be cached with more granularity than just Drupal path and URL. This module allows you to create a custom hash for the cache based on contexts, arguments, Drupal path, URL, users and roles. Cache is expired automatically whenever any element of the hash changes.
  5. Cache rendered entities using Render cache module. You could also use Display cache module instead.

  6. Install distributed cache that can store cache tables of the database in memory or file. Drupal creates and uses its own cache. By default, it is stored in database in tables whose names start with "cache_". A distributed cache can instead store these caches in memory or file. The popular ones are:I prefer memcache since it's easy to install and configure. A lot of developers prefer Redis. I believe it's a tie between memcache and Redis. File Cache will be the slowest of the three so don't go with that.

    1. Memcache or Memcache Storage

    2. Redis

    3. File Cache

  7. Cache entities using Entity cache module. For warming up the entity cache, you can use Entity Cache Loader module.

  8. Enable Far Future Expiration for static assets. See the Webserver section of this article below for more details.

  9. Install a front-end cache. It stores the HTML response in memory. The next time, the same page is requested, it returns the HTML from memory. As a result, on the second request, web server and PHP are completely bypassed and the page load time is much faster. There are two good open-source front-end caches: Varnish and Squid. Drupal has much better support for Varnish such as expiring particular URLs using Rules. That's why I prefer Varnish.

    1. Installation instructions for Debian/Ubuntu, Fedora/RHEL/CentOS. Varnish does not work on Windows.
    2. Configure Varnish for better performance
  10. Use cache_get() and cache_set() functions in your custom modules to cache results from your custom functions.

  11. Use cache warmer to maintain fresh pages in cache. Use this for homepage and other Views pages that you don't want to clear on any content update.

  12. Use Content Delivery Networks (CDN). Cache static content (CSS, JS, fonts, files and images) using CDN such as AWS Cloudfront, Akamai, Fastly or Cloudflare. There are two advantages to using a CDN:

    1. Since CDNs have a different domain than your site, browsers load content from CDN in parallel to the requests to your domain. This speeds up page load even more.
    2. CDNs have endpoints throughout the world so the network delay is reduced.
  13. Use Asynchronous Prefetch Database Query Cache module for prefetching cache calls.

Contributed modules that improve performance

  1. Use Fast 404 module to return pages with 404 error without full Drupal bootstrap.
  2. Enable CSS/JS aggregation.
  3. Install and enable Advanced CSS/JS Aggregation module. Here is what you should do using this module:
    1. Reduce the number of CSS/JS files even further than what Drupal core can do.
    2. Gzip CSS/JS
    3. Minify CSS/JS - You could use Speedy module instead.
    4. Move JS to the bottom - Enable this feature with care. Your site may break if it needs some JS in the header. This can also be done by LABjs module.
  4. Create image sprites so that multiple background images can be served in the same request. Here are some ways to create sprites:
    1. Sprite generator
    2. CSS Sprite Generator module
    3. Spritesheets module
  5. Lazy load images so that only the images above the fold are requested initially. When user scrolls down, additional images are requested. There are multiple Drupal modules available:
    1. Image Lazyloader module
    2. Lazyload module
    3. Lazy image loader module
  6. Laze load images in Views using Views Lazy Load module.
  7. Use Imageinfo Cache module to pre-generate image styles before they are requested for the first time. By default, Drupal generates image styles only on the first request. Using this module will ensure that the image style has already been created beofre the first request and even the first request is fast. In general, this module won't decrease your page load time much so use this only if you really really need 5 ms of reduction in page load time.
  8. Optimize images and reduce their size. There are multiple ways to do this:
    1. ImageAPI Optimize module.
    2. optipng
    3. jpegmini
    4. jpegoptim

Convert non-transparent pngs to jpgs since jpgs are smaller.

  1. Disable logging using Performance module.
  2. Use Shadow module to create shadow tables for slow queries.
  3. Use Views Litepager module to eliminate COUNT queries from Views. InnoDB tables in MySQL do not store total count and hence a count query requires the engine to actually count the number of rows and that can slow down the query.
  4. Use Picture module for rendering responsive images. This ensures that on small screens, smaller images are downloaded which saves bandwidth and decreases page load time.

Miscellaneous

  1. Disable and uninstall modules that are not required for your application such as Update Manager and Statistics.
  2. On production, disable and uninstall modules that only provide UI functionality. Most common ones are Views UI and Rules UI.
  3. Disable Database log (dblog) module so that logs don't write to database. Enable syslog instead.
  4. Fix PHP code so that notices, warnings and errors are not generated and as a result, logging is minimized.
  5. Disable and uninstall modules that are active in the dabase but missing from the file system using Missing module.
  6. Use suggestions from Performance and Scalability Checklist module to improve performance.
  7. Rewrite your custom modules so that only the hooks are present in .module file. All the other functions should be in other files. Include these files as needed using module_load_include() and form_load_include() functions.
  8. Disable PHP Filter. It uses eval() function to run the code and that is slower than code that is compiled.
  9. Reduce the number of times that cron is run. By default, cron flushes Drupal's cache and as a result, frequent cron runs will trigger frequent cache flushes.

Advanced methods

  1. Cache pages for authenticated users. Front-end caches generally cache pages for anonymous users. If your site is being used mostly by authenticated users, choose one of the following two options:
    1. Cache pages using front-end cache such as Varnish after removing all the cookies. All blocks that have user-specific or page-specific content are loaded using AJAX via AJAX Blocks module. The advantage of this approach is that webserver and PHP are not called when returning base HTML to the browser and as a result page load time decreases dramatically.
    2. Cache pages for authenticated users using Authcache. Use authcache if most blocks in your pages has user-specific or role-specific content. Although this is an excellent module and it works very well, it requires some configuration and maintenance. Also since it uses webserver and PHP, page times are slower than using a front-end cache such as Varnish.
  2. Speed up DNS requests. When you type a website URL in the browser, browser first contacts a DNS service to find the IP address. Typically this request takes anywhere from 50 ms to 200 ms. You can use DNS Anycast network to reduce this time. Some services that can help with this are: AWS Route 53, easyDNS, DNS Made Easy, Akamai, Dyn and Neustar UltraDNS.
  3. Use CDNs for serving dynamic content such as your complete HTML page. With this, you get the above two benefits even for your normal pages and not just for static assets. This requires a lot of configuration and we'll post another article on this soon.
  4. Inline critical CSS/JS. Browsers need to send multiple requests to the server before it can start rendering a page. Once it receives the HTML from the browser, it needs to request all the CSS and JS files present in the header. These are blocking requests and the page won't start rendering till they are received. By inlining the CSS/JS that you need to render the content that is above the fold, browsers don't need to make any more request to start rendering and hence the user perceives the page load times to be faster. This is a tool that is extremely useful for mobile devices since their bandwidth is generally limited and hence easy response takes a long time to arrive. There are multiple ways to do this:
    1. CSS Delivery module
    2. Pagespeed module for Apache and nginx. This can inline the critical CSS/JS on the fly and you don't need to change your site at all.
    3. Penthouse
    4. Critical

Database

  1. Tune MySQL for better performance.
  2. Index slow queries.
  3. Optimize Views so that they use INNER JOIN instead of LEFT JOIN.
  4. Enable and configure MySQL query cache. It stores the results of past queries in memory. Next time the same query comes, it first sees if the results are already in memory. If yes, it returns the results from memory. If not, the query is passed to the MySQL query engine to fetch the results. MySQL query cache is always up-to-date, i.e. if any of the tables on which the query depends is modified, then the cache is cleared automatically. As a result, there is no need to clear MySQL query cache manually.
  5. Replace MySQL with Percona Server, a drop-in replacement that offers better performance
    1. Use XtraDB storage engine instead of InnoDB
    2. Configure Percona Server for better performance
  6. Use MongoDB for storing key-value pairs.Using MongoDB does provide performance improvement of about 5% over MySQL. I prefer using Percona Server and then tuning it for better performance.
    1. Installation instructions for Debian/Ubuntu, Fedora/RHEL/CentOS, Windows
    2. Configure MongoDB to work with Drupal.

Webserver

There are plenty of open-source webservers. The two most frequent ones used with Drupal are Apache and Nginx. I have also seen IIS being used on Windows.

  1. Apache
    1. Installation on Debian/Ubuntu, Fedora/RHEL/CentOS, Windows
    2. Configure apache for better performance
    3. Enable far future expiration for static assets
  2. Nginx
    1. Installation on Debian/Ubuntu, Fedora/RHEL/CentOS, Windows
    2. Configure nginx for better performance
    3. Enable far future expiration for static assets
  3. IIS
    1. Installation on Windows

    2. Configure IIS for better performance

    3. Enable far future expiration for static assets I prefer using nginx since its event-driven model makes it much faster and more memory-efficient than Apache.

PHP

  1. Install PHP Opcode Cache. PHP is an interpreted language and it compiles during run-time. Compiler compiles it in two passes. In the first pass, PHP code is converted to an intermediate code (Opcode) which is platform-independent. In the next pass, this code gets converted to binary. Opcode caches store the intermediate code (Opode) in memory so that the next time code runs, compiler can fetch it from memory and skip the first pass. There are plenty of open-source Opcode caches available. Following are the popular ones. I prefer APC because it's easy to install and configure. Starting with PHP 5.5, PHP comes with Zend Optimizer by default so there won't be any need to install Opcode cache separately.
    1. APC
      1. Installation instructions for Debian/Ubuntu, Fedora/RHEL/CentOS, Windows
      2. Configure APC for better performance
    2. eAccelerator
      1. Installation instructions for Debian/Ubuntu, Fedora/RHEL/CentOS, Windows
      2. Configure eAccelerator for better performance
    3. XCache
      1. Installation instructions for Debian/Ubuntu, Fedora/RHEL/CentOS, Windows
      2. Configure XCache for better performance
    4. Zend Optimizer
      1. Installation instructions for Debian/Ubuntu, Fedora/RHEL/CentOS, Windows
      2. Configure Zend Optimizer for better performance
  2. Use PHP-FPM. It is a high-performance FastCGI Process Manager.
    1. Installation instructions on Debian/Ubuntu, Fedora/RHEL/CentOS, Windows
    2. Configure PHP-FPM for better performance
  3. Compile PHP into binary. There are two options:
    1. HHVM
    2. Recki-CT

If you are compiling PHP, make sure to test the application thoroughly before deploying it to production.

OS

Improve the performance of:

  1. Debian/Ubuntu
  2. Fedora/RHEL/CentOS
  3. Windows

Hardware

  1. Replace disk drive by SSD (solid-state drives). I have seen a huge gain in performance using SSD.
  2. Increase RAM to make sure that swap never gets used.
  3. Increase CPU speed.

If I have missed out on any technique, please let me know by writing a comment below and I'll prompty include it in this list.

Related Articles:

Neerav Mehta

Neerav Mehta

Founder & CEO

Neerav Mehta is the Founder & CEO of Red Crackle. With sterling qualities, Neerav’s technological acumen is firing a generation of progressive companies on the digital path. With an undergraduate degree in Electrical Engineering from India's most prestigious institution IIT Bombay and having spent seven years developing and contributing to the launch of AMD's innovative line of computer products, Neerav founded Red Crackle where he is lauded for his dynamic and innovative genius.

View all posts

>

Read Next

10 Tips For Entrepreneurs In 2015

10 Tips For Entrepreneurs In 2015

Learn more

10 Ways To Increase Productivity At Work

10 Ways To Increase Productivity At Work

Learn more

30 best WordPress widgets for your site

30 best WordPress widgets for your site

Learn more

Let’s get you started!

Contact Us

>

RedCrackle

Explore

About Us

Services

Contact Us

Our address

5346 Gerine Blossom Dr,

San Jose, CA 95123

USA

Socials

Twitter
LinkedIn

© 2023 RedCrackle. All rights reserved.