header image
Main Page arrow Published Articles arrow Technical Blogs arrow First Page Loads Slowly in Mambo
First Page Loads Slowly in Mambo PDF Print E-mail
Written by anti-trend   
Jul 18, 2008 at 11:17 PM

ImageEver been annoyed by a Mambo site that loads unreasonably slowly on the first hit, then subsequent page loads are an order of magnitude faster? Unfortunately I have too, and on more than one occasion. When this cropped up for me yet again, I was reminded of the apparent lack of good information on this subject. With that in mind, I decided to sit down and write the following article on how to solve it. If you're with me so far, read on.

Some Background On The Issue

The most obvious symptom of this particular problem is that when a client first connects to a Mambo-powered website, the initial connection takes ages — anywhere from 5 seconds to several minutes. Subsequent hits from the same client are as fast as can be expected, being far under 1 second per page. While there is no shortage of support threads, blog posts, and tech articles on what can cause this fairly wide-spread symptom in Mambo, the story is the same everywhere I've looked: A few generic solutions are proposed, these generally ranging from suggestions of "turn on caching" (can I get a "duh"?) to "get yourself a faster webserver"(?!).

In my particular case, I own and operate the server myself, it's not run by some faceless hosting company. I made sure MySQL, Apache, and PHP were all tuned to their optimal values for my purposes. The hardware itself isn't stellar, but the dual-P3 server hardware with 2GB of SDRAM is more than capable of running my small-scale sites. In fact, the other dozen or so vhosts on this server were all exceedingly fast except a client's first hit on Mambo. For this reason, I knew a solid majority of the support threads on this topic were pretty much worthless in so far as addressing my own issue. I suspect this was true for others as well. Though I'm sure the helpful intent was genuine, the levels of frustration about this issue seemed to reverberate as people simply shrugged and moved on.

Looking Into The Root Cause

There's an old mantra in network-related support circles: "it's probably a DNS problem!" As it turns out, some clichés are absolutely dead-on. While a few threads out there alluded to a possible reverse lookup delaying the initial page load, this was shrugged off by both Mambo developers and power users in every support thread I've read on the topic. In every case, they asserted that their CMS doesn't even do reverse lookups. Not willing to leave it at that, I decided to do a little research on that point...

After sniffing a little traffic with tcpdump and Wireshark I quickly discovered that, in my case, a reverse DNS lookup is exactly what was occurring. When the client connected to the Mambo server, the server was in turn doing a PTR lookup against the client's IP. As it turned out, the statistics subsystem of Mambo was doing the reverse lookup to populate the domain information it gathers. So while it may technically be true that the Mambo core itself doesn't do any reverse lookups, the statistics module certainly seems to. It was especially evident in my own tests because I was connecting from a network with no PTR to lookup; thus the request would eventually time out. Pending the results of the reverse lookup the connection would hang, resulting in an immense pause before the page loaded.

Correcting The Problem

If the reverse lookup behavior is your culprit there are two ways to correct it, thereby alleviating the symptoms such as slow initial page loads. The simplest and most effective of these is to disable the statistics feature of your CMS entirely. An added benefit of this approach is that Mambo's MySQL traffic and associated CPU overhead will be substantially reduced. In Mambo, this is a core feature which is built-in and [has historically been] enabled by default. It can be disabled by either navigating in the admin GUI to Site → Global Configuration → Statistics → Statistics: (No), or if you're more the direct type, you can edit your preferences.php file as follows:

$mosConfig_enable_stats = '0';

In the unusual situation where you do want statistics enabled (your webserver does its own statistics gathering), all is not lost. While you will still generate a whole lot of largely unnecessary activity in MySQL, it is possible to at least disable the reverse DNS lookup, reducing the perceived slowness of the initial page load. This solution is a bit hackish, but you can edit your includes/mambo.php file to comment out the following lines, like so:

			if (phpversion() <= "4.2.1") {
$agent = getenv( "HTTP_USER_AGENT" );
//DISABLED--$ = gethostbyaddr( getenv( "REMOTE_ADDR" ) );
} else {domain
$agent = $_SERVER['HTTP_USER_AGENT'];
//DISABLED--$domain = gethostbyaddr( $_SERVER['REMOTE_ADDR'] );
}
Last Updated ( Jul 06, 2009 at 05:39 AM )
Next>