3980N/A<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
3980N/A<
TITLE>Descriptors and Apache</
TITLE>
4305N/A<!-- Background white, links blue (unvisited), navy (visited), red (active) --> 3980N/A<
H1 ALIGN="CENTER">Descriptors and Apache</
H1>
3980N/A<
P>A <
EM>descriptor</
EM>, also commonly called a <
EM>file handle</
EM> is
3980N/Aan object that a program uses to read or write an open file, or open
3980N/Anetwork socket, or a variety of other devices. It is represented
3980N/Aby an integer, and you may be familiar with <
CODE>stdin</
CODE>,
3980N/A<
CODE>stdout</
CODE>, and <
CODE>stderr</
CODE> which are descriptors 0,
3980N/AApache needs a descriptor for each log file, plus one for each
3980N/Anetwork socket that it listens on, plus a handful of others. Libraries
3980N/Athat Apache uses may also require descriptors. Normal programs don't
3980N/Aopen up many descriptors at all, and so there are some latent problems
3980N/Athat you may experience should you start running Apache with many
3980N/Adescriptors (<
EM>
i.e.</
EM>, with many virtual hosts).
3980N/A<
P>The operating system enforces a limit on the number of descriptors
3980N/Athat a program can have open at a time. There are typically three limits
4305N/Ainvolved here. One is a kernel limitation, depending on your operating
3980N/Asystem you will either be able to tune the number of descriptors available
3980N/Ato higher numbers (this is frequently called <
EM>FD_SETSIZE</
EM>). Or you
3980N/Amay be stuck with a (relatively) low amount. The second limit is called
3980N/Athe <
EM>hard resource</
EM> limit, and it is sometimes set by root in an
3980N/Aobscure operating system file, but frequently is the same as the kernel
3980N/Alimit. The third limit is called the <
EM>soft
3980N/Aresource</
EM> limit. The soft limit is always less than or equal to
3980N/Athe hard limit. For example, the hard limit may be 1024, but the soft
3980N/Alimit only 64. Any user can raise their soft limit up to the hard limit.
3980N/ARoot can raise the hard limit up to the system maximum limit. The soft
3980N/Alimit is the actual limit that is used when enforcing the maximum number
3980N/Aof files a process can have open.
3980N/A #open files <= soft limit <= hard limit <= kernel limit
3980N/A<
P>You control the hard and soft limits using the <
CODE>limit</
CODE> (csh)
3980N/Aor <
CODE>ulimit</
CODE> (sh) directives. See the respective man pages
3980N/Afor more information. For example you can probably use
3980N/A<
CODE>ulimit -n unlimited</
CODE> to raise your soft limit up to the
3980N/Ahard limit. You should include this command in a shell script which
3980N/A<
P>Unfortunately, it's not always this simple. As mentioned above,
3980N/Ayou will probably run into some system limitations that will need to be
3980N/Aworked around somehow. Work was done in version 1.2.1 to improve the
3980N/Asituation somewhat. Here is a partial list of systems and workarounds
3980N/A(assuming you are using 1.2.1 or later):
3980N/A <
DT><
STRONG>BSDI 2.0</
STRONG>
3980N/A <
DD>Under BSDI 2.0 you can build Apache to support more descriptors
3980N/A by adding <
CODE>-DFD_SETSIZE=nnn</
CODE> to
3980N/A <
CODE>EXTRA_CFLAGS</
CODE> (where nnn is the number of descriptors
3980N/A you wish to support, keep it less than the hard limit). But it
3980N/A will run into trouble if more than approximately 240 Listen
3980N/A directives are used. This may be cured by rebuilding your kernel
3980N/A <
DT><
STRONG>FreeBSD 2.2, BSDI 2.1+</
STRONG>
3980N/A <
DD>Similar to the BSDI 2.0 case, you should define
3980N/A <
CODE>FD_SETSIZE</
CODE> and rebuild. But the extra
3980N/A Listen limitation doesn't exist.
3980N/A <
DD>By default Linux has a kernel maximum of 256 open descriptors
3980N/A per process. There are several patches available for the
3980N/A 2.0.x series which raise this to 1024 and beyond, and you
3980N/A can find them in the "unofficial patches" section of <
A 3980N/A None of these patches are perfect, and an entirely different
3980N/A approach is likely to be taken during the
2.1.x development.
3980N/A Applying these patches will raise the FD_SETSIZE used to compile
3980N/A all programs, and unless you rebuild all your libraries you should
3980N/A avoid running any other program with a soft descriptor limit above
3980N/A 256. As of this writing the patches available for increasing
3980N/A the number of descriptors do not take this into account. On a
3980N/A dedicated webserver you probably won't run into trouble.
3980N/A <
DT><
STRONG>Solaris through 2.5.1</
STRONG>
3980N/A <
DD>Solaris has a kernel hard limit of 1024 (may be lower in earlier
3980N/A versions). But it has a limitation that files using
3980N/A the stdio library cannot have a descriptor above 255.
3980N/A Apache uses the stdio library for the ErrorLog directive.
3980N/A When you have more than approximately 110 virtual hosts
3980N/A (with an error log and an access log each) you will need to
3980N/A build Apache with <
CODE>-DHIGH_SLACK_LINE=256</
CODE> added to
3980N/A <
CODE>EXTRA_CFLAGS</
CODE>. You will be limited to approximately
3980N/A 240 error logs if you do this.
3980N/A <
DD>AIX version 3.2?? appears to have a hard limit of 128 descriptors.
3980N/A End of story. Version 4.1.5 has a hard limit of 2000.
3980N/A <
DT><
STRONG>Others</
STRONG>
3980N/A <
DD>If you have details on another operating system, please submit
3980N/A<
P>In addition to the problems described above there are problems with
3980N/Amany libraries that Apache uses. The most common example is the bind
3980N/ADNS resolver library that is used by pretty much every unix, which
fails if it ends up with a descriptor above 256. We suspect there
are other libraries that similar limitations. So the code as of 1.2.1
takes a defensive stance and tries to save descriptors less than 16
for use while processing each request. This is called the <
EM>low
<
P>Note that this shouldn't waste descriptors. If you really are pushing
the limits and Apache can't get a descriptor above 16 when it wants
it, it will settle for one below 16.
<
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