Htaccess considered slow

Are .htacccess configuration files slow ? One could guess so, considering they are checked for changes on every single request. To verify this, I tested three scenarios:

  1. No rewrite rule.
  2. One rewrite rule, matched, rule is in .htaccess file.
  3. One rewrite rule, matched, rule is in Apache configuration file.

Here are the results, with concurrency = 100 and 100 000 requests:

Scenario Avg. throughput (#/s) Avg. response time (ms)
1 5304.41 18.852
2 4321.07 23.142
3 4644.17 21.532

This roughly means that not using an htaccess file for a simple rewrite rule is means a 7% increase in throughput and 7% decrease in response time, which is non-negligible and easy to obtain, especially since it does not affect code quality at all.

Even more surprising is the slowness of the rewrite engine. Granted, regular expressions are not free, but I would guess that Apache caches the matches in a hashmap, on which lookups are practically free (complexity is O(1)). As such, how can you explain the 14% difference in throughput between the scenarios 1 and 3 ?

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s