Speeding up Drupal Forums

The Drupal forum.module has become, well, somewhat infamous for less than awesome scalability. Recently I had a chance to see this firsthand, and track down a solution for managing the long page load times for a client who has a highly trafficked forum. This was not a case of a site that was un-tuned - actually this particular site had a lot of good work and performance enhancements already done to it, including block caching and even some modifications to the forum module that were allowing to work better than it would have without them. But still 5-6 second page load times on /forum persisted.

As this was my first time working on the site, I began by reviewing all of the main configuration files for Apache, MySQL, and PHP, since they are the foundation for everything else. After making some adjustment there, I headed over to the Drupal admin interface and check /admin/setting/performance/ and made sure all was happy there as well. Finally, I went to the block admin page and double-checked all of the blockcache settings, which as it turns out were set a bit to aggressively, resulting in slow form submission times (every time anyone submitted anything a gazillion blocks were being re-cached whether they need to be or not).

With the foundation of the site now looking good and everything, except the forum pages flying along (and the tracker, but that's a story for a later article) - it was just down to forum.module.

Here are the steps that led to cutting the page load time in half from what they were:

1. Disable the forum.module, rename it to something like "forum.module.orig", make a copy and then rename the copy "forum.module".

2. Download the advcache module and apply the forum patch includes to your new copy of the forum.module.

3. If want the cleanest solution and are comfortable with coding/debugging at all, instead of just copying the forum module and working on it directly (and thus having a hacked Drupal core file around all the time) - name the copied file something completely different than forum.module and edit all of the hook/function calls with in it with new name and place it where you keep the rest of your contributed modules.

4. (Note: this step is an option only if all your forums are public)
Open the module and remove all references to db_rewrite_sql. This will keep Drupal from doing a lot of expensive and uneccesary queries in order to check access rights. (thanks Khalid)

5. Get rid of the expensive previous/next links that few people are likely to use by placing the code below in your template.php file, taking care to replace the part where it says "MYNEWMODULESNAME" with the actual name you gave your new forum module. (thanks John)

// No previous/next links for forum topics.
function phptemplate_MYNEWMODULESNAME_topic_navigation($node) {
  return '';
}

6. Enable your new forum.module (or whatever you called it)

7. Enable the advcache.module

8. Rejoice at the new found speed of your forums. :-)

28 February, 2008

Comments

Just an FYI - #5 won't work in Drupal 6. It's actually a bit more complicated in D6 because you have to prevent the preprocess code from running. If you are already hacking the module, you can just take it out, of course. But if you want to get rid of it without hacking the module, take a peek at the advanced forum code for a solution. :)

Michelle

Those dang Drupal 6 preprocess functions strike again. ;-)

Just kidding of course, but I'm only beginning to get acquainted with them, (as are most people, I suppose). From what I gather the benefits to the overall theme layer make it well worth adjusting to them.