wiki'd

by JoKeru

Apache Performance Tunning

The single biggest issue affecting Apache webserver performance is RAM. Have as much RAM as your hardware, OS, and funds allow. The more RAM your system has, the more processes (and threads) Apache can allocate and use - which directly translates into the amount of concurrent requests/clients Apache can serve.

1. TimeOut

Lower the amount of time the server will wait before failing a request.

Timeout 15

2. KeepAlive

This directive allows multiple requests to be sent over the same TCP connection. This is particularly useful while serving HTML pages with lots of images. If KeepAlive is set to Off, then for each images, a separate TCP connection has to be made. Overhead due to establishing TCP connection can be eliminated by turning On KeepAlive. KeepAliveTimeout determines how long to wait for the next request. MaxKeepAliveRequests is the maximum number of requests to allow during a persistent connection.

KeepAlive On  
KeepAliveTimeout 3  
MaxKeepAliveRequests 50  

3. Process Creation - prefork MPM

<ifmodule mpm_prefork_module>  
StartServers 20  
MinSpareServers 10  
MaxSpareServers 20  
MaxClients 256  
MaxRequestsPerChild 5000  
</ifmodule>  

MaxClients sets a limit on the number of simultaneous connections/requests that will be served. Set this number too low and resources will go to waste. Set this number too high and an influx of connections will bring the server to a stand still. Set this number just right and your server will fully utilize the available resources. An approximation of this number should be derived by dividing the amount of system memory (physical RAM) available by the maximum size of an apache/httpd process (with a generous amount spared for all other processes).

MaxClients ≈ (RAM - size_all_other_processes) / (size_apache_process)

Get the value of apache process size in KiloBytes (RSS column):

$ ps -ylC apache2 --sort:rss  

The StartServers directive sets the number of child server processes created on startup. Apache will continue creating child processes until the MinSpareServers setting is reached. This doesn't have much effect on performance if the server isn't restarted frequently. If there are lot of requests and Apache is restarted frequently, set this to a relatively high value.

MaxSpareServers and MinSpareServers determine how many child processes to keep active while waiting for requests. If the MinSpareServers is too low and a bunch of requests come in, Apache will have to spawn additional child processes to serve the requests. Creating child processes is relatively expensive. If the server is busy creating child processes, it won't be able to serve the client requests immediately. MaxSpareServers shouldn't be set too high: too many child processes will consume resources unnecessarily. Tune MinSpareServers and MaxSpareServers so that Apache need not spawn more than 4 child processes per second (Apache can spawn a maximum of 32 child processes per second). When more than 4 children are spawned per second, a message will be logged in the ErrorLog.

The MaxRequestsPerChild directive sets the limit on the number of requests that an individual child server process will handle. After MaxRequestsPerChild requests, the child process will die. It's set to 0 by default, the child process will never expire. It is appropriate to set this to a value of few thousands. This can help prevent memory leakage, since the process dies after serving a certain number of requests. Don't set this too low, since creating new processes does have overhead. The goal here is to recycle each process once per day, as apache threads gradually increase their memory allocation as they run.

4. SymLinks

Make sure Options +FollowSymLinks -SymLinksIfOwnerMatch is set for all directories. Otherwise, Apache will issue an extra system call per filename component to substantiate that the filename is NOT a symlink, and more system calls to match an owner.

<directory xxx>
 Options FollowSymLinks
</directory>

5. AllowOverride

Set a default AllowOverride None for your filesystem. Otherwise, for a given URL to path translation, Apache will attempt to detect an .htaccess file under every directory level of the given path.

<directory xxx>
 AllowOverride None
</directory>

source: http://linuxgazette.net/123/vishnu.html source: http://httpd.apache.org/docs/2.0/misc/perf-tuning.html source: http://www.devside.net/articles/apache-performance-tuning

Comments