descriptors.html revision db81e057b060e365d840d9a1d35a5797192efa81
286N/A<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
286N/A<HTML>
286N/A<HEAD>
286N/A<TITLE>Descriptors and Apache</TITLE>
286N/A</HEAD>
286N/A
286N/A<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
286N/A<BODY
286N/A BGCOLOR="#FFFFFF"
286N/A TEXT="#000000"
286N/A LINK="#0000FF"
286N/A VLINK="#000080"
286N/A ALINK="#FF0000"
286N/A>
286N/A<!--#include virtual="header.html" -->
286N/A<H1 ALIGN="CENTER">Descriptors and Apache</H1>
286N/A
286N/A<p>A <EM>descriptor</EM>, also commonly called a <EM>file handle</EM> is
286N/Aan object that a program uses to read or write an open file, or open
286N/Anetwork socket, or a variety of other devices. It is represented
286N/Aby an integer, and you may be familiar with <code>stdin</code>,
286N/A<code>stdout</code>, and <code>stderr</code> which are descriptors 0,
286N/A1, and 2 respectively.
286N/AApache needs a descriptor for each log file, plus one for each
286N/Anetwork socket that it listens on, plus a handful of others. Libraries
286N/Athat Apache uses may also require descriptors. Normal programs don't
286N/Aopen up many descriptors at all, and so there are some latent problems
286N/Athat you may experience should you start running Apache with many
286N/Adescriptors (i.e. with many virtual hosts).
286N/A
286N/A<p>The operating system enforces a limit on the number of descriptors
286N/Athat a program can have open at a time. There are typically three limits
286N/Ainvolved here. One is a kernel limitation, depending on your operating
286N/Asystem you will either be able to tune the number of descriptors available
286N/Ato higher numbers (this is frequently called <EM>FD_SETSIZE</EM>). Or you
286N/Amay be stuck with a (relatively) low amount. The second limit is called
286N/Athe <EM>hard resource</EM> limit, and it is sometimes set by root in an
286N/Aobscure operating system file, but frequently is the same as the kernel
286N/Alimit. The third limit is called the <EM>soft
286N/Aresource</EM> limit. The soft limit is always less than or equal to
286N/Athe hard limit. For example, the hard limit may be 1024, but the soft
286N/Alimit only 64. Any user can raise their soft limit up to the hard limit.
286N/ARoot can raise the hard limit up to the system maximum limit. The soft
286N/Alimit is the actual limit that is used when enforcing the maximum number
286N/Aof files a process can have open.
286N/A
286N/A<p>To summarize:
286N/A
286N/A<center><pre>
286N/A #open files &lt;= soft limit &lt;= hard limit &lt;= kernel limit
286N/A</pre></center>
286N/A
286N/A<p>You control the hard and soft limits using the <code>limit</code> (csh)
286N/Aor <code>ulimit</code> (sh) directives. See the respective man pages
286N/Afor more information. For example you can probably use
286N/A<code>ulimit -n unlimited</code> to raise your soft limit up to the
286N/Ahard limit. You should include this command in a shell script which
286N/Astarts your webserver.
286N/A
286N/A<p>Unfortunately, it's not always this simple. As mentioned above,
286N/Ayou will probably run into some system limitations that will need to be
286N/Aworked around somehow. Work was done in version 1.2.1 to improve the
286N/Asituation somewhat. Here is a partial list of systems and workarounds
286N/A(assuming you are using 1.2.1 or later):
286N/A
286N/A<dl>
286N/A
286N/A <dt><STRONG>BSDI 2.0</STRONG>
286N/A <dd>Under BSDI 2.0 you can build Apache to support more descriptors
286N/A by adding <code>-DFD_SETSIZE=nnn</code> to
286N/A <code>EXTRA_CFLAGS</code> (where nnn is the number of descriptors
286N/A you wish to support, keep it less than the hard limit). But it
286N/A will run into trouble if more than approximately 240 Listen
286N/A directives are used. This may be cured by rebuilding your kernel
286N/A with a higher FD_SETSIZE.
286N/A <p>
286N/A
286N/A <dt><STRONG>FreeBSD 2.2, BSDI 2.1+</STRONG>
286N/A <dd>Similar to the BSDI 2.0 case, you should define
286N/A <code>FD_SETSIZE</code> and rebuild. But the extra
286N/A Listen limitation doesn't exist.
286N/A <p>
286N/A
286N/A <dt><STRONG>Linux</STRONG>
286N/A <dd>By default Linux has a kernel maximum of 256 open descriptors
286N/A per process. There are several patches available for the
286N/A 2.0.x series which raise this to 1024 and beyond, and you
286N/A can find them in the "unofficial patches" section of <a
286N/A href="http://www.linuxhq.com/">the Linux Information HQ</a>.
286N/A None of these patches are perfect, and an entirely different
286N/A approach is likely to be taken during the 2.1.x development.
286N/A Applying these patches will raise the FD_SETSIZE used to compile
286N/A all programs, and unless you rebuild all your libraries you should
286N/A avoid running any other program with a soft descriptor limit above
286N/A 256. As of this writing the patches available for increasing
286N/A the number of descriptors do not take this into account. On a
286N/A dedicated webserver you probably won't run into trouble.
286N/A <p>
286N/A
286N/A <dt><STRONG>Solaris through 2.5.1</STRONG>
286N/A <dd>Solaris has a kernel hard limit of 1024 (may be lower in earlier
286N/A versions). But it has a limitation that files using
286N/A the stdio library cannot have a descriptor above 255.
286N/A Apache uses the stdio library for the ErrorLog directive.
286N/A When you have more than approximately 110 virtual hosts
286N/A (with an error log and an access log each) you will need to
286N/A build Apache with <code>-DHIGH_SLACK_LINE=256</code> added to
286N/A <code>EXTRA_CFLAGS</code>. You will be limited to approximately
286N/A 240 error logs if you do this.
286N/A <p>
286N/A
286N/A <dt><STRONG>AIX version ??</STRONG>
286N/A <dd>AIX appears to have a hard limit of 128 descriptors. End of
286N/A story.
286N/A <p>
286N/A
286N/A <dt><STRONG>Others</STRONG>
286N/A <dd>If you have details on another operating system, please submit
286N/A it through our <a href="http://www.apache.org/bug_report.html">Bug
286N/A Report Page</a>.
286N/A <p>
286N/A
286N/A</dl>
286N/A
286N/A<p>In addition to the problems described above there are problems with
286N/Amany libraries that Apache uses. The most common example is the bind
286N/ADNS resolver library that is used by pretty much every unix, which
286N/Afails if it ends up with a descriptor above 256. We suspect there
286N/Aare other libraries that similar limitations. So the code as of 1.2.1
286N/Atakes a defensive stance and tries to save descriptors less than 16
286N/Afor use while processing each request. This is called the <EM>low
286N/Aslack line</EM>.
286N/A
286N/A<p>Note that this shouldn't waste descriptors. If you really are pushing
286N/Athe limits and Apache can't get a descriptor above 16 when it wants
286N/Ait, it will settle for one below 16.
286N/A
<p>In extreme situations you may want to lower the low slack line,
but you shouldn't ever need to. For example, lowering it can
increase the limits 240 described above under Solaris and BSDI 2.0.
But you'll play a delicate balancing game with the descriptors needed
to serve a request. Should you want to play this game, the compile
time parameter is <code>LOW_SLACK_LINE</code> and there's a tiny
bit of documentation in the header file <code>httpd.h</code>.
<p>Finally, if you suspect that all this slack stuff is causing you
problems, you can disable it. Add <code>-DNO_SLACK</code> to
<code>EXTRA_CFLAGS</code> and rebuild. But please report it to
our <a href="http://www.apache.org/bug_report.html">Bug
Report Page</a> so that
we can investigate.
<!--#include virtual="footer.html" -->
</BODY>
</HTML>