<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>Hints on Running a High-Performance Web Server</title>
</head>

<body>
<IMG SRC="../images/apache_sub.gif" ALT="">
<h2>Hints on Running a High-Performance Web Server</H2>

Running Apache on a heavily loaded web server, one often encounters
problems related to the machine and OS configuration.  "Heavy" is
relative, of course - but if you are seeing more than a couple hits
per second on a sustained basis you should consult the pointers on
this page.  In general the suggestions involve how to tune your kernel
for the heavier TCP load, hardware/software conflicts that arise, etc.

<UL>
<LI><A HREF="#AUX">A/UX (Apple's UNIX)</A>
<LI><A HREF="#BSD">BSD-based (BSDI, FreeBSD, etc)</A>
<LI><A HREF="#Linux">Linux</A>
<LI><A HREF="#Solaris">Solaris</A>
<LI><A HREF="#SunOS">SunOS 4.x</A>
</UL>

<HR>

<A NAME="AUX">
<H3>A/UX (Apple's UNIX)</H3>
</A>

If you are running Apache on A/UX, a page that gives some helpful
performance hints (concerning the <I>listen()</I> queue and using
virtual hosts)
<A HREF="http://www.jaguNET.com/apache.html">can be found here</A>

<P><HR>

<A NAME="#BSD">
<H3>BSD-based (BSDI, FreeBSD, etc)</H3>
</A>

Like other OS's, the listen queue is often the <b>first limit hit</b>.  The
following are comments from "Aaron Gifford &lt;agifford@InfoWest.COM&gt;"
on how to fix this on BSDI 1.x, 2.x,  and FreeBSD 2.0 (and earlier):

<p>

Edit the following two files:
<blockquote><code>  /usr/include/sys/socket.h <br>
  /usr/src/sys/sys/socket.h </code></blockquote>
In each file, look for the following:
<pre>
    /*
     * Maximum queue length specifiable by listen.
     */
    #define SOMAXCONN       5
</pre>

Just change the "5" to whatever appears to work.  I bumped the two
machines I was having problems with up to 32 and haven't noticed the
problem since.

<p>

After the edit, recompile the kernel and recompile the Apache server
then reboot.  

<P>

FreeBSD 2.1 seems to be perfectly happy, with SOMAXCONN
set to 32 already.

<P><HR>

<A NAME="DEC">
<H3>Digital UNIX</H3>
</A>

A whole page here is dedicated to Digital Unix

<A NAME="Linux">
<H3>Linux</H3>
</A>

The most common problem on Linux shows up on heavily-loaded systems
where the whole server will appear to freeze for a couple of minutes
at a time, and then come back to life.  This has been traced to a
listen() queue overload - certain Linux implementations have a low
value set for the incoming connection queue which can cause problems.
Please see our <a
href="http://www.qosina.com/apache/linux-tcp.html">Using Apache on
Linux</a> page for more info on how to fix this.

<P><HR>

<A NAME="Solaris">
<H3>Solaris 2.4</H3>
</A>

The Solaris 2.4 TCP implementation has a few inherent limitations that
only became apparent under heavy loads.  This has been fixed to some
extent in 2.5 (and completely revamped in 2.6), but for now consult
the following URL for tips on how to expand the capabilities if you
are finding slowdowns and lags are hurting performance.

<P>

<A href="http://www.sun.com/cgi-bin/show?sun-on-net/Sun.Internet.Solutions/performance/index.html">
http://www.sun.com/cgi-bin/show?sun-on-net/Sun.Internet.Solutions/performance/index.html</a>

<P><HR>

<A NAME="SunOS">
<H3>SunOS 4.x</H3>
</A>

More information on tuning SOMAXCONN on SunOS can be found at 
<A HREF="http://www.islandnet.com/~mark/somaxconn.html">
http://www.islandnet.com/~mark/somaxconn.html</A>.  

<P><HR>

<H3>More welcome!</H3>

If you have tips to contribute, send mail to <a
href="mailto:brian@organic.com">brian@organic.com</a>

<P><HR><P>
<A HREF="/"><IMG SRC="../images/apache_home.gif" ALT="Home"></A>
<A HREF="."><IMG SRC="../images/apache_index.gif" ALT="Index"></A>
</body></html>

