« Upgrading Movable Type 3.2 to 4.2 | Main | LiveScribe »

August 16, 2008

Speeding Up Movable Type

Movable Type is so painfully slow that I can't live with it any more. It takes much too long to post entries, comments, etc. I'll see if I can get this to work faster, but this was one of my main goals in upgrading....to get MT to run faster, and I'm not there yet, obviously. Either it's got to get faster, or I'm going to jump ship and go with a different software program.

I went and deleted a bunch of my Index and Archive templates. I'm not sure if that was slowing me down or not, but I'll try anything at this point.

No, that didn't help. MT is still as slow as molasses in January any time I try to post.
Now, I've deleted a bunch of garbage out of my Main Index template, hoping that it would help. Nope. It still takes forever. Sucks.

I deleted my Apache logs, to see if that would make it any faster.

I cleared out the Movable Type activity log (Tools - Activity Log - Clear Activity log).

This person seems to be having some performance problems with MT as well.

One suggestion is to use FastCGI. Six Apart recommends using FastCGI.

There are two Recommended FastCGI Implementations:
* mod_fcgid
* mod_fastcgi

Here are some benchmarks for the MT without fastcgi, with mod_fastcgi, and mod_fcgid. It looks like mod_fcgid is faster.

Hosting MT Under FastCGI

Apache FastCGI Module Installation

http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html

Jay Allen has a post up about using fastcgi with MT on DreamHost.

I added these lines to my root .htaccess file to see if fastcgi was already installed or not.

<IfModule mod_fastcgi.c>
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi
FastCGIConfig -autoUpdate -idle-timeout 120 -killInterval 3600 -maxClassProcesses 6 -maxProcesses 15
</IfModule></blockquote>

Then, I created a Helloworld.fcgi program as follows:

#!/usr/bin/perl
use FCGI;
while (FCGI::accept() >= 0) {
print ("Content-type: text/html\r\n\r\n");
print ("This is coming from a FastCGI server.\n
\n");
}

But when I tried to run it, I got:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.


FastCGI for Perl
http://www.cpan.org/modules/by-module/FCGI/
http://www.cpan.org/modules/by-module/FCGI/FCGI-0.67.readme
http://www.cpan.org/modules/by-module/FCGI/FCGI-0.67.tar.gz


This appears to be the most current documentation from Movable Type titled Hosting MT Under FastCGI.

Movable Type FastCGI Notes

The problem with this documentation (above) is that there is basically one line that says "Install FastCGI". Like....um....I wish it were that easy. Neil Turner's blog has some more detailed instructions on installing FastCGI.

Neil clarifies the install of FastCGI for Apache: "You're going to need to download two packages -- FastCGI itself and mod_fastcgi (both link to the actual files). The latter is the Apache module that links FastCGI with your web server..."

So, this helps. There are apparently two parts to the FastCGI install. So, I downloaded these two packages. Then I installed WinRar and extracted them. So far, so good.

So, it looks like I'm going with mod_fastcgi as opposed to mod_fcgi. Fair enough.

From the fcgi-2.4.0/readme file:

Basic Directions
----------------
Win32:
nmake -f Makefile.nt
(or use the MSVC++ project files in the Win32 directory)

Of course, when I type in "nmake -f Makefile.nt", I get "nmake is not recognized as internal or external command". Big surprise there. Apparently, I need to have a there is a need to have a C compiler available?

Here is some better documention on mod_fastcgi in a Windows environment:
http://www.fastcgi.com/
http://www.fastcgi.com/mod_fastcgi/INSTALL

It explains in some detail how to install C++ and compile it, but I'm wondering if I can't just skip all of that and go grab a copy of mod_fastcgi.dll for Apache 2.0.69 and start with the directions below:

To install mod_fastcgi (built above or retrieved from http://fastcgi.com/dist/):
1. Copy the mod_fastcgi.dll to the Apache modules directory (e.g. C:\Apache\modules)
2. Edit the httpd configurion file (e.g. C:\Apache\conf\httpd.conf) and add a line like:
LoadModule fastcgi_module modules/mod_fastcgi.dll

OK. I did this. So far, so good.

Note that if there's a ClearModuleList directive after new entry, you'll have to either move the LoadModule after the ClearModuleList or add (have a look at how the other modules are handled):

I don't have a ClearModuleList directive in my httpd.conf.

AddModule mod_fastcgi.c

Hmmm. Slowly, it dawns on me what I need to do. I'm going to have to add the following two statements to my http.conf:

LoadModule fastcgi_module modules/mod_fastcgi.dll
AddModule mod_fastcgi.c

Now that I'm understanding this, I bet what I need to do is go back to the old mod_fastcgi distribution library and get a pair of these things. I chose to go with release 2.4.2 because it says "AP20", which makes me think it will work with Apache 2.0.69, as opposed to Apache 2.2, which I don't have.

mod_fastcgi-2.4.2-AP20.dll 23-Nov-2003 22:07 100k
mod_fastcgi-2.4.2.tar.gz 24-Nov-2003 19:07 96k

OK. Now that I've downloaded those, I put the following two lines in my httpd.conf:

LoadModule fastcgi_module modules/mod_fastcgi.dll
AddModule mod_fastcgi.c

I tried to stop and restart Apache. It wouldn't restart until I commented out the AddModule mod_fastcgi.c command. Not clear why this is. Then I restarted Apache, and tried to run mt.cgi, and got an internal server errror. So, I commented them both out and restarted Apache.

The directions continue:

3. Edit the httpd configuration file(s) to enable your FastCGI application(s). See docs/mod_fastcgi.html for details.

Now, I think I need to add a handler? Neil says to add the following:

<IfModule mod_fastcgi.c>
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi
</IfModule>

According to BP, we can put the use "AddHandler fastcgi-script .fcgi", either in your .htaccess, or in the appropriate slot in your httpd.conf.

Trying to restart Apache, however, I still get "The requested operation has failed!" if I don't uncomment my Addmodule line. Interestingly though, if I leave the "LoadModule fastcgi_module modules/mod_fastcgi.dll" line in there, I do see this as an available module when I restart Apache.

But then, if I try to run mt.cgi, I get an Internal Service Error. So, I looked in my Apache error.log to see what was going on and saw the following:

C:/Inetpub/wwwroot/.htaccess: FastCgiIpcDir not allowed here

So, Apache is barfing on the code that I put in the .htaccess from yesterday (8/15/08). So, I commented out the the following lines from my .htaccess file:

# RAK 08/15/08 - test to see if fastcgi is installed.
# <IfModule mod_fastcgi.c>
# FastCgiIpcDir /tmp/fcgi_ipc/
# AddHandler fastcgi-script .fcgi
# FastCGIConfig -autoUpdate -idle-timeout 120 -killInterval 3600 -maxClassProcesses 6 -maxProcesses 15
# </IfModule>

And, lo-and-behold, it does, in fact, allow me to restart Apache and also run mt.cgi without getting any errors. The Apache Service Monitor shows:

Apache/2.0.63 (Win32) PHP/5.1.2 mod_fastcgi/2.4.2

So, I have accomplished something. Precious little, I know, but something, none-the-less.
OK. Now, that I got the garbage out of my .htaccess file that was hosing me up, I'm going back into my httpd.conf and uncommenting my "AddModule" and "IfModule" commands and I do see a relevant error message in my Apache error.log file now:

Invalid command 'AddModule', perhaps mis-spelled or defined by a module not included in the server configuration

So, it doesn't like my AddModule command, which is interesting. I'm going to copy my mod_fastcgi.c to my apache\modules folder and see if that's the rub. No dice. That didn't help.

I'm beginning to think that I'm going to have to install C++ and make the project?

So, I apparently need to install Microsoft Visual C++ 6.0

Microsoft Visual C++ 2008 Express Edition (x86)
http://www.microsoft.com/express/download/

OK. After installing Microsoft Visual C++ Express Edition (x86), I again tried to follow the directions at http://www.fastcgi.com/mod_fastcgi/INSTALL for Windows:

4) Windows NT
=============
To build mod_fastcgi from the command line:
1. Edit the APACHE_SRC_DIR variable in Makefile.nt.
2. Build the module
> nmake -f Makefile.nt CFG=[debug | release]

I was finally able to locate the APACHE_SRC_DIR variable. I found it in the file \mod_fastcgi-2.4.2\Win32\makefile.nt. However, when I try to run the command "nmake -f Makefile.nt", I still get "nmake is not recognized as internal or external command".

After a bit of research, I see that Nmake.exe is a 32-bit Microsoft Program Maintenance Utility. Nmake is a tool that builds projects based on commands contained in a description file.

So, nmake isn't a typo. It's a real program. I searched and found it at C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\nmake.exe.

So, I updated by Path to include the directory that includes the nmake.exe program.

Now, when I type in "nmake.exe -f makefile.nt", at least I finally get some results. Lots of errors, of course, but at least the computer recognizes the nmake.exe command.

I enter the following: nmake -f Makefile.nt CFG=debug

And I get a warning, followed by a fatal error.
Warning: cannot find "mod_fastcgi.dep"

Microsoft (R) Program Maintenance Utility Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.

Warning: cannot find "mod_fastcgi.dep"
cl.exe /nologo /MTd /W3 /Gm /GX /Zi /Od /I "C:\Program Files\Apache Group\Apache\src\include" /I "C:\Program Files\Apache Group\Apache\src\os\win32" /D "WIN32" /D "_DEBUG" /D "FCGI_DEBUG" /D "_WINDOWS" /FR".\Debug\\" /Fp".\Debug\mod_fastcgi.pch" /YX /Fo".\Debug\\" /Fd".\Debug\\" /FD /c ..\fcgi_buf.c
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\cl.exe"' : return code '0xc0000135'
Stop.

But now, it occurs to me that I never set the APACHE_SRC_DIR variable in the makefile.nt.

I'm sure that this is all unnecessary, and it's just a wild goose chase, but I'm not sure what else to do at this point.

I'm not even clear that I have the source, so I downloaded the Windows source code for Apache 2.0.63.

Hmm. I'm not clear that there is any value to the Apache source that I downloaded. As in, it doesn't appear to have solved any of my problems.

I'm not clear what to set the APACHE_SRC_DIR variable to. Right now, it's set to "C:\Program Files\Apache Group\Apache\src". Scrolling through the makefile.nt logic, though, i find this:

LINK32_FLAGS="$(APACHE_SRC_DIR)\Release\ApacheCore.lib"

But, when I scan my pc, I don't find anything named ApacheCore.lib. So, I'm not clear that I've downloaded the right source. I'm giving up for the night.

OK. After some more research, I've decided that it's probably going to create the file named ApacheCore.lib on the fly. (It could happen, right?) In any event, after looking at the makefile.nt file some more, I found the following:

$(APACHE_SRC_DIR)\include
$(APACHE_SRC_DIR)\os\win32

So, I did see these two folder in the Apache 2.0.63 source package that I downloaded yesterday. So, I think I've figured out what the APACHE_SRC_DIR variable should be I'm going to set it as follows:

APACHE_SRC_DIR=C:\Program Files\Apache Group\httpd-2.0.63

So, I think I've got the APACHE_SRC_DIR set right, but I'm still getting the same error:

C:\Inetpub\wwwroot\FastCGI\mod_fastcgi-2.4.2\Win32>nmake -f Makefile.nt CFG=rele
ase

Microsoft (R) Program Maintenance Utility Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.

Warning: cannot find "mod_fastcgi.dep"
if not exist ".\Release/" mkdir ".\Release"
cl.exe /nologo /MT /W3 /GX /O2 /I "C:\Program Files\Apache Group\httpd-2
.0.63\include" /I "C:\Program Files\Apache Group\httpd-2.0.63\os\win32" /D "WIN3
2" /D "NDEBUG" /D "_WINDOWS" /Fp".\Release\mod_fastcgi.pch" /YX /Fo".\Release\\"
/Fd".\Release\\" /FD /c ..\fcgi_buf.c
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 9.0\VC\bin
\cl.exe"' : return code '0xc0000135'
Stop.

C:\Inetpub\wwwroot\FastCGI\mod_fastcgi-2.4.2\Win32>


http://msdn.microsoft.com/en-us/visualc/aa336437.aspx

http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html

Posted by Rob Kiser on August 16, 2008 at 12:01 AM

Comments

Post a comment




Remember Me?

(you may use HTML tags for style)


NOTICE: IT WILL TAKE APPROX 1-2 MINS FOR YOUR COMMENT TO POST SUCCESSFULLY. YOU WILL HAVE TO REFRESH YOUR BROWSER. PLEASE DO NOT DOUBLE POST COMMENTS OR I WILL KILL YOU.