These changes are useful for all web servers, regardless of the architectural model.
The following parameter increases the number of TCP SYN packets that the server can queue before SYNs are dropped:
echo 30000 > /proc/sys/net/ipv4/tcp_max_syn_backlog
Web servers typically have a large number of TCP connections in the TIME-WAIT state. The following parameter increases the number connections that are allowed in that state:
echo 2000000 > /proc/sys/net/ipv4/tcp_max_tw_buckets
The following parameter sets the length for the number of packets that can be queued in the network core (below the IP layer). This allows more memory to be used for incoming packets, which would otherwise be dropped.
echo 50000 > /proc/sys/net/core/netdev_max_backlog
Apache’s main configuration file is httpd.conf. Several parameters can be modified in that file to improve performance:
The following parameter sets the upper bound on the number of processes that Apache can have running concurrently:
Larger values allow larger numbers of clients to be served simultaneously. Very large values may require Apache to be recompiled. This change should be used with care, because large numbers of processes can cause excessive overhead.
The following parameter indicates the number of requests that a single Apache process will perform on a connection for a client before it closes the connection:
Opening and closing connections consumes CPU cycles, so it is better for the server to provide as many responses on a single connection as possible. Therefore, larger numbers are better. In fact, setting this value to 0 indicates that the server should never close the connection if possible.
It determines the number of requests an individual Apache process will serve before it dies (and is reforked). 0 implies that the number is unlimited, but on some systems with memory leaks in the operating system, setting this to a nonzero value keeps the memory leak under control.
The following parameters determine the minimum and maximum number of idle processes that Apache keeps in anticipation of new requests coming in:
The idea is that it is cheaper to keep a live process idle than to fork a new process in response to a new request arrival. For highly loaded sites, you might want to increase these values.
Flash and Other Event-Driven Servers
A common problem event-driven servers have is that they use a large number of file descriptors and thus can run out of these descriptors if the maximum is not increased.
The following is an sh (shell) command that increases the number of open files a process may have:
ulimit -n 16384
The process (in this case, the web server) must also be modified to take advantage of large numbers of descriptors:
#define __FD_SETSIZE 16384
The default FD_SETSIZE on Linux 2.4 is only 1024.
The following parameter determines the number of active simultaneous connections:
echo 20000 > /proc/sys/net/tux/max_connect
The following parameter sets the maximum number of connections waiting in Tux’s accept queue:
echo 8192 > /proc/sys/net/tux/max_backlog
The following parameter disables logging of requests to disk:
echo 0 > /proc/sys/net/tux/logging
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
ExpiresByType image/x-icon “access plus 1 week”
ExpiresByType image/gif “access plus 1 week”
ExpiresByType image/jpg “access plus 1 week”
ExpiresByType image/jpeg “access plus 1 week”
ExpiresByType image/png “access plus 1 week”
ExpiresByType text/js “access plus 3 days”
ExpiresByType text/css “access plus 3 days”
ExpiresByType text/x-json “access plus 3 days”