54

Drupal is fast at develop, but the performance is so poor. It is hard to reach 50 request per second.

And there are so many SQL queries in a simple web page. If you test the request time of a form submit in Drupal.org it will always take seconds to finish.

How do you improve the speed of your web site?

2
  • 3
    Have you actually searched the site? I can't imagine this hasn't been discussed repeatedly before.
    – Letharion
    Mar 2, 2012 at 8:22
  • 1
    Checkout my slides goo.gl/30yi39 should help you
    – mikeytown2
    Jul 7, 2014 at 21:41

10 Answers 10

61

Caching, caching, and caching.

Some suggestions I have previously given to a similar question on d.o.

  1. Putting Varnish or another reverse-proxy in front of your http-deamon is probably the single best thing you can do.
  2. During DrupalCon Copehagen, Rasmus stated that using a php opcode cache, such as APC, is one of the best things you can do to speed up PHP in general. Performance improves with newer versions of PHP. There is also additional benefits to upgrading PHP when you upgrade Drupal. From 6 to 8, Drupal will go through a major shift towards object orientation, which is also were most performance improvements happens in the newer PHP versions.
  3. Memcache is a popular choice for speeding up cache, by putting the cache into memory instead of disc.
  4. Panels + Caching combined with Cache actions can increase performance significantly, even for logged in users, as it supports quite complex logic.
  5. The Entity Cache is a nice and zero-conf speed boost for anyone using Drupal 7.
  6. Write-heavy sites have fewer "well established" solutions. Some options include.
    1. Moving frequent writes entirely, for example statistics, somewhere else, such as google analytics.
    2. Caching frequent write operations with a custom solution in something like NodeJS that will write to DB once every Xth second.
    3. Sacrifice the sacred ACID, and use a database like MongoDB. (See Berdir's comment below)
    4. Cluster your SQL-database. Do reads from one database, writes to another. This is native to D7 and Pressflow can help with that in D6.
6
  • All this have been added, but all this is for read caching, not good for the sites have lots of write.
    – Bruce Dou
    Mar 2, 2012 at 9:26
  • You didn't say anything specific about writes. :) I will add something about it in my answer.
    – Letharion
    Mar 2, 2012 at 9:39
  • 1
    Clarification on MongoDB. You can't switch your complete database to MongoDB. MongoDB is something completely different than a DBMS like MySQL and does for example not use SQL. You can only replace certain pluggable components and use them to store a part of your data in MongoDB, for example fields, logs, blocks and so on.
    – Berdir
    Mar 10, 2012 at 15:39
  • @Letharion >> Cluster your SQL-database. Do reads from one database, writes to another. Pressflow can help with that. How can this be achieved ?
    – GoodSp33d
    Apr 17, 2012 at 14:27
  • 1
    Great answer! Definitive. To add to this, have a look at the Advanced CSS/JS Aggregation module as my understanding is that aggregation reduces requests for single CSS and JS files thereby helping improve performance. Sep 17, 2013 at 9:00
23

These are notes from my experiences and might vary from what others experience. I predominantly use LAMP stack and have considered the same in my suggestions.

Thumb rules for caching that I generally follow.

  1. Process Once Use Multiple Times.
  2. Live with stale data when possible
  3. Clear Caches infrequently and keep it very specific.
  4. When possible do the changes at the lowest level in the stack. LAMP - DCCc : Linux, Apache, Mysql, PHP, Drupal Core, Contrib and custom module.

Improve Performance of a Drupal Site (In the increasing order of complexity)

  1. Keep the core updated, contrib module and themes updated. Yes it matters.

  2. Install APC on your server. (Moved to top based on suggestion from Letharion)

  3. Page Caching : admin/config/development/performance Difference between Minimum cache lifetime and Expiration of cached pages

  4. Block Caching https://drupal.org/project/blockcache_alter Caching options for all the blocks.
  5. Aggregate javascript and css files - Front End Improvements https://www.drupal.org/project/advagg
  6. Disable Unnecessary modules. Every module adds to the amount of code that needs to be available for a page load. And it also increases the number of lookups. Wherver possible use a generic module in place of multiple module that does specific functionalities.
  7. Cache Views content - Content aware caching for Views https://www.drupal.org/project/views_content_cache
  8. Disable DB logging - Use https://drupal.org/project/syslog_ng
  9. Reduce 404 Errors - http://www.brokenlinkcheck.com/
  10. Fast 404 Responses - https://drupal.org/project/fast_404 - Try handling at server level.
  11. Client Side Validations - https://www.drupal.org/project/clientside_validation
  12. Compress Image - https://www.drupal.org/project/imageapi_optimize
  13. Lazy Loading of Images - Don’t load unnecessary images - https://www.drupal.org/project/lazyloader
  14. Use Sprite Sheets - https://www.drupal.org/project/spritesheets

  15. Set Minimum Cache Life Time Value to a higher number and use cache clearing modules to clear the caches for specific pages - Whenever I edit/update a node all the page caches for anonymous user are lost

  16. Use Devel Module to watch queries.
  17. Rewrite Views Queries / avoid Views if its a overkill.
  18. XHProf - https://www.drupal.org/project/XHProf
  19. FPM, HHVM.
  20. DB Profiling and Tuning - https://www.drupal.org/project/dbtuner
  21. Use Boost, don't Bootstrap DB if not required. https://drupal.org/project/boost For most of the small to medium sites Boost is good enough and you may not need Reverse Proxies or so.
  22. Use CDNs - https://www.drupal.org/project/cdn Its easy to set up.
  23. If your cache tables are huge use Memcached - If you can install memcached and set up RAM for it, it is not as complex as it sounds.
  24. Etags - Configure Etags properly. https://developer.yahoo.com/blogs/ydnfiveblog/high-performance-sites-rule-13-configure-etags-7211.html
  25. Use Reverse Proxy Server - Varnish(at-least for assets). Helps a lot if most of your users are anonymous.
  26. Compressed transfer - Enable gzip compression
  27. Keep Alive - Use Persistent Connections where possible.
  28. Progressive JPEGS -
  29. CACHING IN CODE - Eaton’s blog is awesome. http://www.lullabot.com/blog/article/beginners-guide-caching-data-drupal-7
  30. Implement Cache Warming - https://www.drupal.org/project/cache_warmer - Cache Warm the pages before the end user hits them.
  31. Master Slave DB Config - https://www.drupal.org/project/autoslave makes it easier for you to set up one.
  32. Database Clusters - https://stackoverflow.com/questions/1163216/database-cluster-and-load-balancing
  33. Load Balancers -http://en.wikipedia.org/wiki/Load_balancing_(computing)
  34. Use heuristic Cache Warming - https://www.drupal.org/project/cache_graceful
  35. Authenticated User Caching - https://www.drupal.org/project/authcache
1
17

Boost module is also quite useful, it creates static file caches from your webpages. It's mostly for websites with lots of Anonymous user traffic.

Boost provides static page caching for Drupal enabling a very significant performance and scalability boost for sites that receive mostly anonymous traffic. For shared hosting this is your best option in terms of improving performance. On dedicated servers, you may want to consider Varnish instead.

Apache is fully supported, with Nginx, Lighttpd and IIS 7 semi-supported. Boost will cache & gzip compress html, xml, ajax, css, & javascript. Boosts cache expiration logic is very advanced; it's fairly simple to have different cache lifetimes for different parts of your site. The built in crawler makes sure expired content is quickly regenerated for fast page loading.

1
  • 1
    Boost works great for Drupal 7 now imao. On a shared hosting solution this is an excellent way to go (as they often don't allow Varnish for example).
    – Sage
    Apr 30, 2015 at 1:13
4

It worth mentioning, if you are using SQLIte database driver you might have to disable disk synchronization.

/**
 * Implements hook_init().
 */
function HOOK_init() {
  db_query('PRAGMA synchronous = OFF');
}

On some server configurations it will improve performance dramatically.

2
  • 2
    Since this disabled it on every page load, I was thinking if there is a better way to disable it permanently. Should spend some time on checking it out.
    – Gokul N K
    Aug 11, 2015 at 7:12
  • 1
    It is possible to do it in sites/default/settings.php, by adding an 'init_commands' element to the $databases array. I found an example for the "PRAGMA synchronous = OFF" here: bitacoles.enging.com/node/210
    – dinopmi
    Mar 3, 2016 at 13:31
3

The secret of Drupal performance is in caching and following the good practices. Suggestions:

Drupal back-end

  • Enable caching in Performance section.
  • Check Performance and Performance and Scalability Checklist modules.
  • Check Drupal 7 Performance Optimization Options and Checklist.
  • Disable unused and non-production modules (such as Devel, Views UI, Rules UI, etc.).
  • Disable unstable modules.
  • Disable statistics.
  • Disable dblog core module and replace with syslog.
  • Disable Update Manager core module.
  • Cron: Use Drupal's builtin cron, not poormanscron (consider Elysia or Ultimate cron).
  • Views: Use cache for views at different layers (database query, markup, time-based).
  • Blocks: Use block caching if your view is a block (per page, user, etc.).
  • Blocks: Consider tweaking cache settings per block by Block Cache Alter module.
  • Panels: Use cache as much as possible (for D7 check PCC & PHC modules).
  • Entity: Enable Entity cache.
  • When using multiple environments, consider missing module which can improve page load.
  • Enable authenticated users page caching with Authcache module.
  • Avoid redirects which slow down the user experience.
  • Enhance cache invalidation by using Expire module.
  • Use PHP profiling before production (e.g. XDebug).

Drupal front-end

  • Minimalize HTTP Requests by:
    • Enable JS/CSS aggregation in Performance section.
    • Use CSS Sprites for reducing the number of image requests.
    • Use small images as inline data (URIs in a stylesheet).
    • Use Image maps to combine multiple images into a single image.
    • Also consider using lazy images loading (see: Image Lazyloader).
    • Install BigPipe module to reduce load times.
    • Consider Lazy loading vs Lazy evaluation.
    • See: Browser Cache Usage - Exposed!
  • Consider making some JavaScript and CSS External (in some cases it's quicker).
  • Minify JavaScript and CSS (see: Speedy module). Avoid inline.
  • When referencing a JS, use either defer or async attributes.
  • Minimize the number of iframes.
  • Optimize images, fonts, CSS Sprites, make favicon small cacheable and reduce cookie size.
  • Reduce the number of DOM elements and cache references to accessed elements.
  • Make your 404 pages load faster by using Fast 404 module.
  • Enable front-end resources aggregation and caching with Advanced CSS/JS Aggregation.
  • Put stylesheets at the top and scripts at the bottom.
  • Add an Expires or a Cache-Control header, also ETags to reduce the responses.
  • Use GET for AJAX and make them cacheable.
  • Preload and Post-load components to take advantage of the time the browser is idle.
  • Sometimes splitting components across domains can maximize parallel downloads.
  • Don't scale images in HTML and keep components under 25k.
  • Avoid Filters, CSS Expressions, HTML elements with empty src or href.
  • Use reverse proxy to debug your web requests (e.g. Charles).
  • Use tools such as Y-Slow and PhantomJS for basic performance checks.
  • Use Google PageSpeed tools to analyze and optimize your website.
  • Read about W3C Navigation Timing specs (GitHub).

PHP

  • Enable PHP caching (e.g. OpCache, APC) and tweak settings.
  • Consider using PHP-FPM instead of mod_php plus Nginx instead of Apache.

Database

Server

High-traffic websites

If you expect high load for your website, use Varnish. Consider also using CDN.

Read more at: Real world experience in scaling and tuning performance


Further resources:

2

There is a book named High Performance Drupal that's provides best practices, examples, and in-depth explanations for solving several performance and scalability issues. You’ll learn how to apply coding and infrastructure techniques to Drupal internals, application performance, databases, web servers, and performance analysis.

In the Performance and Scalability in Drupal 7 article you can find some examples about Drupal 6 and Drupal 7 and the following list:

Drupal 7 performance and scalability projects to watch:

1

There have been a lot of tweaks to optimize the performance of your Drupal site - but not all are imperative though. We have to look around for certain alternatives and techniques that would lead to an optimize platform of Drupal. Cache, yes, it is a way to optimize the website through different means but some more add-ons and tips can increase and tune up your website with no hassle free processes to undertake.

We have published a similar article to our website recently which i believe might help you in doing some tweak work.

Source: http://www.cloudreviews.com/blog/drupal-performance-optimization-tips

1

There are some possibilities to improve Drupal speed for a reasonable level by without installing any new modules. Yes, Drupal has performance configuration.

  1. You can set this up by going to: YourSiteDomain/admin/config/development/performance
  2. Enable 'Cache pages for anonymous users' under Chaching
  3. Minimum cache lifetime: 1 day (If you don't do regular updates)
  4. Expiration of cached pages: 1 day (If you don't do regular updates)
  5. Enable 'Compress cached pages'
  6. Enable 'Aggregate and compress CSS files'
  7. Enable 'Aggregate JavaScript files'

  8. Once this configurations are set, Go to: YourSiteDomain/admin/reports/status

  9. Check for if there is any permission issues for 'css' and 'js' directories
  10. Correct the permission as defined on the Status Report page

And now you are done with the speed optimization for your drupal 7 site.

There are few online speed testing tools to check the speed. Make sure to use one of the speed check tool and run a test before updating the above settings. And once after you have updated the performance setting run the speed test again. You will definitely see improvement.

Pingdom and the HTTP Fox (FireFox plugin) are the best tools to check the site speed.

The above settings not only caches your pages for anonymous users, It also compresses the CSS and JS files. Example if your site is loading 80 files, post these settings the number of requests will cut down to at least by 50%, So here you have 2x speed improvement on your Drupal site.

1

As a backend developer there is always room to improve your code to boost the performance of the website. Some guidelines for backend developers could be:

1) Clean up your watchdog table

2) Don't abuse the variable API

3) Make Fewer or Better HTTP Requests

4) Keep your "dot module" short

When it comes to font-end and site builders much more can be achieve but it is important to take performance into consideration from every point of view.

Source: Optimize before you go live

1

An unoptimized Drupal 7 site with 2 GB of RAM can serve about 20-25 requests per second satisfactorily. If you want to go beyond that, the site will require some tweaking. What you tweak depends on whether most of the users on the site are anonymous or authenticated. Here are the top things you can do for performance improvement:

Site is serving mostly anonymous users:

1) Definitely install and configure APC, memcache and entitycache.

2) Put Varnish proxy in front of the webserver. It takes about 30 minutes to install and configure but will dramatically lower your page load times. In fact, Varnish can handle about 300 requests per second on a 2 GB machine if all the pages are cached. Use Expire module to expire only selected pages on content update/deletion.

3) Use Advanced CSS/JS Aggregation module to aggregate CSS and JS files. Try moving all the JS files to the bottom of the page. But note that this may break your site so implement this on production after thorough testing. Also experiment with inlining critical CSS. In my experience, it will decrease page load time by about half a second.

4) CSS/JS/images should have far future expiry header. This will ensure that browsers won't request for the same CSS/JS/images again and again.

5) Make sure that webserver is serving compressed pages/CSS/JS.

After implementing the above 5 steps, your 2 GB RAM server should be able to server 50 requests per second pretty easily.

Site is serving mostly authenticated users:

Optimizing such a site is more complex. Such sites fall in one of the two sub-categories for optimization purposes:

(a) Most of the pages on the site are identical except 1 or 2 blocks that have user-specific information. For e.g. Drupal Commerce site.

(b) Most of the pages are completely customized for the user. For e.g. Drupal Commons site.

If your site falls in category (a), then apply most of the techniques that we discussed for the site serving mostly anonymous users. The only difference is that for non-admin pages, Varnish will need to remove the SESSION cookie from the header and serve cached pages. Use AJAX Block module to server blocks with user-specific information using AJAX. This way most of the page will be served extremely quickly using Varnish and then user-specific information will be served over AJAX.

If your site falls in category (b), then use Authcache module. I prefer not to use it as much as possible because it requires quite a bit of configuration and maintenance. But it does work really well. It won't be as fast as using Varnish but it will be able to handle 50 requests per second that you are looking for.

If you are looking to go above and beyond what we have discussed here, then have a look at Drupal Performance Optimization Checklist. Disclosure: It is written by me. It cites an exhaustive list of things you can do to make your Drupal site blazing fast.

Not the answer you're looking for? Browse other questions tagged or ask your own question.