Search This Blog

Sunday, June 06, 2010

Apache Optimization

Apache "Directives"

You can configure the Apache software by modifying text configuration files. These files contain instructions. These instructions are created in a format known as "directives".

For Example:

Directives typically look like this:


ServerRoot /usr/local/lib/apache

OR


Order allow,deny
Allow from all
Deny from badusers.com


Directives are used in all configuration files



Optimizing the Directives

Timeout

The number of seconds before receives and sends is known as time out
By default the Timeout directive is set to 300 seconds.

We can decrease the Value of the timeout up to 15 Sec to avoid the potential effect of the DDOS attack or there is a heavy load in the server.

KeepAlive

The KeepAlive directive allows multiple requests to be sent over the same TCP connection.


For Eg:

If a particular page consists of lot of images in it, If KeepAlive is set to Off, then for each images, a separate TCP connection has to be made

Issues due to establishing lot of TCP connections can be eliminated by turning on the KeepAlive to On.

MaxKeepAliveRequests

The MaxKeepAliveRequests means that the maximum number of connections allowed in persistent connection.

Keep this value as 0 means that unlimited connections are possible. For the Maximum performance keep the value intact.


KeepAliveTimeout

It determines how long to wait for the next request for the processing. Generally we will set this value to a small one. That is in between 2-5 Secs.

MaxClients

It sets the limit on maximum simultaneous requests that can be supported by the server.

It is the maximum number of child processes spawned. It should be a medium value.

Setting this value to very low number creates the unused resources, since the new connections are put in queue, which eventually time-out.

Setting this value to very high number will cause the server to start swapping and the response time will degrade drastically

The apt value for the MaxClients can be calculated from the following equation.

MaxClients = Total RAM dedicated to the web server / Max child process size


DirectoryIndex

The DirectoryIndex directive sets the list of resources to look for, when the client requests an index of the directory.

DirectoryIndex index.html.var index.htm index.html index.shtml index.xhtml index.wml index.perl index.pl index.plx index.ppl index.cgi index.jsp index.js index.jp index.php4 index.php3 index.php index.phtml default.htm default.html home.htm index.php5 Default.html Default.htm home.html

Use the above given format rather than using the Wildcard method.


MPM (Multi-Processing Modules)

It is designed to allow more requests to be served simultaneously by passing off some processing work to supporting threads, freeing up the main threads to work on new requests.

StartServers

StartServers controls the number of child-processes that Apache forks before starting to accept connections

It is better to keep StartServers and MinSpareServers to high numbers,so that if you get a high load just after the server has been restarted, the fresh servers will be ready to serve requests immediately

FollowSymLinks and SymLinksIfOwnerMatch

For maximum performance, set FollowSymLinks everywhere and never set SymLinksIfOwnerMatch. Or else, if SymLinksIfOwnerMatch is required for a directory, then set it for that directory alone.


Common Configuration used in the Apache

Timeout 120
KeepAlive On
MaxKeepAliveRequests 300
KeepAliveTimeout 5
MinSpareServers 5
MaxSpareServers 20
StartServers 8
MaxClients 300
MaxRequestsPerChild 10

No comments: