Thursday, April 12, 2012

Scaling Drupal


I am working on a Drupal based site and notice there are a lot of seperate CSS and js files. Wading though some of the code I can also see quite a few cases where many queries are used too.



What techniques have you tried to improve the performance of Drupal and what modules (if any) do you use to improve the performance of Drupal 'out of the box'?


Source: Tips4all

4 comments:

  1. Going to the admin/settings/performance page, turning on CSS and JS aggregation, and page caching with a minimum lifetime of 1 minute, will give you an immediate boost on a high traffic site. If you're writing your own code and doing any queries, consider writing your own discrete caching for expensive functions. The linked article covers Drupal 5, not 6, but the only change in d6 is the elimiation of the serialization requirement and the function signature for the cache_set() and cache_get() functions. (Both noted in comments on the article)

    On large scale sites also consider dropping a memcached server onto the network: Using the memcached module, you can entirely bypass the drupal database for cached data. If you have huge amounts of content and search is a hot spot, you can also consider using lucene/solr as your search indexer instead of drupal's built-in search indexer. It's nice for a built-in indexer but it's not designed for heavy loads (hundreds or thousands of new pieces of content an hour, say, with heavy faceted searching). The apache solr module can tie in with that.

    If you're making heavy use of Views, be sure that you've checked the queries it generates for unindexed fields; sorting and filtering by CCK fields in particular can be slow, because CCK doesn't automatically add indexes beyond the primary keys. In D6, preview the View in the admin screen, copy the text of the query, and run it through EXPLAIN in mysql or whatever query analysis tools you have.

    Tools like YSlow and Firebug can also help you spot slow stuff like massive image files, JS hosted on remote servers, and so on.

    ReplyDelete
  2. Drupal 6, out-of-the-box, provides css and javascript aggregation --- most css and js files will be combined into a single file (and thus a single HTTP request), and are also whitespace-shortened (to reduce bandwidth consumption). You can enable this under /admin/settings/performance .

    Also on that screen are controls for Drupal's (very effective) cache, which helps reduce the number of database queries.

    Additionally, because Drupal (and all the modules you'll probably have installed) has a ton of PHP source, using a PHP opcode cache such as APC helps significantly decrease the request time.

    ReplyDelete
  3. The boost module also provides a huge performance gain. I'd recommend using that aswell

    ReplyDelete
  4. I strongly second Benedict's recommendation of the Boost module - it alone will make your website fly on shared hosting, if configured correctly, and is not really buggy at all.

    Turn on CSS/JS aggregation, turn on Boost, and your site can perform very well for anonymous users.

    If your site deals with mostly logged-in users, you're going to have to do a lot more work making sure sessions are cached well, and probably consider using memcached and more SQL query caching.

    The biggest performance gains always come from caching—but monitoring and adjusting your slow queries, monitoring and adjusting apache and PHP configurations, and being smart about the modules you use are very important as well.

    ReplyDelete