Apache Optimization
Benchmark Tools
To tune well, you need to benchmark your Web server. You can get some benchmark figures using these tools:
ApacheBench (ab)
httperf
Optimization tip
Don’t run X-Windows on the server and other unneeded processes.
Don’t use images when text will do. Reduce your image sizes.
Don’t Resolve Hostnames:
HostnameLookups off
Don’t do reverse lookups inside Apache. I can’t think of a good reason to do it. Any self respecting log parser can do this offline, in the background.
disable htaccess check:
<Directory />
AllowOverride none
</Directory>
turn on follow FollowSymLinks and turn off SymLinksIfOwnerMatch to prevent additional lstat() system calls:
Options FollowSymLinks
#Options SymLinksIfOwnerMatch
Optimizing Apache for low memory usage
Handle Fewer Simultaneous Requests:
StartServers 4
MinSpareServers 4
MaxSpareServers 8
MaxClients 16
MaxRequestsPerChild 48
The MaxRequestsPerChild variable tells Apache how many requests a given child process can handle before it should be killed. You want to kill processes, because different page requests will allocate more memory. If a script allocates a lot of memory, the Apache process under which it runs will allocate that memory, and it won’t let it go. If you’re bumping up against the memory limit of your system, this could cause you to have unnecessary swapping. Different people use different settings here. How to set this is probably a function of the traffic you receive and the nature of your site. Use your brain on this one.
Use KeepAlives, but not for too long:
KeepAlive On
KeepAliveTimeout 2
Keepalives are a way to have a persistent connection between a browser and a server. Originally, HTTP was envisioned as being “stateless.� Prior to keepalive, every image, javascript, frame, etc. on your pages had to be requested using a separate connection to the server. When keepalives came into wide use with HTTP/1.1, web browsers were able to keep a connection to a server open, in order to transfer multiple files across that same connection. Fewer connections, less overhead, more performance.