As great as Drupal 7 core can be, it doesn't scale well for Web sites with a lot of content and/or a lot of users. To make it perform better under these scenarios, it's necessary to make use of several strategies, tools and techniques.
Although some of items mentioned here can simply be enabled on all Drupal sites to increase performance, I would instead recommend that folks target problematic areas that will be different for each and every situation. Take a holistic perspective, and whittle down problem areas to reach a specific performance target. Basically, it's essential to take measurements before and after making changes. Otherwise, you could be increasing complexity unnecessarily and targeting the wrong areas, thereby missing opportunities for larger gains.
I've split this article into several categories listed below. Click on any of these to jump directly to the respective section.
- Configuration Best Practices
- Views Caching
- System Administration
- Cache Replacements
- Cache and Optimize Specific Components
- External Caching
- Cache Warming / Priming
- Drupal-Specific Hosting
- Useful References
Configuration Best Practices
- Disable unused and non-essential modules. Loading additional code unnecessarily will consume additional server resources.
- Disable the Statistics module as it writes to the database on every hit. You're probably using Google Analytics anyway.
- Disable the Update Manager module on Production. As part of your DevOps process, after synchronizing your Development/Integration server with Staging or Production, enable it there. Your Production server doesn't need to spend time polling drupal.org.
- Enable site-wide caching over at Administer » Configuration » Development » Performance.
- Convert non-transparent images to JPGs (with some exceptions - see the first comment below).
As the Views module is the most popular contributed module, most of us are using it to display content is various ways. Views instances should be cached so that when accessed, a cached copy is returned instead of having to rebuild each view every time it's loaded. There are two (2) options here.
- Time-based caching for each view display (ships with Views)
- Views Content Cache: Update each view only when its constituent element have been updated.
If you've got a lot of content and are using Views paging, you may want to consider using Views Litepager. It will work around slow COUNT queries on InnoDB tables, those using the default table-engine type in MySQL.
- Alternative PHP Cache (APC) for PHP < 5.5. (This is part of core PHP in newer versions.)
- PHP-FPM (a FastCGI implementation) instead of mod_php.
- Nginx: An alternative to the ubiquitous Apache Web server.
- Syslog: OS-integrated logging: Send logs to your operating system instead of writing to your database.
- Solid state drives (SSDs): These cost more, but if you can afford it, use them instead of classic hard disk drives (HDDs) in your server hardware.
- Disable automatic cron & run a proper cron job: Ensure that users aren't running periodic tasks before they see content. It's usually not necessary to run it more than once per day, but if more granular control (over which tasks are run when) is necessary, one can set up the Elysia Cron module.
The default Drupal-site caching is not very efficient. As a result, alternative mechanisms have sprung up to fill the void.
- Memcache API and Integration or Memcache Storage
- File Cache
- Redis (a key-value store)
Cache and Optimize Specific Components
If there are specific components of your site that need a performance boost, the following list will help you target certain areas in specific ways.
- Cache entities with Entity Cache.
- Cache entity view modes with Display Cache.
- Improve CSS/JS performance with Advanced CSS/JS Aggregation or Aggregate cache.
- Cache Panels content with Panels Content Cache or Panels Hash Cache.
- Load images only when needed with Image Lazyloader or similar modules.
- Minify JS files with Speedy.
- React to page-not-found errors quicker with Fast 404.
- Speed up your site by removing no-longer-available modules with Missing Module.
- Cache components with logged-in users via Authenticated User Page Caching (Authcache).
It's possible to place another application in front of yours that will serve cached copies of your Web pages. This is called "HTTP acceleration" or "reverse proxy caching". There's really only one game in town, but it has some helpful add-ons.
If you don't have access to Varnish (usually because of shared hosting), then you can run Boost instead.
Cache Warming / Priming
If caching systems are used heavily (for a lot of content), it may take quite a while for cached data to get rebuilt whenever caches are cleared. If this is the case, it's worth considering a tool to rebuild these after any clearing happens. Otherwise, the first users hitting the site afterwards will experience slow page-load times.
There are several services that can be used in conjunction with your Drupal site to monitor and/or increase performance.
- Content delivery networks (CDNs) such as CloudFlare
- ProjectPAAS along with its connector module: Drupal-specific performance service.
- New Relic: General performance monitoring that supports Drupal. Works nicely with Pantheon.
- BlazeMeter Module for Load and Performance Testing: General service that works with a plug-in module.
There are some fine folks out there that will manage the infrastructure for you. If you don't need to be managing your own software stack, it's probably best to let others do it. The options over at Drupal-specific hosting: Choose a provider from those offering comprehensive platforms generally include infrastructural features mentioned in this post.
There are several tools available for tracking your performance.
- The Performance and Scalability Checklist module
- The Performance Logging and Monitoring module
- Slow query logging with the Devel module
- The XHProf PHP profiler
Some great tips can be found at the following links.
JPEG and PNG optimization
If an image is not a photograph and has a limited number of colours, a well-optimized PNG may end up being smaller than a JPEG.
Back in 2009, Smashing Magazine ran a series of articles on optimizing images: JPEG Optimization Techniques, PNG Optimization Techniques and More image optimization techniques.
Added note above
#AberdeenCloud for hosting
You forgot #AberdeenCloud in your list of Drupal specific hosts.
Didn't know about it
Very interesting summary, but I missed:
* Boost module
* Don't run cron more often than strictly needed. E.g. One per day.
* Diversify cron executing using Asylia cron module
Just stumbling upon this now. Great write up. Couple comments:
- at the very beginning you mention: "it's essential to take measurements". Yes, fully agree, benchmarking is key to any successful optimization plan. Perhaps in a spin-off article you can suggest techniques to do this. :)
- you mention Drupal specific hosting as an improvement. What is it about these that makes them "better"? I have a CentOS dev server that I host all my development work on that runs me just over $100/mo. We recently moved one of the sites we developed for a large US university to an Acquia hosted solution. I think the site runs about roughly 1/2 the speed there that it does on my $100/mo server (at I am sure significantly greater cost).
- re: disabling modules you don't need on Production. Yes, great.. but kinda bites that Drupal (afaik) has no way to enable/disable modules via settings.php or similar. Without this, if you disabled a pile of "dev" modules, you are stuck manually re-enabling them on your dev environment every time you grab a db snapshot from your production site. ugh!!
Thanks for the great write-up.
Thanks for the feedback
Is there typical reason for very long FIRST HITS?
Hello, for me first hit on a drupal site always seems to lag. Now I am developing on a multisite remote installation that takes a long as 30 seconds to respond if I haven't worked on it for a few hours. That first hit takes for ever and the consecutive hits are much better. I know that's totally crazy. When it's this bad, what would you first check? Like what are the most likely culprits. I am a relative newbie.
See my other blog post
Very good points
Thanks for sharing, this is indeed nicely compiled list.
You might want to add using amazon s3 buckets for storage of files with Storage API.
What about Drupion?
If you search for "Drupal specific hosting" then you get Drupion as one of the top results. Has anyone been using them?
Interesting and Insightful Post
This is quite an insightful post; thanks for sharing some useful tips.
Drupal Performance Analyzer
That is a nice list! If it's of interest for anyone, we have developed a free online tool, that can give quick hints on performance tuning just looking from the public side of Drupal site - http://www.macronsoftware.com/drupal-performance-analyzer . Any feedback appreciated!
Add Varnish in front of Drupal
This is a really great article about the topic we are working on now. We have already added APC and memcached to our Drupal site. APC helps on PHP code execution while memcached speeds up the SQL. Now we are thinking to speed up the static content with Varnish. Do you have any experience with it? Does it worth the extra layer?
My Drupal site slow...
Have a drupal site of mine which is been running slow and did check most of that is mentioned in here and still its not performing as it should be. Meanwhile did see a suggestion on using Apachebooster, did any one in this group has tried their hands on it. Need your suggestion.
Great Article for Drupal!
Our Website was built on Drupal and having heavy load time. I implemented some of the modules you have here and running a lot better. Thank you so much!
My success story of code optimization
While launching new website of Itransition we faced some problems with Drupal compability with Google Speed Insight standards. So we had to use a number of filters and prefer inline-CSS, to avoid code comments and other useless items.
I am using most of the
I am using most of the services mentioned in this article: Nginx, Varnish, Memcached, etc. I highly recommend using these services to speed up your website. My hosting provider, Cloudways (https://www.cloudways.com/en/drupal-cloud-hosting.php ), uses these services in their stack. I didn't know how good these packages are in improving performance before hosting with them. Apart from these services, I am also using Cloudflare CDN on my Drupal website, so this adds to the performance of my website as well. I am also thinking of moving to http/2 and PHP FPM to further improve the performance.
Most of the drupal website we did for our customers at Adoriasoft speed optimizations we did were based on an open-source module "PageSpeed" that can be used either with Apache or Nginx servers.
After thinking a lot how to deal with render-blocking CSS files in the head of the page we discovered that the aggregation and compression provided by Drupal was not a 100%-decision. We enabled a couple of filters to additionally minify and aggregate CSS and configured that module to inline small CSS files in the web-page.
love JCH Optimize
Great info! Just would like to add this module to the list. I love JCH Optimize is great module for optimizing Drupal website speed. It's a one stop optimization module so it basically does almost all performance optimization reducing need of too many plugins.
Add new comment