What performance issues are there with using symlinks for your Apache docroot

I tried to find an existing question for this already, but couldn't find a good match.

As part of my deploy process for my public facing sites, I am using symlinks to swap between versions of the web application.

For instance, I have a vhost abc.com which has a docroot here: /var/www/abc.com

The docroot itself (/var/www/abc.com) is a symlink to the application's web-accesible directory (/var/www/package/buildX/web)

When I deploy a new build, I simply swap out the symlink and replace with another symlink to the new build.

The question I have is, what is the performance overhead (or concerns I should have) with using symlinks for an Apache docroot


Solution 1:

The first issue is, are all of these files in the same filesystem or physical storage device? If so, the difference between a direct reference and a symlink will be nearly impossible to detect.

You need to think in orders of magnitude here. Your application is probably underpinned by a scripting language and a database. Those elements of the application will be the limiting factor, not a minor filesystem feature. Jeff Atwood explains this best in this blog post.

Solution 2:

Don't worry about symlink performance hit. Practically everything else will be a bottleneck before that one. Resolving a symlink does not take too many CPU cycles; running your PHP script, handling the database queries and result sets, possibly using modules like Apache's mod_security will be the real bottle neck.

In theory you could optimize something if everything your server serves is static content; even then, tuning the web server and/or kernel parameters and scaling the hardware is the right thing to do, not silly micro-optimization such as dealing with symlinks. Symbolic links provide you a clean and convenient way to switch between web site version etc; use them happily.