Forum Moderators: phranque

Message Too Old, No Replies

300 Mod Rewrite Rules, Performance

         

HoboTraveler

7:21 am on Apr 3, 2008 (gmt 0)

10+ Year Member



Hi All,

I am curious to know if there's a performance hit involved if I were to create ~300 mod rewrite rules.

I have 300 groups of files that I want to mod rewrite to specific directories. A single regular expression would not work since these are unique groups.

Do I need to be concerned with Apache? Would a URL take longer to resolve?

TIA

jdMorgan

3:32 am on Apr 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is kind of a "how long is a piece of string" question. All that can be said is that the performance hit of 300 rules will be approximately 300 times greater than that of one rule, and about one-half that of the 600 or so rules I have on one site... :)

The performance hit depends on two main things: Your server performance and your traffic levels. Even an old slow server with minimal memory and a slow disk array can handle 300 rules if you're only getting 10 hits per second, but if you're getting 500, it's a completely different game.

And how do you quantify server performance? You've got the hardware (CPU speed, memory size, bus widths, disk latency and transfer speed, etc. Then you've got software... DO you use PERL and/or PHP scripts? How big are those scripts? Oh, and are you on a shared server? The performance will then depend upon how "busy" all the rest of the sites on that server are...

In short, you can hire an Einstein to sit down and calculate the answer, given a year or two, or you can take 299 rules that won't do a rewrite, followed by the last one which will do a rewrite, and slap them in your .htaccess or httpd.conf file, and see if you notice any difference. The 299 rules won't do anything, but they will have to be processed, and then the last one will execute, just to prove that your code works.

There are also some techniques that can be applied to minimize performance problems, even if you're stuck (like most Webmasters) with .htaccess privileges only. For example, instead of putting all of the rules into one big .htaccess file in your home directory, put all the rules that apply to images into a smaller .htaccess file in your /images directory, and put your code that applies to external JavaScript files into an .htaccess file in your /js directory. That way, those rules will only be processed when a URL resolves to the directory they're located in.

So, concerning your 300 rules, this is the best "non-answer" I can give... :)

Jim