CA BD NY
  • Categories

  • Recent Posts

  • RSS MySQL Hacker

  • RSS CentOS Hacker

  • RSS Editor's Lists

    • An error has occurred; the feed is probably down. Try again later.
  • Meta

  • Avoiding .htaccess is a Good Thing for Apache Performance

    Published November 28th, 2008

    Problem Statement

    When you are running a busy Web site, you need to count on every ounce of juice to gain performance almost bit by bit. If your site is blessed with a lot of traffic and you are struggling to keep it fast, we hope you are not using .htaccess or any other file pointed by AccessFileName directive in your Apache configuration (httpd.conf). Let us explain why.

    Why .htaccess is bad for performance

    When you run a site with .htaccess enabled, the site is likely to be configured with an Apache configuration like below:

    
    AccessFileName .htaccess
    <Directory "/path/to/your/docroot">l;
       AllowOverride All
    </Directory>
    

    This tells Apache that you can have a .htaccess file anywhere in your Web site and it can have a lot of different directives to customize how Apache handles your site. This sounds great but the catch is that for every access to any page on your Web site, Apache now must also check if there is a .htaccess file that exists.

    Since disk I/O is the slowest component of your server response time, adding an additional disk I/O to read the .htaccess file makes every access slower. For example, say you have placed an .htaccess file in the document root (/var/data/web/site/htdocs) and you are accessing an image file in http://server/dir1/dir2/dir3/myphoto.png. Here is what Apache checks:

    Does /var/data/web/site/htdocs/.htaccess exists?
    Does /var/data/web/site/htdocs/dir1/.htaccess exists?
    Does /var/data/web/site/htdocs/dir1/dir2/.htaccess exists?
    Does /var/data/web/site/htdocs/dir1/dir2/dir3/.htaccess exists?
    

    As you can see, this can be really hurting a busy site’s performance as many unnecessary disk I/O requests are made just to check the existence of the .htaccess file.

    How to avoid .htaccess performance penalty

    Here are your options:

    • Avoid .htaccess and place your configuration in your virtual host configuration file that gets loaded once by Apache server at startup
    • If you must use .htaccess, consider placing it inside the directory where you need it

    Get a Trackback link

    No Comments Yet

    Be the first to comment!

    Leave a comment

    Comment Policy: First time comments are moderated. Please be patient.

    You must be logged in to post a comment.