Latest high traffic web server config

This is for Apache 2.2.15 that ships with Red Hat Linux 6 on a web server with 16G RAM and 4 CPU. That’s right, this is a big one. This post was revised on 19 December 2013 to reflect new learnings (learnings, not leanings).

How much is enough RAM and CPU when it comes to high traffic web servers? The short answer is: never enough.

Putting aside the whole Apache vs. Nginx debate for now, here’s my latest config for an intranet server that always needs to be ready for a ridiculously large number of hits over a short period.

The server hosts a WordPress site backended by a co-located MySQL server database.

First my timeout and KeepAlive settings:

Timeout 60
KeepAlive On
MaxKeepAliveRequests 200
KeepAliveTimout 3

These are the RHEL 6 defaults. They’re actually pretty reasonable for most servers, including this one.

Here’s my prefork MPM config:

StartServers      10
MinSpareServers    5
MaxSpareServers   20
ServerLimit      300
MaxClients       300
MaxRequestsPerChild  1000

No major departures from the RHEL defaults here. StartServers, Min and MaxSpareServers are actually close to the defaults. ServerLimit and MaxClients are double the original values.

The biggest change here is probably in MaxRequestsPerChild. Out of the box Red Hat sets this to 4000, but with a raging debate over values from 0 to 4000 (Apache source defaults to 0, as does Fedora 19) I decided to run some tests with the check_httpd_limits.pl script and was surprised to find that reducing it to 1000 resulted in much more efficient use of RAM.

This is what the result looked like (host name changed to protect the innocent — and my employer’s network):

[root@bigserver ~]# check_httpd_limits.pl -v

Check Apache Httpd MPM Config Limits (Version 2.4)
by Jean-Sebastien Morisset - http://surniaulula.com/

Httpd Binary

 - CONFIG                : /etc/httpd/conf/httpd.conf
 - EXE                   : /usr/sbin/httpd
 - MPM                   : prefork
 - ROOT                  : /etc/httpd
 - VERSION               : 2.2

Httpd Processes

 - PID 2287 (httpd)      :   44.27 MB /   5.97 MB shared
 - PID 2853 (httpd)      :   15.37 MB /   5.35 MB shared
 - PID 18056 (httpd)     :   46.68 MB /   7.59 MB shared
 - PID 18922 (httpd)     :   47.77 MB /   7.83 MB shared
 - PID 19462 (httpd)     :   46.24 MB /   7.64 MB shared
 - PID 19463 (httpd)     :   46.64 MB /   7.57 MB shared
 - PID 20014 (httpd)     :   46.69 MB /   7.61 MB shared
 - PID 20124 (httpd)     :   46.67 MB /   7.57 MB shared
 - PID 20125 (httpd)     :   49.30 MB /   7.64 MB shared
 - PID 23774 (httpd)     :   46.83 MB /   7.58 MB shared
 - PID 23775 (httpd)     :   45.30 MB /   7.58 MB shared
 - PID 28202 (httpd)     :   46.88 MB /   7.77 MB shared
 - PID 28203 (httpd)     :   46.04 MB /   7.57 MB shared
 - PID 28206 (httpd)     :   46.71 MB /   7.60 MB shared
 - PID 28209 (httpd)     :   46.17 MB /   7.57 MB shared
 - PID 30599 (httpd)     :   49.25 MB /   7.57 MB shared
 - PID 30603 (httpd)     :   46.63 MB /   7.58 MB shared
 - PID 30604 (httpd)     :   46.71 MB /   7.60 MB shared
 - PID 30605 (httpd)     :   46.18 MB /   7.58 MB shared
 - PID 30836 (httpd)     :   46.19 MB /   7.60 MB shared
 - PID 31506 (httpd)     :   14.34 MB /   7.37 MB shared [excluded from averages]

 - HttpdRealAvg          :   38.79 MB [excludes shared]
 - HttpdSharedAvg        :    7.59 MB
 - HttpdRealTot          :  761.11 MB [excludes shared]
 - HttpdRunning          :      21

Httpd Config

 - StartServers          : 10
 - ServerLimit           : 300
 - MinSpareServers       : 5
 - MaxSpareServers       : 20
 - MaxRequestsPerChild   : 1000
 - MaxClients            : 300

Server Memory

 - Cached                :  8781.42 MB
 - MemFree               :  4624.80 MB
 - MemTotal              : 15953.82 MB
 - SwapFree              :  4031.99 MB
 - SwapTotal             :  4031.99 MB

Calculations Summary

 - OtherProcsMem         :  1778.90 MB (MemTotal - Cached - MemFree - HttpdRealTot - HttpdSharedAvg)
 - FreeMemNoHttpd        : 14174.92 MB (MemFree + Cached + HttpdRealTot + HttpdSharedAvg)
 - MaxLimitHttpdMem      : 11644.59 MB (HttpdRealAvg * MaxClients + HttpdSharedAvg)
 - AllProcsTotalMem      : 13423.49 MB (OtherProcsMem + MaxLimitHttpdMem)

Maximum Values for MemTotal (15953.82 MB)

   
	StartServers              10	# (no change) Default is 5
	ServerLimit              365	# (300 -> 365) MaxClients
	MinSpareServers            5	# (no change) Default is 5
	MaxSpareServers           20	# (no change) Default is 10
	MaxRequestsPerChild     1000	# (no change) Default is 10000
	MaxClients               365	# (300 -> 365) (MemFree + Cached + HttpdRealTot + HttpdSharedAvg) / HttpdRealAvg
   

Result

OK: AllProcsTotalMem (13423.49 MB) fits within MemTotal (15953.82 MB).
This entry was posted in System Administration, Web on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).