
Drupal Performance Tuning
January 6th, 2012Performance problems are a bit of an embarrassment of riches. It's great that your site is getting a lot of visitors, but are all those visitors slowing down your site or potentially causing crashes? How do you go about resolving this issue? Unfortunately there's no hard-and-fast answer to performance problems, and examining the shear breadth and depth of the topic would result in the longest and most boring blog post ever. However I will attempt to outline the general strategies you might follow to diagnose and solve problems.
The first step is to consider what part of your site is experiencing problems. A particular page or View, for example, being slow will generally indicate a different set of problems to the entire site feeling sluggish. Another issue to consider is whether it's the backend that's slow, or the frontend. A tool such as Chrome's web inspector can tell you what assets (CSS files, JS files, images) are being loaded, how big they are and how long it is taking, among other useful metrics.
Secondly, it's a good idea to determine what the bottleneck is, if possible. Take a look at the load on your CPU when you notice poor performance as serving complex PHP applications can be quite taxing. You might also want to turn on the Devel module's query log (or the MySQL slow query log) to determine if any queries are taking an exceptional amount of time.
When tuning the performance of a site and its server I'll typically follow a strategy where by I'll implement a number of steps then re-examine performance, before moving on to more gradually more complex solutions if the need arises. On every production Drupal site I'll take the following steps:
- Enable CSS/JS compression
- Make sure APC is enabled and properly configured
- Disable unnecessary modules
- Clean up as many PHP errors as possible, especially if we're logging with the dblog or syslog modules
- Make sure the MySQL query cache is enabled and properly configured
- Sprite images where possible for frontend performance benefits
The aforementioned steps will go a long way to ensuring that your site is performant while having very few, if any, detrimental effects. With that said, sometimes this isn't enough. Fear not, we can go further to attempt to address outstanding issues:
- Cache expensive or time consuming operations, for example, requesting data from a web service. Drupal makes this simple with cache_set() / cache_get().
- Turn on additional caching, such as Views or Block, if possible
- Use the MySQL slow query log and run EXPLAIN on the logged queries. Look for queries which have joins using filesort or temporary tables and determine whether these could be rewritten or sped up with an index.
- Analyze the traffic pattern. A site with a largely anonymous user base can see a significant benefits from implementing the Boost module or Varnish in to the server stack.
- Change cache backends. Drupal reads and writes a lot of data from its caches (as it should) so you can see some great speed improvements storing this data in memory (fast!) rather than the database (on the disk, slow!).
We're still just scratching the surface of optimizations that can be made to a website or the server stack, or even the servers themselves. Scaling vertically (using bigger servers) or horizontally (using more servers) are solutions that are often utilized when a site has outgrown its existing server (and sometimes before that point).
If your interest in performance and tuning has been piqued there's a couple of great resources for Drupal. Swing by the High Performance group (http://groups.drupal.org/high-performance) or http://2bits.com/ for a number of helpful tips on how you can improve the performance of your Drupal website.
We'd also be happy to discuss any questions or observations you might have, so feel free to post a comment!



Comments
There are also useful resources on the documentation page Drupal caching, speed and performance.
Nice resource, thanks!
Good research. I like your article very much. Keep up the great work...
Good article.
The biggest performance improvements to my site (with a large database) were:
- increasing innodb_buffer_pool_size in the MySQL server: this generally seems to be set too low by default
- defining the Memcached serializer as igbinary: this involved compiling a new version of Memcached as it's a relatively old OS
- front-end performance was increased through appropriate rules in Varnish for serving static files.
There does seem to be a fair amount of misleading (or overly absolutist) advice out there on Drupal performance. This is what did not help me:
- worrying much about database performance: the site spends about 5% of the page load time in the database. Nearly all of the time is spend in the theme layer.
- disabling unnecessary modules: I have plenty of helpful but not essential modules, but most of them are small and have no discernible impact on performance or memory usage. NB that's probably because of the other caching/server optimizations, and this is Drupal 7 not 6.
- using a CDN: but perhaps the CDN provider is inadequate and traffic isn't very high yet anyway
- using HeadJS: despite the claims on the project page, for me it was still much faster to load a large, albeit blocking aggregate JS file than it was to load 30 or so small files in parallel via HeadJS.
- using APC user cache (as opposed to the APC opcode cache): for whatever reason it doesn't seem to bring any performance benefit over the database/Memcached caches.
- compromising security by avoiding SSL: using HTTPS was barely any slower for me, despite what the web might say, so authenticated users get HTTPS for the entirety of their session.
Great tips. Another one is to avoid modules like statistics if you can. Those can add a significant performance hit.
On caching - generally APC is the best for user caching and offers significant performance increases over db cache and memcache. On the high performance group you do see people complain that memcache is generally as slow if not slower than database caching. This is true, but memcache takes a lot of work from the database, so while it might be the same or a little slower to read, it's helping all your other queries out.
Trim the fat from Apache. Get rid of modules you don't use. A lot of repos installations of Apache include a bunch of unneeded modules, so take the time to go through those.
If you have a very heavy query that you cache, refresh the cache with cron or use a locking mechanism so that multiple requests don't try to refresh that item.
If your not doing anything really special with comments, then using a 3rd party service like Disqus can really help. You don't have to worry about page caches being invalidated on every comment, plus remove the overhead of Drupal having to handle them.
How about using Pressflow rather then stock Drupal?
Nice article, thanks for posting.
Unfortunately, there are lots of articles about how to do the obvious stuff (enable anonymous user cache, varnis etc) but nothing (that I've found) that addresses the real problem: that performance of Drupal for authenticated users is appalling.
There is the AuthCache module, which whilst a good thing only works on Drupal 6 and requires that the user has javascript enabled (not acceptable).
Even Drupal Gardens (you'd imagine this uses state of the art Drupal performance techniques) takes around 800ms (measured using Yslow) to generate a page for an authenticated user.
Why has no-0ne solved this problem (or even talks about it) ?
I've been working improving authenticated user performance if using pressflow
http://groups.drupal.org/node/187209
This requires patching core so this is advanced stuff; but the gains are pretty big. I was able to cut page load times in half on a large site by using a couple of the patches I wrote for core, and most people seem to have success with it as well.
Thanks for the link Mike, and for your various other contributions to the Drupal performance community!
@Simon
People do talk about performance for authenticated users. Many strategies in this article and comments apply to anonymous and authenticated users alike. There were talks at the last European Drupal Conference which covered in detail issues such as MySQL tuning (e.g. http://london2011.drupal.org/conference/sessions/damn-quick-drupal-how-m...).
That said, it's a challenge, and I agree there isn't much information out there that goes beyond the obvious.
If promised D7 modules such as ESI come to fruition, the situation will be much improved.
It's about 450ms on my site with 185 enabled modules (that's not meant as bragging!). Although that is still slow, it's acceptable and the availability and scalability are fine.
Lullabot, in linking to this article, have also included these resources:
Interested in digging deeper? Video of Nate Haug's performance tuning deep-dive from the 2011 Do It With Drupal conference is available for free on Drupalize.me [http://drupalize.me/videos/overview-performance-scalability]. Related: A fantastic 2011 article that introduces software-focused devs to the exciting world of server management and "DevOps" [http://www.paperplanes.de/2011/7/25/web_operations_101_for_developers.html].
Also worth mentioning, Acquia will be running a free webinar on "Solving the Top 5 Drupal Performance Issues" on Wednesday, January 18, 2012.
Registration and more details at http://www.acquia.com/resources/acquia-tv/conference/solving-top-5-drupa...
This weird tool usually helps me to find problems with my drupal sites.
http://www.unshit.com
What I hate in drupal it often changes its own performance settings, for some season.
yeah i second that drupal is a bit bothering wordpress is simple and more user friendly.
MMA News
I am no computer programmer, but it seems alot of work in tuning the performance of Drupal. I have in the past reduced the amount of modules in use and that has increased speed.
Dsquared Clothing Dsquared Hoodies Dsquared Jeans Dsquared Shoes Dsquared Sweater Dsquared T Shirt Dsquared Belt Dsquared Women Heels Shoes Dsquared Cap Dsquared Jacket Dsquared Polo Shirt Dsquared Shirt Dsquared Pants Dsquared Swim Dsquared Coat Moncler Doudoune Moncler Shoes Moncler Vest Moncler Coat Moncler Jacket Moncler Hoodies Moncler Sweater Moncler Polo Shirt Moncler Down Jacket Moncler Boots Moncler Cap Moncler Down Jacket Moncler Pants Moncler Shorts Moncler Kids Belstaff Leather Belstaff Bag Belstaff Leather Jacket Belstaff Leather Jacket Men Belstaff Leather Jacket Women Belstaff Women Jacket Tory Burch Shoes Tory Burch Tote Bag Tory Burch Wallet Tory Burch Flat Shoes Tory Burch Sandals Tory Burch Suede Shoes Tory Burch Boots Tory Burch Heels Shoes Tory Burch Wedge Shoes Tory Burch Flip Flops Tod's Shoes Tod's Ballet Shoes Tod's Boots Tod's Fall Shoes Tod's Handbag Tod's Loafers Tod's Moccasins Juicy Couture Clothes Juicy Couture Tracksuit Juicy Couture Flip Flops
Dsquared2 Men Dsquared2 Hoodies
Dsquared2 Jacket Dsquared2 Jeans Dsquared2 Shoes Dsquared2 T Shirt Docle Gabbana
Post a new comment