1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5 This file is generated from xml source: DO NOT EDIT
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
8 <title>Descriptors and Apache - Apache HTTP Server</title>
9 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
12 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
13 <body id="manual-page"><div id="page-header">
14 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
15 <p class="apache">Apache HTTP Server Version 2.0</p>
16 <img alt="" src="../images/feather.gif" /></div>
17 <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
19 <a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.0</a> > <a href="./">Miscellaneous Documentation</a></div><div id="page-content"><div id="preamble"><h1>Descriptors and Apache</h1>
21 <p><span>Available Languages: </span><a href="../en/misc/descriptors.html" title="English"> en </a></p>
25 <div class="warning"><h3>Warning:</h3>
26 <p>This document has not been fully updated
27 to take into account changes made in the 2.0 version of the
28 Apache HTTP Server. Some of the information may still be
29 relevant, but please use it with care.</p>
32 <p>A <em>descriptor</em>, also commonly called a <em>file
33 handle</em> is an object that a program uses to read or write
34 an open file, or open network socket, or a variety of other
35 devices. It is represented by an integer, and you may be
36 familiar with <code>stdin</code>, <code>stdout</code>, and
37 <code>stderr</code> which are descriptors 0, 1, and 2
38 respectively. Apache needs a descriptor for each log file, plus
39 one for each network socket that it listens on, plus a handful
40 of others. Libraries that Apache uses may also require
41 descriptors. Normal programs don't open up many descriptors at
42 all, and so there are some latent problems that you may
43 experience should you start running Apache with many
44 descriptors (<em>i.e.</em>, with many virtual hosts).</p>
46 <p>The operating system enforces a limit on the number of
47 descriptors that a program can have open at a time. There are
48 typically three limits involved here. One is a kernel
49 limitation, depending on your operating system you will either
50 be able to tune the number of descriptors available to higher
51 numbers (this is frequently called <em>FD_SETSIZE</em>). Or you
52 may be stuck with a (relatively) low amount. The second limit
53 is called the <em>hard resource</em> limit, and it is sometimes
54 set by root in an obscure operating system file, but frequently
55 is the same as the kernel limit. The third limit is called the
56 <em>soft resource</em> limit. The soft limit is always less
57 than or equal to the hard limit. For example, the hard limit
58 may be 1024, but the soft limit only 64. Any user can raise
59 their soft limit up to the hard limit. Root can raise the hard
60 limit up to the system maximum limit. The soft limit is the
61 actual limit that is used when enforcing the maximum number of
62 files a process can have open.</p>
66 <div class="example"><p><code>
67 #open files <= soft limit <= hard limit <= kernel limit
71 <p>You control the hard and soft limits using the
72 <code>limit</code> (csh) or <code>ulimit</code> (sh)
73 directives. See the respective man pages for more information.
74 For example you can probably use <code>ulimit -n
75 unlimited</code> to raise your soft limit up to the hard limit.
76 You should include this command in a shell script which starts
79 <p>Unfortunately, it's not always this simple. As mentioned
80 above, you will probably run into some system limitations that
81 will need to be worked around somehow. Work was done in version
82 1.2.1 to improve the situation somewhat. Here is a partial list
83 of systems and workarounds (assuming you are using 1.2.1 or
87 <div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#bsdi">BSDI 2.0</a></li>
88 <li><img alt="" src="../images/down.gif" /> <a href="#freebsd">FreeBSD 2.2, BSDI 2.1+</a></li>
89 <li><img alt="" src="../images/down.gif" /> <a href="#linux">Linux</a></li>
90 <li><img alt="" src="../images/down.gif" /> <a href="#solaris">Solaris through 2.5.1</a></li>
91 <li><img alt="" src="../images/down.gif" /> <a href="#AIX">AIX</a></li>
92 <li><img alt="" src="../images/down.gif" /> <a href="#sco">SCO OpenServer</a></li>
93 <li><img alt="" src="../images/down.gif" /> <a href="#tru64">Compaq Tru64 UNIX/Digital UNIX/OSF</a></li>
94 <li><img alt="" src="../images/down.gif" /> <a href="#others">Others</a></li>
96 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
98 <h2><a name="bsdi" id="bsdi">BSDI 2.0</a></h2>
100 <p>Under BSDI 2.0 you can build Apache to support more
101 descriptors by adding <code>-DFD_SETSIZE=nnn</code> to
102 <code>EXTRA_CFLAGS</code> (where nnn is the number of
103 descriptors you wish to support, keep it less than the hard
104 limit). But it will run into trouble if more than
105 approximately 240 Listen directives are used. This may be
106 cured by rebuilding your kernel with a higher
109 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
110 <div class="section">
111 <h2><a name="freebsd" id="freebsd">FreeBSD 2.2, BSDI 2.1+</a></h2>
113 <p>Similar to the BSDI 2.0 case, you should define
114 <code>FD_SETSIZE</code> and rebuild. But the extra Listen
115 limitation doesn't exist.</p>
117 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
118 <div class="section">
119 <h2><a name="linux" id="linux">Linux</a></h2>
121 <p>By default Linux has a kernel maximum of 256 open
122 descriptors per process. There are several patches available
123 for the 2.0.x series which raise this to 1024 and beyond, and
124 you can find them in the "unofficial patches" section of <a href="http://www.linuxhq.com/">the Linux Information HQ</a>.
125 None of these patches are perfect, and an entirely different
126 approach is likely to be taken during the 2.1.x development.
127 Applying these patches will raise the FD_SETSIZE used to
128 compile all programs, and unless you rebuild all your
129 libraries you should avoid running any other program with a
130 soft descriptor limit above 256. As of this writing the
131 patches available for increasing the number of descriptors do
132 not take this into account. On a dedicated webserver you
133 probably won't run into trouble.</p>
135 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
136 <div class="section">
137 <h2><a name="solaris" id="solaris">Solaris through 2.5.1</a></h2>
139 <p>Solaris has a kernel hard limit of 1024 (may be lower in
140 earlier versions). But it has a limitation that files using
141 the stdio library cannot have a descriptor above 255. Apache
142 uses the stdio library for the ErrorLog directive. When you
143 have more than approximately 110 virtual hosts (with an error
144 log and an access log each) you will need to build Apache
145 with <code>-DHIGH_SLACK_LINE=256</code> added to
146 <code>EXTRA_CFLAGS</code>. You will be limited to
147 approximately 240 error logs if you do this.</p>
149 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
150 <div class="section">
151 <h2><a name="AIX" id="AIX">AIX</a></h2>
153 <p>AIX version 3.2?? appears to have a hard limit of 128
154 descriptors. End of story. Version 4.1.5 has a hard limit of
157 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
158 <div class="section">
159 <h2><a name="sco" id="sco">SCO OpenServer</a></h2>
161 <p>Edit the <code>/etc/conf/cf.d/stune</code> file or use
162 <code>/etc/conf/cf.d/configure</code> choice 7 (User and
163 Group configuration) and modify the <code>NOFILES</code>
164 kernel parameter to a suitably higher value. SCO recommends a
165 number between 60 and 11000, the default is 110. Relink and
166 reboot, and the new number of descriptors will be
169 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
170 <div class="section">
171 <h2><a name="tru64" id="tru64">Compaq Tru64 UNIX/Digital UNIX/OSF</a></h2>
174 <li>Raise <code>open_max_soft</code> and
175 <code>open_max_hard</code> to 4096 in the proc subsystem.
176 Do a man on sysconfig, sysconfigdb, and
179 <li>Raise <code>max-vnodes</code> to a large number which
180 is greater than the number of apache processes * 4096
181 (Setting it to 250,000 should be good for most people).
182 Do a man on sysconfig, sysconfigdb, and
185 <li>If you are using Tru64 5.0, 5.0A, or 5.1, define
186 <code>NO_SLACK</code> to work around a bug in the OS.
187 <code>CFLAGS="-DNO_SLACK" ./configure</code></li>
190 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
191 <div class="section">
192 <h2><a name="others" id="others">Others</a></h2>
194 <p>If you have details on another operating system, please
195 submit it through our <a href="http://httpd.apache.org/bug_report.html">Bug Report
198 <p>In addition to the problems described above there are
199 problems with many libraries that Apache uses. The most common
200 example is the bind DNS resolver library that is used by pretty
201 much every unix, which fails if it ends up with a descriptor
202 above 256. We suspect there are other libraries that similar
203 limitations. So the code as of 1.2.1 takes a defensive stance
204 and tries to save descriptors less than 16 for use while
205 processing each request. This is called the <em>low slack
208 <p>Note that this shouldn't waste descriptors. If you really
209 are pushing the limits and Apache can't get a descriptor above
210 16 when it wants it, it will settle for one below 16.</p>
212 <p>In extreme situations you may want to lower the low slack
213 line, but you shouldn't ever need to. For example, lowering it
214 can increase the limits 240 described above under Solaris and
215 BSDI 2.0. But you'll play a delicate balancing game with the
216 descriptors needed to serve a request. Should you want to play
217 this game, the compile time parameter is
218 <code>LOW_SLACK_LINE</code> and there's a tiny bit of
219 documentation in the header file <code>httpd.h</code>.</p>
221 <p>Finally, if you suspect that all this slack stuff is causing
222 you problems, you can disable it. Add <code>-DNO_SLACK</code>
223 to <code>EXTRA_CFLAGS</code> and rebuild. But please report it
224 to our <a href="http://httpd.apache.org/bug_report.html">Bug
225 Report Page</a> so that we can investigate. </p>
228 <div class="bottomlang">
229 <p><span>Available Languages: </span><a href="../en/misc/descriptors.html" title="English"> en </a></p>
230 </div><div id="footer">
231 <p class="apache">Copyright 2009 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
232 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>