homepage Welcome to WebmasterWorld Guest from 54.211.73.232
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Performance hit for Redirect 301?
All I've heard is theory -- who's got numbers?
MichaelBluejay

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1696 posted 1:35 am on Jun 19, 2004 (gmt 0)

So conventional wisdom has it that the more Redirect 301's you have in your .htaccess file the slower your server will be at delivering pages, because it has to check all those Redirectives first. But how much slower? I looked all over the SERPs and WebmasterWorld but I couldn't find anything useful. I'm particularly interested in a comparison, such as speed to deliver pages with 0, 50, 100, and 500 Redirects respectively. Anyone know where to find information like that?

 

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 1696 posted 1:59 am on Jun 19, 2004 (gmt 0)

How about on your server? That's the best place to test for impact, since all servers and sites will be different. Cut and paste 500 copies of a redirect that refers to a non-existent file, so it won't interfere with any real files on your server, and then measure the impact that checking those 500 redirects has on serving your non-redirected pages.

Also, if there is any pattern to your redirects, you can often handle more than one file with a single redirect.

I added about 20 redirects, and at least 300 IP address and user-agent checks to my .htaccess over time, and couldn't see any difference in performance -- the server execution time is still completely swamped by internet transmission time. Many sites are completely script-based, so a few more lines of server-native scripting in .htaccess won't make much difference.

I would be interested in seeing your results, though.

Jim

MichaelBluejay

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1696 posted 5:04 am on Jun 19, 2004 (gmt 0)

Servers are not my strong suit -- I don't know how to how to run such a test myself.

Uh, I guess I could have a Perl script get the time, call a redirected page, and then have the landing page get the time after it loads so I can compute elapsed time?

sonjay

10+ Year Member



 
Msg#: 1696 posted 3:43 pm on Jun 19, 2004 (gmt 0)

That's one of the reasons it's better to put your redirects and other .htaccess directives directly into your httpd.conf file, if you have access to it. Anything in that file is loaded into the server's memory when Apache is restarted, so the server knows what needs to be redirected and doesn't have to read your .htaccess file everytime someone requests a page.

Although really, any server should be able to handle even a fairly large .htaccess file without any noticeable overhead. If your .htaccess file is resulting in a noticeable performance hit, you probably need to upgrade your server.

MichaelBluejay

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1696 posted 1:36 am on Jun 20, 2004 (gmt 0)

I'm afraid I don't have access to the httpd file, and I'm not experiencing a "noticable" performance hit, but it's kind of hard to notice these things. Anyway, I cracked open my copy of the Perl Cookbook and did some simple benchmarks.

Bear in mind that my server is part of a shared hosting plan with who knows how many other websites running on it so my tests weren't exactly part of a controlled environment. Still, the conclusion seems to be clear: No noticable performance hit from using 100 redirects vs. 0, or using <AddHandler server-parsed .html> for SSI, vs. not having that line in the file.


-----------------------------
Test Code
--------------------------------
#!/usr/bin/perl

use LWP::Simple;
use Time::HiRes qw(gettimeofday);

print "Content-type: text/html\n\n";

$t0 = gettimeofday;
getprint('http://example.com/page.html');
$t1 = gettimeofday;

$elapsed = $t1-$t0;
print '<P>' . $elapsed;

-----------------------------
Results
-----------------------------
Times are in seconds. I ran each test six times.

Empty .htaccess
0.0948460102081299
0.0967559814453125
0.0930469036102295
0.0901648998260498
0.0909998416900635
0.0918800830841064

Add: A redirect for the file I'm processing
0.247492074966431 << Is it only slow the first time because it gets cached?
0.111835956573486
0.105646133422852
0.105272054672241
0.110029935836792
0.118083953857422

Add: 99 redirects before the one that will actually be called
0.10962700843811
0.109647035598755
0.108677864074707
0.136151075363159
0.12981104850769
0.145864963531494

.htaccess contains only: AddHandler server-parsed .html
Call a 24k file with an SSI directive in it

0.1545729637146 << Is it only slow the first time because it gets cached?
0.108921051025391
0.112843990325928
0.104007005691528
0.103969097137451

Empty .htaccess file
Call the same 24k file

0.103510856628418
0.100152969360352
0.102439880371094
0.0986959934234619
0.103201150894165

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved