At Focalworks, we have worked with Drupal since 2011, creating websites, portals, web applications, and even an Intranet. Drupal offers a suite of tools (or modules) that make it ideal for handling a large volume of content and rapid development. However, the infrastructure on which you run your Drupal instance can significantly impact performance. In this blog, we’ll discuss crucial tweaks to enhance the performance of a Drupal website.
The Strengths of Drupal
Drupal is an excellent CMS for rapid website development. Its theming layer offers a clear separation of concerns, allowing front-end developers to work independently on HTML markup. You can write HTML, CSS, and JS based on design requirements and then integrate that markup as a theme within a module to fetch data from the database.
Recently, we have started exploring Drupal’s Paragraph module, which has added a new dimension to our workflow. While this topic is detailed in a separate blog—discussing the proper use of paragraphs and BEM format—interested readers can refer to the provided link for more information on the module and its concepts.
Performance Concerns with Drupal 8
Our experience with Drupal dates back to 2009, starting with Drupal 6, and we upgraded to Drupal 7 in 2011 to leverage its improved features. However, performance was a significant concern, particularly with authenticated users. Although Drupal 7 has its strengths, it can be a performance hog. Understanding the reasons behind its slowness is crucial to finding solutions.
Drupal’s architecture allows for extensive customisation without altering core files, thanks to hooks, theme registries, and module discovery features. While these features are beneficial, they can impact performance. Moreover, the CMS’s generic nature means that extending its architecture can lead to performance issues. For instance, each content type in Drupal can have numerous fields, creating multiple tables in the database. As Drupal builds a node, it queries several tables, which can degrade performance if not managed properly.
Enhancing Performance with Caching
Drupal’s Cache API has significantly improved from Drupal 7 to Drupal 8. It supports caching blocks and pages by default and minifies and aggregates JS and CSS files. However, these features are primarily useful for anonymous users. For sites with logged-in users, some caching mechanisms, like page cache, may not be applicable due to personalised content.
To address this, we utilise caching software such as Redis. Redis is a valuable tool not only for Drupal-based sites but also for applications built with Laravel and other PHP frameworks. By installing Redis and configuring the Drupal Redis cache module, we can cache frequent queries, allowing Drupal to retrieve data from RAM instead of the database.
Leveraging Advanced Caching Modules
One module that significantly improves performance is the Dynamic Page Cache module. Unlike the traditional page cache module, which caches rendered HTML for anonymous users, the Dynamic Page Cache module uses Drupal’s cache context to cache responses based on individual user contexts. Wim Leers’ article on Drupal 8 Dynamic Page Cache offers insightful information on how this module can impact performance.
Another powerful tool is Varnish, which can greatly enhance site performance by serving content directly from the server’s RAM memory, bypassing the database for anonymous users. Varnish can also be beneficial for logged-in users, as Drupal’s cache API uses block-level cache and dynamic page cache. However, setting up Varnish requires thorough configuration and tweaking of Varnish Configuration Language (VCL) files.
Looking Ahead
In addition to Varnish and Redis, we are exploring further performance optimisation techniques such as Big Pipe and caching responses for authenticated users via a CDN. Big Pipe, in particular, has the potential to significantly improve the speed of rendering the first element on public-facing websites. We look forward to sharing our experiences with these advancements once we implement them in a production environment.
Table of Contents