📄 710-712.html
字号:
<HTML>
<HEAD>
<TITLE>Special Edition Using Linux, Fourth Edition:Managing an Internet Web Server</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0789717468//-->
<!--TITLE=Special Edition Using Linux, Fourth Edition//-->
<!--AUTHOR=Jack Tackett//-->
<!--AUTHOR=Jr.//-->
<!--AUTHOR=Steve Burnett//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Que//-->
<!--CHAPTER=37//-->
<!--PAGES=710-712//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch36/707-708.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="712-714.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 37<BR>Managing an Internet Web Server
</FONT></H2>
<P><I>by Steve Burnett</I></P>
<DL>
<DT><B><BIG>I</BIG>n this chapter
</B><DT>Controlling Server Child Processes
<DT>Using the Scoreboard File
<DT>Increasing Efficiency in the Server Software
<DT>Automating Logfile Rotation
<DT>Understanding Security Issues
<DT>Other Tuning Issues
</DL>
<P>One of the biggest strengths of the Apache Web server is that it’s highly tunable. Just about every feature that imposes any sort of extra server load is an option, which means you can sacrifice features for speed if you need to do so. That said, Apache is designed for speed and efficiency. Even with all of Apache’s features, you’ll probably swamp a full T1 worth of bandwidth before exhausting the resources of a well-constructed Web server’s hardware, be it a Linux system or something else.
</P>
<P>Apache has also been designed to give site administrators control over where to draw the line between security and functionality. For some sites with many internal users, such as an Internet service provider, being able to control the policies toward what functionality can be used where is important. Meanwhile, a Web design shop might want complete flexibility, even if it means that an errant Common Gateway Interface (CGI) script could expose a security hole or do damage (incidentally, many feel that CGI in general is one big security risk).</P>
<H3><A NAME="Heading2"></A><FONT COLOR="#000077">Controlling Server Child Processes</FONT></H3>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR>• <B>See</B> “Starting Up Apache,” <B>p. 677</B><HR></FONT>
</BLOCKQUOTE>
<P>As you learned in Chapter 35, “Getting Started with Apache,” Apache uses the concept of a <I>swarm</I> of semi-persistent <I>daemons</I>, sometimes also called <I>children</I>, running and answering queries simultaneously. Although the size of that swarm varies, there are limits to how large it can get and how quickly or slowly it can grow. This size issue is critical; one of the main performance problems with older servers that executed a <TT>fork()</TT> system call at every request was that there was no limit to the total number of simultaneous daemons, so when the main memory of a machine would get consumed and start swapping to disk, the machine would effectively lock up and become unuseable. This was colloquially called <I>daemon-spamming</I>.</P>
<P>Other server software lets you specify a fixed number of processes, with the “fork for every request” behavior kicking in if all the children are busy when a new request comes in. This is also not the best model—not only do many people set that fixed number too high (having 30 children running when only five are needed can hinder performance), but this design model also removed the protection against daemon-spamming.</P>
<P>So, the Apache model is to start out with a certain number of persistent processes, and make sure that you always keep some number (actually, a range somewhere between a minimum and a maximum) of “spare” processes to handle a wave of simultaneous requests. If you have to launch a few more processes to maintain the minimum number of spares, no problem. If you find yourself with more idle servers than your maximum number of spares, the excess idle ones can be killed. There’s a maximum number of processes, beyond which no more will be launched, to protect the machine against daemon-spamming.</P>
<P>The algorithm to protect against too many processes bogging down or killing a server is configured by using the following configuration directives in /usr/local/apache/httpd.conf:</P>
<!-- CODE SNIP //-->
<PRE>
StartServers 10
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
</PRE>
<!-- END CODE SNIP //-->
<P>These numbers are the defaults. This says that when Apache launches, 10 children (<TT>StartServers</TT>) are automatically launched, regardless of the request load at start. If all 10 children are swamped, more are forked until all requests can be answered as fast as they’re received. This requires at least five (<TT>MinSpareServers</TT>) but not more than 10 <TT>MaxSpareServers</TT>) free servers to deal with <I>spikes</I> in requests (that is, when a sudden burst of requests come in well within half a second of each other). Incidentally, these spikes are often caused by browsers that open a separate TCP connection for each inline image in a page in an attempt to improve perceived performance to the user, often at the expense of the server and network.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>These directives are part of the core feature set of Apache and should be available on any version of Apache.<HR></FONT>
</BLOCKQUOTE>
<P>Usually a stable number of simultaneous child processes is reached, but if the requests are just pouring in (you’ve installed the Pamela Anderson Fan Club page on your site, for example), you might reach the <TT>MaxClients</TT> limit. At that point, requests will queue into your kernel’s “listen” queue, waiting to get served. If still more pour in, your visitors will eventually see a “connections refused” message. However, this is still preferable to leaving the number of simultaneous processes unlimited, because the server would just launch children with wild abandon and start daemon-spamming, resulting in nobody getting any response from the server at all.</P>
<P>It’s recommended that you don’t adjust <TT>MaxClients</TT>, because 150 is a good number for most systems. However, you might be itching to see how many requests you can handle with that sixteen-multiprocessor Sun Enterprise 10000 with two gigabytes of RAM; in that case, setting <TT>MaxClients</TT> much higher makes sense. On the opposite end of the spectrum, you might be running the Web server on a machine with limited memory or CPU resources, and you might want to make sure that Apache doesn’t consume all resources at the cost of possibly not being able to serve all requests that come to your site. In that context, setting <TT>MaxClients</TT> lower makes sense.</P>
<H3><A NAME="Heading3"></A><FONT COLOR="#000077">Using the Scoreboard File</FONT></H3>
<P>Because the multiprocess model described in the preceding section required some decent communication between the parent and child processes, the most cross-platform method of performing that communication was chosen. This is a <I>scoreboard file</I>, where each child had a chunk of space in the file to which it was authorized to write. The parent <TT>httpd</TT> process watched that file to get a status report and make decisions about whether to launch more child processes or kill idle processes.</P>
<P>At first, this file was located in the /tmp directory. However, because of problems with Linux setups that regularly clear out /tmp directories (causing the server to go haywire), the scoreboard file has since been moved into the /var/log/ directory. You can configure where the scoreboard file goes exactly with a <TT>ScoreBoardFile</TT> directive.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch36/707-708.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="712-714.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -