Apache HTTP Server Configuration Examples
MaxRequestsPerChild has been renamed to MaxConnectionsPerChild, describes more accurately what it does. The old name is still supported.
MaxClients has been renamed to MaxRequestWorkers, which describes more accurately what it does. For async MPMs, like event, the maximum number of clients is not equivalent than the number of worker threads. The old name is still supported.
Apache2.2 Apache2.4 MaxClients -> MaxRequestsPerChild MaxRequestsPerChild -> MaxConnectionsPerChild
netstat -an |grep :80 |wc -l watch -d -n 1 "netstat -an |grep :80 |wc -l"
# To see number of IP connections and IPs connected to port 80, use the following command. netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1 watch -d -n 1 "netstat -plan|grep :80|awk {'print $5'}|sed -e 's/\:[^.]*$//'|sort|uniq -c|sort -nk 1"
Ref. http://www.webhostingtalk.com/showthread.php?t=673467
watch -d -n 1 "netstat -plan|egrep ':(80|443) '|awk {'print $5'}|sed -e 's/\:[^.]*$//'|sort|uniq -c|sort -nk 1"
# apachectl -V | grep 'Server MPM' Server MPM: Prefork or Server MPM: Worker
prefork (default)
# The default processing model (MPM) is the process-based # 'prefork' model. A thread-based model, 'worker', is also # available, but does not work with some modules (such as PHP). # The service must be stopped before changing this variable. # #HTTPD=/usr/sbin/httpd.worker
worker
HTTPD=/usr/sbin/httpd.worker
# prefork MPM # StartServers: number of server processes to start # MinSpareServers: minimum number of server processes which are kept spare # MaxSpareServers: maximum number of server processes which are kept spare # ServerLimit: maximum value for MaxClients for the lifetime of the server # MaxClients: maximum number of server processes allowed to start # MaxRequestsPerChild: maximum number of requests a server process servesStartServers 8 MinSpareServers 5 MaxSpareServers 20 ServerLimit 256 MaxClients 256 MaxRequestsPerChild 4000 # worker MPM # StartServers: initial number of server processes to start # MaxClients: maximum number of simultaneous client connections # MinSpareThreads: minimum number of worker threads which are kept spare # MaxSpareThreads: maximum number of worker threads which are kept spare # ThreadsPerChild: constant number of worker threads in each server process # MaxRequestsPerChild: maximum number of requests a server process servesStartServers 2 MaxClients 150 MinSpareThreads 25 MaxSpareThreads 75 ThreadsPerChild 25 MaxRequestsPerChild 0
MaxClients x The memory size of using a apache process < PhisicalMemory 500 x 10MB = 5,000MB = 5GB 1000 x 10MB = 10,000MB = 10GB 1500 x 10MB = 15,000MB = 15GB
The memory size of using a apache process = RES - SHR 5,292Kbyte - 1612Kbyte = 3,680Kbyte = 3.6Mbyte
#top PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1045 root 20 0 179m 4180 2144 S 0.0 0.8 0:00.18 httpd 1051 apache 20 0 181m 5448 1752 S 0.0 1.1 0:00.00 httpd 1052 apache 20 0 181m 5292 1612 S 0.0 1.1 0:00.00 httpd 1053 apache 20 0 181m 5292 1612 S 0.0 1.1 0:00.11 httpd 1054 apache 20 0 181m 5292 1612 S 0.0 1.1 0:00.00 httpd 1055 apache 20 0 181m 5292 1612 S 0.0 1.1 0:00.11 httpd 1056 apache 20 0 181m 5448 1752 S 0.0 1.1 0:00.06 httpd 1057 apache 20 0 181m 5292 1612 S 0.0 1.1 0:00.17 httpd 1058 apache 20 0 181m 5448 1752 S 0.0 1.1 0:00.00 httpd
#!/bin/sh HTTPD="/usr/sbin/httpd" #HTTPD="/usr/local/apache2/httpd" #Physical Memory MEM=`cat /proc/meminfo |grep MemTotal |awk '{print $2}'` #Apache SUM=0 for PID in `ps aux |grep ${HTTPD} |grep -v grep |awk '{print $2}'` do TMP=`cat /proc/$PID/status |grep VmHWM| awk '{print $2}'` if [ "$?" -eq "0" ]; then TMPSUM=`expr \( $SUM + $TMP \) / 2` SUM=$TMPSUM fi done MAX=`expr $MEM / $SUM` #1024MB * 1000 / 5kB (kB) MEM01G=`expr 1024 \* 1000 / $SUM` MEM02G=`expr 2048 \* 1000 / $SUM` MEM04G=`expr 4096 \* 1000 / $SUM` MEM06G=`expr 6144 \* 1000 / $SUM` MEM08G=`expr 8192 \* 1000 / $SUM` MEM12G=`expr 12280 \* 1000 / $SUM` MEM16G=`expr 16384 \* 1000 / $SUM` cat <<OUT Memory : `printf "%'d\n" "$MEM"` kB a apache memory : `printf "%'d\n" "$SUM"` kB MaxClients $MAX If Memory 1G : maxClients $MEM01G Memory 2G : maxClients $MEM02G Memory 4G : maxClients $MEM04G Memory 6G : maxClients $MEM06G Memory 8G : maxClients $MEM08G Memory 12G : maxClients $MEM12G Memory 16G : maxClients $MEM16G OUT
# ./test.sh Memory : 502,220 kB a apache memory : 5,499 kB MaxClients 91 If Memory 1G : maxClients 186 Memory 2G : maxClients 372 Memory 4G : maxClients 744 Memory 6G : maxClients 1117 Memory 8G : maxClients 1489 Memory 12G : maxClients 2233 Memory 16G : maxClients 2979