Pages

Friday, July 1, 2011

APACHE 2 Performance tuning

Apache 2 Webserver Performance Tutorial



mod_gzipIf a clients Request contains Accept-encoding: gzip, deflate in the header then you should allow your webserver to serve your pages compressed.


mod_bandwidth
Mod_bandwidth is a bandwidth throttling module, useful for keeping the traffic of a whole Apache installation or of specific VirtualHosts or directories in check
mod_proxy
Another method to reduce traffic for a specific server and increase the speed with which pages are served is by using a front proxy.


KeepAlive and KeepAliveTimeout
The KeepAlive directive allows multiple requests to be sent over the same TCP connection. This is particularly useful while serving HTML pages with lot of images.

MaxRequestsPerChild
The MaxRequestsPerChild directive sets the limit on the number of requests that an individual child server process will handle.

MinSpareServers, MaxSpareServers, and StartServers
MaxSpareServers and MinSpareServers determine how many child processes to keep while waiting for requests. If the MinSpareServers is too low and a bunch of requests come in, then Apache will have to spawn additional child processes to serve the requests. Creating child processes is relatively expensive.Tune MinSpareServers and MaxSpareServers such that Apache need not frequently spwan more than 4 child processes per second


MaxClients
The MaxClients sets the limit on maximum simultaneous requests that can be supported by the server

AllowOverride
If AllowOverride is not set to 'None', then Apache will attempt to open .htaccess file (as specified by AccessFileName directive) in each directory that it visits.

When using Allow from or Deny from directives, use IP address instead of a domain name or a hostname. Otherwise a double DNS lookup is performed to make sure that the domain name or the hostname is not being spoofed.

Choose appropriate MPM
Apache server ships with a selection of Multi-Processing Modules (MPMs) which are responsible for binding to network ports on the machine, accepting requests, and dispatching children to handle the requests. Only one MPM can be loaded into the server at any time.

DECISION FACTORS
1. whether the OS supports threads
2. how much memory is available
3. scalability versus stability,
4. whether non-thread-safe third-party modules are used, etc..
     Linux systems can choose to use a threaded MPM like worker or a
     non-threaded MPM like prefork.

A.   Worker MPM
  1. uses multiple child processes.
  2. It's multi-threaded within each child and each thread handles a single connection.
  3. Worker is fast and highly scalable and the memory footprint is comparatively low.
  4. It's well suited for multiple processors.

Worker is less tolerant to faulty modules and faulty threads can affect all the threads in a child process.

B. Prefork MPM
uses multiple child processes, each child handles one connection at a time. Prefork is well suited for single or double CPU systems, speed is comparable to that of worker and it's highly tolerant to faulty modules and crashing children. But the memory usage is high, more traffic leads to more memory usage.

Load only the required modules
 This reduces the memory footprint and hence the server performance.



No comments:

Post a Comment