Forum Moderators: phranque

Message Too Old, No Replies

301 redirect performance puzzle

Why is httping to non-www so much slower than to www?

         

Loggy

2:46 pm on Nov 21, 2011 (gmt 0)

10+ Year Member



I have a Ubuntu 10.04 LTS VPS with complete access and some Wordpress installations mounted. Current Apache2 version is 2.2.14-5ubuntu8.7 and the mod-php5 is 5.3.2-1ubuntu4.10. FWIW.

The vhosts file for a typical site is:

<VirtualHost *:80>
ServerAdmin webmaster@mydomain.com
DocumentRoot /home/myuser/www/mydomain.com
ServerName mydomain.com

CustomLog /home/myuser/logs/mydomain.com/access_log combined
ErrorLog /home/myuser/logs/mydomain.com/error_log

<DIRECTORY /home/myuser/www/mydomain.com >
OPTIONS FollowSymLinks
AllowOverride All
</DIRECTORY>
IndexOptions FancyIndexing
</VirtualHost>

<VirtualHost *:80>
ServerName www.mydomain.com
RedirectMatch permanent ^/(.*) http://mydomain.com/$1
</VirtualHost>


So this has a proper 301 redirect.

For some sites it is, I just used ServerAlias:

<VirtualHost *:80>
ServerAdmin webmaster@mydomain.com
DocumentRoot /home/myuser/www/mydomain.com
ServerName mydomain.com
ServerAlias www.mydomain.com

CustomLog /home/myuser/logs/mydomain.com/access_log combined env=!loopback
ErrorLog /home/myuser/logs/mydomain.com/error_log

<DIRECTORY /home/myuser/www/mydomain.com >
OPTIONS FollowSymLinks
AllowOverride All
</DIRECTORY>
IndexOptions FancyIndexing
</VirtualHost>


The .htaccess is set to:


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


I have only the following modules enabled:

    LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so
    LoadModule auth_basic_module /usr/lib/apache2/modules/mod_auth_basic.so
    LoadModule authn_file_module /usr/lib/apache2/modules/mod_authn_file.so
    LoadModule authz_groupfile_module /usr/lib/apache2/modules/mod_authz_groupfile.so
    LoadModule authz_host_module /usr/lib/apache2/modules/mod_authz_host.so
    LoadModule authz_user_module /usr/lib/apache2/modules/mod_authz_user.so
    LoadModule autoindex_module /usr/lib/apache2/modules/mod_autoindex.so
    LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so
    LoadModule dir_module /usr/lib/apache2/modules/mod_dir.so
    LoadModule expires_module /usr/lib/apache2/modules/mod_expires.so
    LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so
    LoadModule mime_module /usr/lib/apache2/modules/mod_mime.so
    LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
    LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
    LoadModule setenvif_module /usr/lib/apache2/modules/mod_setenvif.so
    LoadModule status_module /usr/lib/apache2/modules/mod_status.so


In both cases the URL is set in Wordpress without the www. prefix and, as you see, the ServerName does not include the www but is aliased in one of two ways to the www.mydomain.com.

This all works hunky dory but I am trying to optimise the server and also tune the sites.

Because when I try httping, which as I understand it does test the page generation etc, I get very different results. For the first setup, it is substantially faster when httping the www-version by a factor of about 4. For the second setup, there appears to be no difference.

My questions to the assembled multitude are:

1) Is there a reason outside my settings why apache should return better figures for the www version than the non-www version? I can't believe there is as the www is only a convention devised I assume by Sir Tim and is just a sub-domain.
2) Is it possible that httping is just reporting the latency to the redirect stage rather than building the page? Ping is substantially quicker though at about 1/3rd the faster time.
3) Is there a general SEO recommendation whether to include www or not? I have added the appropriate AddIgnoredRef to Google Analytics in one case but that is only interesting for reporting reasons. Obviously I want the search engines to regard the site and canoncial versions as the same.

Hopefully you have understood my garbled message ;-)

lucy24

10:40 pm on Nov 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



:: recycled answer ::

Sit tight, loggy, we are not ignoring you. We're accustomed to buying time with "RTFM" type responses, but your post doesn't leave room for this option, so it will take longer ;)

Loggy

8:07 am on Nov 22, 2011 (gmt 0)

10+ Year Member



Tks lucy24.

A little RTFM by myself reminded me to add a -G to the httping options which forces a GET to build the whole page, otherwise it just returns the header.:-)

This gave a more variable response as it probably had to fight with other demands. The initial time was almost seconds in fact.

However looking at the minimum page build times, the effect is still there - httping to www.mydomain.com is substantially lower than the minimum for mydomain.com for my vhosts type 1 example but doesn't appear to be very different for the vhosts type 2 example. If anything I wold have expected the httping to www.mydomain.com to be longer because of the time taken for the redirect itself - Apache will have to do a whole set of calculations twice before arriving at the code.

Still puzzled ...