Htaccess considered slow
Posted: March 27, 2011 Filed under: Uncategorized Leave a comment »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:
- No rewrite rule.
- One rewrite rule, matched, rule is in .htaccess file.
- 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 ?