Bug In Movable Type 3.2 Causes Slow Comment Post Speed

Movable Type

Posting a comment on my web site takes forever! I started getting sick of it. 90+ seconds to post a comment! What’s the deal?

I read many of the articles on how to speed up comments. Some of the tips were obvious and already done. Others provided minimal improvements. I opened a support ticket with SixApart and did many different timing tests and provided the data. However, the more I dug into the code, the more I figured out what was going on.

In Movable Type 3.2, they added this ability to run background tasks. Cool. This allows the app to rebuild the page that displays the comment (usually individual entry) and then return back to the user. Then in the background, the other indexes, etc. are rebuilt. What I noticed on my server was that the user had to wait for the background task to complete before having the page displayed. The time here depends on how long it takes for your server to rebuild. I have tons of plugins and includes and stuff so my rebuilds are longer than most. If you have all the standard MT templates with no plugins, you probably don’t notice the bug because your rebuilds are fast. However, you can make them faster with this fix!

As I understand it, this only applies if you have a UNIX server. The deal is that when you fork a new process, Perl seems to have both processes (the parent and the child) hold on to the same STDOUT, STDIN, and STDERR. Therefore, when running as a CGI, the response will not return to the user until all of these are freed up. The usual workaround is to close the handles to STDOUT, STDIN, and STDERR. Unfortunately in the MT code, SixApart missed STDERR. This causes your parent process to wait for your child process to finish. So this bug basically obliterates the advantage of running tasks in the background. So if you notice your background and non-background times are close, then you are getting hit with this bug.

To fix the issue, go into your MT installation into lib/MT/Util.pm. Go to around line 1344, and you will see the code addressing this. You need to add a line for STDERR.

close STDIN; open STDIN, "</dev/null";

close STDOUT; open STDOUT, ">/dev/null";

close STDERR; open STDERR, ">/dev/null";     # Add for bug fix

Once you do this, your comment posts will return to the user quicker and the rebuilds will happen in the background.