Making Apach2 even faster
When I built my new webserver I had to decide if I gonna use lighttpd or apache2. I wanted to use lighttpd because in fact it is faster than apache2. But then I discovered that it doesn’t support .htaccess files heavily used by my customers. So I had to throw away my flowery plans and use apache2 again. (Not that I’m really sad about it – the configuration was easy beacause I’m using it since… a long time ago
)
But I figured there has to be something to make the apache2 faster that it is out-of-the-box on a Debian Etch system. I wanted to use mod_fastcgi to link PHP and use mpm-worker for apache2 but due to a lack of time I failed. Later I discovered it was only a matter of permission which prevented this. Due to mod-php5 I couldn’t use mpm-worker but had to use mpm-prefork the slower variant.
With this in mind I thought “lets check the apache2 docs and check if there is something we can do about this”. So I discovered the following directives which can fasten up things a little bit:
BufferedLogs On EnableSendfile On HostnameLookups Off
BufferedLogs is an experimental directive which prevents Apache2 to write logs directly to the disk but keeps them in memory and write them in a bunch. This should minimize the write overhead for each access so the access itself is faster.
With EnableSendfile you tell apache2 to use the sendfile method from the Kernel for static files which should prevent apache2 to read the file itself so reducing the readoverhead for static content.
HostnameLookups is off by default on Debian Etch. I don’t know how it is on other distributions. The command prevents apache2 to make an lookup for the ip from the visitor. When your nameserver is slow or no hostname can be resolved this could slow your system down incredibly. (In my expirience 70% all the problems with databases or webserver are DNS problems).