home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / apache_2.2.8-win32-x86-no_ssl.msi / Data1.cab / _1AA1F855507FD487E03A9EE4DA301F2A < prev    next >
Extensible Markup Language  |  2007-11-17  |  53KB  |  1,056 lines

  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
  7.       -->
  8. <title>Apache Performance Tuning - 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.2</p>
  16. <img alt="" src="../images/feather.gif" /></div>
  17. <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
  18. <div id="path">
  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.2</a> > <a href="./">Miscellaneous Documentation</a></div><div id="page-content"><div id="preamble"><h1>Apache Performance Tuning</h1>
  20. <div class="toplang">
  21. <p><span>Available Languages: </span><a href="../en/misc/perf-tuning.html" title="English"> en </a> |
  22. <a href="../ko/misc/perf-tuning.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
  23. </div>
  24.  
  25.  
  26.     <p>Apache 2.x is a general-purpose webserver, designed to
  27.     provide a balance of flexibility, portability, and performance.
  28.     Although it has not been designed specifically to set benchmark
  29.     records, Apache 2.x is capable of high performance in many
  30.     real-world situations.</p>
  31.  
  32.     <p>Compared to Apache 1.3, release 2.x contains many additional
  33.     optimizations to increase throughput and scalability. Most of
  34.     these improvements are enabled by default. However, there are
  35.     compile-time and run-time configuration choices that can
  36.     significantly affect performance. This document describes the
  37.     options that a server administrator can configure to tune the
  38.     performance of an Apache 2.x installation. Some of these
  39.     configuration options enable the httpd to better take advantage
  40.     of the capabilities of the hardware and OS, while others allow
  41.     the administrator to trade functionality for speed.</p>
  42.  
  43.   </div>
  44. <div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#hardware">Hardware and Operating System Issues</a></li>
  45. <li><img alt="" src="../images/down.gif" /> <a href="#runtime">Run-Time Configuration Issues</a></li>
  46. <li><img alt="" src="../images/down.gif" /> <a href="#compiletime">Compile-Time Configuration Issues</a></li>
  47. <li><img alt="" src="../images/down.gif" /> <a href="#trace">Appendix: Detailed Analysis of a Trace</a></li>
  48. </ul></div>
  49. <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  50. <div class="section">
  51. <h2><a name="hardware" id="hardware">Hardware and Operating System Issues</a></h2>
  52.  
  53.     
  54.  
  55.     <p>The single biggest hardware issue affecting webserver
  56.     performance is RAM. A webserver should never ever have to swap,
  57.     as swapping increases the latency of each request beyond a point
  58.     that users consider "fast enough". This causes users to hit
  59.     stop and reload, further increasing the load. You can, and
  60.     should, control the <code class="directive"><a href="../mod/mpm_common.html#maxclients">MaxClients</a></code> setting so that your server
  61.     does not spawn so many children it starts swapping. This procedure
  62.     for doing this is simple: determine the size of your average Apache
  63.     process, by looking at your process list via a tool such as
  64.     <code>top</code>, and divide this into your total available memory,
  65.     leaving some room for other processes.</p>
  66.  
  67.     <p>Beyond that the rest is mundane: get a fast enough CPU, a
  68.     fast enough network card, and fast enough disks, where "fast
  69.     enough" is something that needs to be determined by
  70.     experimentation.</p>
  71.  
  72.     <p>Operating system choice is largely a matter of local
  73.     concerns. But some guidelines that have proven generally
  74.     useful are:</p>
  75.  
  76.     <ul>
  77.       <li>
  78.         <p>Run the latest stable release and patchlevel of the
  79.         operating system that you choose. Many OS suppliers have
  80.         introduced significant performance improvements to their
  81.         TCP stacks and thread libraries in recent years.</p>
  82.       </li>
  83.  
  84.       <li>
  85.         <p>If your OS supports a <code>sendfile(2)</code> system
  86.         call, make sure you install the release and/or patches
  87.         needed to enable it. (With Linux, for example, this means
  88.         using Linux 2.4 or later. For early releases of Solaris 8,
  89.         you may need to apply a patch.) On systems where it is
  90.         available, <code>sendfile</code> enables Apache 2 to deliver
  91.         static content faster and with lower CPU utilization.</p>
  92.       </li>
  93.     </ul>
  94.  
  95.   </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  96. <div class="section">
  97. <h2><a name="runtime" id="runtime">Run-Time Configuration Issues</a></h2>
  98.  
  99.     
  100.  
  101.     <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="../mod/mod_dir.html">mod_dir</a></code></li><li><code class="module"><a href="../mod/mpm_common.html">mpm_common</a></code></li><li><code class="module"><a href="../mod/mod_status.html">mod_status</a></code></li></ul></td><td><ul><li><code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code></li><li><code class="directive"><a href="../mod/mod_dir.html#directoryindex">DirectoryIndex</a></code></li><li><code class="directive"><a href="../mod/core.html#hostnamelookups">HostnameLookups</a></code></li><li><code class="directive"><a href="../mod/core.html#enablemmap">EnableMMAP</a></code></li><li><code class="directive"><a href="../mod/core.html#enablesendfile">EnableSendfile</a></code></li><li><code class="directive"><a href="../mod/core.html#keepalivetimeout">KeepAliveTimeout</a></code></li><li><code class="directive"><a href="../mod/prefork.html#maxspareservers">MaxSpareServers</a></code></li><li><code class="directive"><a href="../mod/prefork.html#minspareservers">MinSpareServers</a></code></li><li><code class="directive"><a href="../mod/core.html#options">Options</a></code></li><li><code class="directive"><a href="../mod/mpm_common.html#startservers">StartServers</a></code></li></ul></td></tr></table>
  102.  
  103.     <h3><a name="dns" id="dns">HostnameLookups and other DNS considerations</a></h3>
  104.  
  105.       
  106.  
  107.       <p>Prior to Apache 1.3, <code class="directive"><a href="../mod/core.html#hostnamelookups">HostnameLookups</a></code> defaulted to <code>On</code>.
  108.       This adds latency to every request because it requires a
  109.       DNS lookup to complete before the request is finished. In
  110.       Apache 1.3 this setting defaults to <code>Off</code>. If you need
  111.       to have addresses in your log files resolved to hostnames, use the
  112.       <code class="program"><a href="../programs/logresolve.html">logresolve</a></code>
  113.       program that comes with Apache, or one of the numerous log
  114.       reporting packages which are available.</p>
  115.  
  116.       <p>It is recommended that you do this sort of postprocessing of
  117.       your log files on some machine other than the production web
  118.       server machine, in order that this activity not adversely affect
  119.       server performance.</p>
  120.  
  121.       <p>If you use any <code><code class="directive"><a href="../mod/mod_access.html#allow">Allow</a></code> 
  122.       from domain</code> or <code><code class="directive"><a href="../mod/mod_access.html#deny">Deny</a></code> from domain</code> 
  123.       directives (i.e., using a hostname, or a domain name, rather than
  124.       an IP address) then you will pay for
  125.       two DNS lookups (a reverse, followed by a forward lookup
  126.       to make sure that the reverse is not being spoofed). For best
  127.       performance, therefore, use IP addresses, rather than names, when
  128.       using these directives, if possible.</p>
  129.  
  130.       <p>Note that it's possible to scope the directives, such as
  131.       within a <code><Location /server-status></code> section.
  132.       In this case the DNS lookups are only performed on requests
  133.       matching the criteria. Here's an example which disables lookups
  134.       except for <code>.html</code> and <code>.cgi</code> files:</p>
  135.  
  136.       <div class="example"><p><code>
  137.         HostnameLookups off<br />
  138.         <Files ~ "\.(html|cgi)$"><br />
  139.         <span class="indent">
  140.           HostnameLookups on<br />
  141.         </span>
  142.         </Files>
  143.       </code></p></div>
  144.  
  145.       <p>But even still, if you just need DNS names in some CGIs you
  146.       could consider doing the <code>gethostbyname</code> call in the
  147.       specific CGIs that need it.</p>
  148.  
  149.     
  150.  
  151.     <h3><a name="symlinks" id="symlinks">FollowSymLinks and SymLinksIfOwnerMatch</a></h3>
  152.  
  153.       
  154.  
  155.       <p>Wherever in your URL-space you do not have an <code>Options
  156.       FollowSymLinks</code>, or you do have an <code>Options
  157.       SymLinksIfOwnerMatch</code> Apache will have to issue extra
  158.       system calls to check up on symlinks. One extra call per
  159.       filename component. For example, if you had:</p>
  160.  
  161.       <div class="example"><p><code>
  162.         DocumentRoot /www/htdocs<br />
  163.         <Directory /><br />
  164.         <span class="indent">
  165.           Options SymLinksIfOwnerMatch<br />
  166.         </span>
  167.         </Directory>
  168.       </code></p></div>
  169.  
  170.       <p>and a request is made for the URI <code>/index.html</code>.
  171.       Then Apache will perform <code>lstat(2)</code> on
  172.       <code>/www</code>, <code>/www/htdocs</code>, and
  173.       <code>/www/htdocs/index.html</code>. The results of these
  174.       <code>lstats</code> are never cached, so they will occur on
  175.       every single request. If you really desire the symlinks
  176.       security checking you can do something like this:</p>
  177.  
  178.       <div class="example"><p><code>
  179.         DocumentRoot /www/htdocs<br />
  180.         <Directory /><br />
  181.         <span class="indent">
  182.           Options FollowSymLinks<br />
  183.         </span>
  184.         </Directory><br />
  185.         <br />
  186.         <Directory /www/htdocs><br />
  187.         <span class="indent">
  188.           Options -FollowSymLinks +SymLinksIfOwnerMatch<br />
  189.         </span>
  190.         </Directory>
  191.       </code></p></div>
  192.  
  193.       <p>This at least avoids the extra checks for the
  194.       <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> path.
  195.       Note that you'll need to add similar sections if you
  196.       have any <code class="directive"><a href="../mod/mod_alias.html#alias">Alias</a></code> or
  197.       <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> paths
  198.       outside of your document root. For highest performance,
  199.       and no symlink protection, set <code>FollowSymLinks</code>
  200.       everywhere, and never set <code>SymLinksIfOwnerMatch</code>.</p>
  201.  
  202.     
  203.  
  204.     <h3><a name="htacess" id="htacess">AllowOverride</a></h3>
  205.  
  206.       
  207.  
  208.       <p>Wherever in your URL-space you allow overrides (typically
  209.       <code>.htaccess</code> files) Apache will attempt to open
  210.       <code>.htaccess</code> for each filename component. For
  211.       example,</p>
  212.  
  213.       <div class="example"><p><code>
  214.         DocumentRoot /www/htdocs<br />
  215.         <Directory /><br />
  216.         <span class="indent">
  217.           AllowOverride all<br />
  218.         </span>
  219.         </Directory>
  220.       </code></p></div>
  221.  
  222.       <p>and a request is made for the URI <code>/index.html</code>.
  223.       Then Apache will attempt to open <code>/.htaccess</code>,
  224.       <code>/www/.htaccess</code>, and
  225.       <code>/www/htdocs/.htaccess</code>. The solutions are similar
  226.       to the previous case of <code>Options FollowSymLinks</code>.
  227.       For highest performance use <code>AllowOverride None</code>
  228.       everywhere in your filesystem.</p>
  229.  
  230.     
  231.  
  232.     <h3><a name="negotiation" id="negotiation">Negotiation</a></h3>
  233.  
  234.       
  235.  
  236.       <p>If at all possible, avoid content-negotiation if you're
  237.       really interested in every last ounce of performance. In
  238.       practice the benefits of negotiation outweigh the performance
  239.       penalties. There's one case where you can speed up the server.
  240.       Instead of using a wildcard such as:</p>
  241.  
  242.       <div class="example"><p><code>
  243.         DirectoryIndex index
  244.       </code></p></div>
  245.  
  246.       <p>Use a complete list of options:</p>
  247.  
  248.       <div class="example"><p><code>
  249.         DirectoryIndex index.cgi index.pl index.shtml index.html
  250.       </code></p></div>
  251.  
  252.       <p>where you list the most common choice first.</p>
  253.  
  254.       <p>Also note that explicitly creating a <code>type-map</code>
  255.       file provides better performance than using
  256.       <code>MultiViews</code>, as the necessary information can be
  257.       determined by reading this single file, rather than having to
  258.       scan the directory for files.</p>
  259.  
  260.     <p>If your site needs content negotiation consider using
  261.     <code>type-map</code> files, rather than the <code>Options
  262.     MultiViews</code> directive to accomplish the negotiation. See the
  263.     <a href="../content-negotiation.html">Content Negotiation</a>
  264.     documentation for a full discussion of the methods of negotiation,
  265.     and instructions for creating <code>type-map</code> files.</p>
  266.  
  267.     
  268.  
  269.     <h3>Memory-mapping</h3>
  270.  
  271.       
  272.  
  273.       <p>In situations where Apache 2.x needs to look at the contents
  274.       of a file being delivered--for example, when doing server-side-include
  275.       processing--it normally memory-maps the file if the OS supports
  276.       some form of <code>mmap(2)</code>.</p>
  277.  
  278.       <p>On some platforms, this memory-mapping improves performance.
  279.       However, there are cases where memory-mapping can hurt the performance
  280.       or even the stability of the httpd:</p>
  281.  
  282.       <ul>
  283.         <li>
  284.           <p>On some operating systems, <code>mmap</code> does not scale
  285.           as well as <code>read(2)</code> when the number of CPUs increases.
  286.           On multiprocessor Solaris servers, for example, Apache 2.x sometimes
  287.           delivers server-parsed files faster when <code>mmap</code> is disabled.</p>
  288.         </li>
  289.  
  290.         <li>
  291.           <p>If you memory-map a file located on an NFS-mounted filesystem
  292.           and a process on another NFS client machine deletes or truncates
  293.           the file, your process may get a bus error the next time it tries
  294.           to access the mapped file content.</p>
  295.         </li>
  296.       </ul>
  297.  
  298.       <p>For installations where either of these factors applies, you
  299.       should use <code>EnableMMAP off</code> to disable the memory-mapping
  300.       of delivered files. (Note: This directive can be overridden on
  301.       a per-directory basis.)</p>
  302.  
  303.     
  304.  
  305.     <h3>Sendfile</h3>
  306.  
  307.       
  308.  
  309.       <p>In situations where Apache 2.x can ignore the contents of the file
  310.       to be delivered -- for example, when serving static file content -- 
  311.       it normally uses the kernel sendfile support the file if the OS 
  312.       supports the <code>sendfile(2)</code> operation.</p>
  313.  
  314.       <p>On most platforms, using sendfile improves performance by eliminating
  315.       separate read and send mechanics.  However, there are cases where using
  316.       sendfile can harm the stability of the httpd:</p>
  317.  
  318.       <ul>
  319.         <li>
  320.           <p>Some platforms may have broken sendfile support that the build
  321.           system did not detect, especially if the binaries were built on
  322.           another box and moved to such a machine with broken sendfile support.</p>
  323.         </li>
  324.         <li>
  325.           <p>With an NFS-mounted files, the kernel may be unable 
  326.           to reliably serve the network file through it's own cache.</p>
  327.         </li>
  328.       </ul>
  329.  
  330.       <p>For installations where either of these factors applies, you
  331.       should use <code>EnableSendfile off</code> to disable sendfile
  332.       delivery of file contents. (Note: This directive can be overridden 
  333.       on a per-directory basis.)</p>
  334.  
  335.     
  336.  
  337.     <h3><a name="process" id="process">Process Creation</a></h3>
  338.  
  339.       
  340.  
  341.       <p>Prior to Apache 1.3 the <code class="directive"><a href="../mod/prefork.html#minspareservers">MinSpareServers</a></code>, <code class="directive"><a href="../mod/prefork.html#maxspareservers">MaxSpareServers</a></code>, and <code class="directive"><a href="../mod/mpm_common.html#startservers">StartServers</a></code> settings all had drastic effects on
  342.       benchmark results. In particular, Apache required a "ramp-up"
  343.       period in order to reach a number of children sufficient to serve
  344.       the load being applied. After the initial spawning of
  345.       <code class="directive"><a href="../mod/mpm_common.html#startservers">StartServers</a></code> children,
  346.       only one child per second would be created to satisfy the
  347.       <code class="directive"><a href="../mod/prefork.html#minspareservers">MinSpareServers</a></code>
  348.       setting. So a server being accessed by 100 simultaneous
  349.       clients, using the default <code class="directive"><a href="../mod/mpm_common.html#startservers">StartServers</a></code> of <code>5</code> would take on
  350.       the order 95 seconds to spawn enough children to handle
  351.       the load. This works fine in practice on real-life servers,
  352.       because they aren't restarted frequently. But does really
  353.       poorly on benchmarks which might only run for ten minutes.</p>
  354.  
  355.       <p>The one-per-second rule was implemented in an effort to
  356.       avoid swamping the machine with the startup of new children. If
  357.       the machine is busy spawning children it can't service
  358.       requests. But it has such a drastic effect on the perceived
  359.       performance of Apache that it had to be replaced. As of Apache
  360.       1.3, the code will relax the one-per-second rule. It will spawn
  361.       one, wait a second, then spawn two, wait a second, then spawn
  362.       four, and it will continue exponentially until it is spawning
  363.       32 children per second. It will stop whenever it satisfies the
  364.       <code class="directive"><a href="../mod/prefork.html#minspareservers">MinSpareServers</a></code>
  365.       setting.</p>
  366.  
  367.       <p>This appears to be responsive enough that it's almost
  368.       unnecessary to twiddle the <code class="directive"><a href="../mod/prefork.html#minspareservers">MinSpareServers</a></code>, <code class="directive"><a href="../mod/prefork.html#maxspareservers">MaxSpareServers</a></code> and <code class="directive"><a href="../mod/mpm_common.html#startservers">StartServers</a></code> knobs. When more than 4 children are
  369.       spawned per second, a message will be emitted to the
  370.       <code class="directive"><a href="../mod/core.html#errorlog">ErrorLog</a></code>. If you
  371.       see a lot of these errors then consider tuning these settings.
  372.       Use the <code class="module"><a href="../mod/mod_status.html">mod_status</a></code> output as a guide.</p>
  373.  
  374.     <p>Related to process creation is process death induced by the
  375.     <code class="directive"><a href="../mod/mpm_common.html#maxrequestsperchild">MaxRequestsPerChild</a></code>
  376.     setting. By default this is <code>0</code>,
  377.     which means that there is no limit to the number of requests
  378.     handled per child. If your configuration currently has this set
  379.     to some very low number, such as <code>30</code>, you may want to bump this
  380.     up significantly. If you are running SunOS or an old version of
  381.     Solaris, limit this to <code>10000</code> or so because of memory leaks.</p>
  382.  
  383.     <p>When keep-alives are in use, children will be kept busy
  384.     doing nothing waiting for more requests on the already open
  385.     connection. The default <code class="directive"><a href="../mod/core.html#keepalivetimeout">KeepAliveTimeout</a></code> of <code>5</code>
  386.     seconds attempts to minimize this effect. The tradeoff here is
  387.     between network bandwidth and server resources. In no event
  388.     should you raise this above about <code>60</code> seconds, as <a href="http://www.research.digital.com/wrl/techreports/abstracts/95.4.html">
  389.     most of the benefits are lost</a>.</p>
  390.  
  391.     
  392.  
  393.   </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  394. <div class="section">
  395. <h2><a name="compiletime" id="compiletime">Compile-Time Configuration Issues</a></h2>
  396.  
  397.     
  398.  
  399.     <h3>Choosing an MPM</h3>
  400.  
  401.       
  402.  
  403.       <p>Apache 2.x supports pluggable concurrency models, called
  404.       <a href="../mpm.html">Multi-Processing Modules</a> (MPMs).
  405.       When building Apache, you must choose an MPM to use.  There
  406.       are platform-specific MPMs for some platforms:
  407.       <code class="module"><a href="../mod/beos.html">beos</a></code>, <code class="module"><a href="../mod/mpm_netware.html">mpm_netware</a></code>,
  408.       <code class="module"><a href="../mod/mpmt_os2.html">mpmt_os2</a></code>, and <code class="module"><a href="../mod/mpm_winnt.html">mpm_winnt</a></code>.  For
  409.       general Unix-type systems, there are several MPMs from which
  410.       to choose.  The choice of MPM can affect the speed and scalability
  411.       of the httpd:</p>
  412.  
  413.       <ul>
  414.  
  415.         <li>The <code class="module"><a href="../mod/worker.html">worker</a></code> MPM uses multiple child
  416.         processes with many threads each.  Each thread handles
  417.         one connection at a time.  Worker generally is a good
  418.         choice for high-traffic servers because it has a smaller
  419.         memory footprint than the prefork MPM.</li>
  420.  
  421.         <li>The <code class="module"><a href="../mod/prefork.html">prefork</a></code> MPM uses multiple child
  422.         processes with one thread each.  Each process handles
  423.         one connection at a time.  On many systems, prefork is
  424.         comparable in speed to worker, but it uses more memory.
  425.         Prefork's threadless design has advantages over worker
  426.         in some situations: it can be used with non-thread-safe
  427.         third-party modules, and it is easier to debug on platforms
  428.         with poor thread debugging support.</li>
  429.  
  430.       </ul>
  431.  
  432.       <p>For more information on these and other MPMs, please
  433.       see the MPM <a href="../mpm.html">documentation</a>.</p>
  434.  
  435.     
  436.  
  437.     <h3><a name="modules" id="modules">Modules</a></h3>
  438.  
  439.         
  440.  
  441.         <p>Since memory usage is such an important consideration in
  442.         performance, you should attempt to eliminate modules that you are
  443.         not actually using. If you have built the modules as <a href="../dso.html">DSOs</a>, eliminating modules is a simple
  444.         matter of commenting out the associated <code class="directive"><a href="../mod/mod_so.html#loadmodule">LoadModule</a></code> directive for that module.
  445.         This allows you to experiment with removing modules, and seeing
  446.         if your site still functions in their absense.</p>
  447.  
  448.         <p>If, on the other hand, you have modules statically linked
  449.         into your Apache binary, you will need to recompile Apache in
  450.         order to remove unwanted modules.</p>
  451.  
  452.         <p>An associated question that arises here is, of course, what
  453.         modules you need, and which ones you don't. The answer here
  454.         will, of course, vary from one web site to another. However, the
  455.         <em>minimal</em> list of modules which you can get by with tends
  456.         to include <code class="module"><a href="../mod/mod_mime.html">mod_mime</a></code>, <code class="module"><a href="../mod/mod_dir.html">mod_dir</a></code>,
  457.         and <code class="module"><a href="../mod/mod_log_config.html">mod_log_config</a></code>. <code>mod_log_config</code> is,
  458.         of course, optional, as you can run a web site without log
  459.         files. This is, however, not recommended.</p>
  460.  
  461.     
  462.  
  463.     <h3>Atomic Operations</h3>
  464.  
  465.       
  466.  
  467.       <p>Some modules, such as <code class="module"><a href="../mod/mod_cache.html">mod_cache</a></code> and
  468.       recent development builds of the worker MPM, use APR's
  469.       atomic API.  This API provides atomic operations that can
  470.       be used for lightweight thread synchronization.</p>
  471.  
  472.       <p>By default, APR implements these operations using the
  473.       most efficient mechanism available on each target
  474.       OS/CPU platform.  Many modern CPUs, for example, have
  475.       an instruction that does an atomic compare-and-swap (CAS)
  476.       operation in hardware.  On some platforms, however, APR
  477.       defaults to a slower, mutex-based implementation of the
  478.       atomic API in order to ensure compatibility with older
  479.       CPU models that lack such instructions.  If you are
  480.       building Apache for one of these platforms, and you plan
  481.       to run only on newer CPUs, you can select a faster atomic
  482.       implementation at build time by configuring Apache with
  483.       the <code>--enable-nonportable-atomics</code> option:</p>
  484.  
  485.       <div class="example"><p><code>
  486.         ./buildconf<br />
  487.         ./configure --with-mpm=worker --enable-nonportable-atomics=yes
  488.       </code></p></div>
  489.  
  490.       <p>The <code>--enable-nonportable-atomics</code> option is
  491.       relevant for the following platforms:</p>
  492.  
  493.       <ul>
  494.  
  495.         <li>Solaris on SPARC<br />
  496.             By default, APR uses mutex-based atomics on Solaris/SPARC.
  497.             If you configure with <code>--enable-nonportable-atomics</code>,
  498.             however, APR generates code that uses a SPARC v8plus opcode for
  499.             fast hardware compare-and-swap.  If you configure Apache with
  500.             this option, the atomic operations will be more efficient
  501.             (allowing for lower CPU utilization and higher concurrency),
  502.             but the resulting executable will run only on UltraSPARC
  503.             chips.
  504.         </li>
  505.  
  506.         <li>Linux on x86<br />
  507.             By default, APR uses mutex-based atomics on Linux.  If you
  508.             configure with <code>--enable-nonportable-atomics</code>,
  509.             however, APR generates code that uses a 486 opcode for fast
  510.             hardware compare-and-swap.  This will result in more efficient
  511.             atomic operations, but the resulting executable will run only
  512.             on 486 and later chips (and not on 386).
  513.         </li>
  514.  
  515.       </ul>
  516.  
  517.     
  518.  
  519.     <h3>mod_status and ExtendedStatus On</h3>
  520.  
  521.       
  522.  
  523.       <p>If you include <code class="module"><a href="../mod/mod_status.html">mod_status</a></code> and you also set
  524.       <code>ExtendedStatus On</code> when building and running
  525.       Apache, then on every request Apache will perform two calls to
  526.       <code>gettimeofday(2)</code> (or <code>times(2)</code>
  527.       depending on your operating system), and (pre-1.3) several
  528.       extra calls to <code>time(2)</code>. This is all done so that
  529.       the status report contains timing indications. For highest
  530.       performance, set <code>ExtendedStatus off</code> (which is the
  531.       default).</p>
  532.  
  533.     
  534.  
  535.     <h3>accept Serialization - multiple sockets</h3>
  536.  
  537.       
  538.  
  539.     <div class="warning"><h3>Warning:</h3>
  540.       <p>This section has not been fully updated
  541.       to take into account changes made in the 2.x version of the
  542.       Apache HTTP Server. Some of the information may still be
  543.       relevant, but please use it with care.</p>
  544.     </div>
  545.  
  546.       <p>This discusses a shortcoming in the Unix socket API. Suppose
  547.       your web server uses multiple <code class="directive"><a href="../mod/mpm_common.html#listen">Listen</a></code> statements to listen on either multiple
  548.       ports or multiple addresses. In order to test each socket
  549.       to see if a connection is ready Apache uses
  550.       <code>select(2)</code>. <code>select(2)</code> indicates that a
  551.       socket has <em>zero</em> or <em>at least one</em> connection
  552.       waiting on it. Apache's model includes multiple children, and
  553.       all the idle ones test for new connections at the same time. A
  554.       naive implementation looks something like this (these examples
  555.       do not match the code, they're contrived for pedagogical
  556.       purposes):</p>
  557.  
  558.       <div class="example"><p><code>
  559.         for (;;) {<br />
  560.         <span class="indent">
  561.           for (;;) {<br />
  562.           <span class="indent">
  563.             fd_set accept_fds;<br />
  564.             <br />
  565.             FD_ZERO (&accept_fds);<br />
  566.             for (i = first_socket; i <= last_socket; ++i) {<br />
  567.             <span class="indent">
  568.               FD_SET (i, &accept_fds);<br />
  569.             </span>
  570.             }<br />
  571.             rc = select (last_socket+1, &accept_fds, NULL, NULL, NULL);<br />
  572.             if (rc < 1) continue;<br />
  573.             new_connection = -1;<br />
  574.             for (i = first_socket; i <= last_socket; ++i) {<br />
  575.             <span class="indent">
  576.               if (FD_ISSET (i, &accept_fds)) {<br />
  577.               <span class="indent">
  578.                 new_connection = accept (i, NULL, NULL);<br />
  579.                 if (new_connection != -1) break;<br />
  580.               </span>
  581.               }<br />
  582.             </span>
  583.             }<br />
  584.             if (new_connection != -1) break;<br />
  585.           </span>
  586.           }<br />
  587.           process the new_connection;<br />
  588.         </span>
  589.         }
  590.       </code></p></div>
  591.  
  592.       <p>But this naive implementation has a serious starvation problem.
  593.       Recall that multiple children execute this loop at the same
  594.       time, and so multiple children will block at
  595.       <code>select</code> when they are in between requests. All
  596.       those blocked children will awaken and return from
  597.       <code>select</code> when a single request appears on any socket
  598.       (the number of children which awaken varies depending on the
  599.       operating system and timing issues). They will all then fall
  600.       down into the loop and try to <code>accept</code> the
  601.       connection. But only one will succeed (assuming there's still
  602.       only one connection ready), the rest will be <em>blocked</em>
  603.       in <code>accept</code>. This effectively locks those children
  604.       into serving requests from that one socket and no other
  605.       sockets, and they'll be stuck there until enough new requests
  606.       appear on that socket to wake them all up. This starvation
  607.       problem was first documented in <a href="http://bugs.apache.org/index/full/467">PR#467</a>. There
  608.       are at least two solutions.</p>
  609.  
  610.       <p>One solution is to make the sockets non-blocking. In this
  611.       case the <code>accept</code> won't block the children, and they
  612.       will be allowed to continue immediately. But this wastes CPU
  613.       time. Suppose you have ten idle children in
  614.       <code>select</code>, and one connection arrives. Then nine of
  615.       those children will wake up, try to <code>accept</code> the
  616.       connection, fail, and loop back into <code>select</code>,
  617.       accomplishing nothing. Meanwhile none of those children are
  618.       servicing requests that occurred on other sockets until they
  619.       get back up to the <code>select</code> again. Overall this
  620.       solution does not seem very fruitful unless you have as many
  621.       idle CPUs (in a multiprocessor box) as you have idle children,
  622.       not a very likely situation.</p>
  623.  
  624.       <p>Another solution, the one used by Apache, is to serialize
  625.       entry into the inner loop. The loop looks like this
  626.       (differences highlighted):</p>
  627.  
  628.       <div class="example"><p><code>
  629.         for (;;) {<br />
  630.         <span class="indent">
  631.           <strong>accept_mutex_on ();</strong><br />
  632.           for (;;) {<br />
  633.           <span class="indent">
  634.             fd_set accept_fds;<br />
  635.             <br />
  636.             FD_ZERO (&accept_fds);<br />
  637.             for (i = first_socket; i <= last_socket; ++i) {<br />
  638.             <span class="indent">
  639.               FD_SET (i, &accept_fds);<br />
  640.             </span>
  641.             }<br />
  642.             rc = select (last_socket+1, &accept_fds, NULL, NULL, NULL);<br />
  643.             if (rc < 1) continue;<br />
  644.             new_connection = -1;<br />
  645.             for (i = first_socket; i <= last_socket; ++i) {<br />
  646.             <span class="indent">
  647.               if (FD_ISSET (i, &accept_fds)) {<br />
  648.               <span class="indent">
  649.                 new_connection = accept (i, NULL, NULL);<br />
  650.                 if (new_connection != -1) break;<br />
  651.               </span>
  652.               }<br />
  653.             </span>
  654.             }<br />
  655.             if (new_connection != -1) break;<br />
  656.           </span>
  657.           }<br />
  658.           <strong>accept_mutex_off ();</strong><br />
  659.           process the new_connection;<br />
  660.         </span>
  661.         }
  662.       </code></p></div>
  663.  
  664.       <p><a id="serialize" name="serialize">The functions</a>
  665.       <code>accept_mutex_on</code> and <code>accept_mutex_off</code>
  666.       implement a mutual exclusion semaphore. Only one child can have
  667.       the mutex at any time. There are several choices for
  668.       implementing these mutexes. The choice is defined in
  669.       <code>src/conf.h</code> (pre-1.3) or
  670.       <code>src/include/ap_config.h</code> (1.3 or later). Some
  671.       architectures do not have any locking choice made, on these
  672.       architectures it is unsafe to use multiple
  673.       <code class="directive"><a href="../mod/mpm_common.html#listen">Listen</a></code>
  674.       directives.</p>
  675.  
  676.       <p>The directive <code class="directive"><a href="../mod/mpm_common.html#acceptmutex">AcceptMutex</a></code> can be used to
  677.       change the selected mutex implementation at run-time.</p>
  678.  
  679.       <dl>
  680.         <dt><code>AcceptMutex flock</code></dt>
  681.  
  682.         <dd>
  683.           <p>This method uses the <code>flock(2)</code> system call to
  684.           lock a lock file (located by the <code class="directive"><a href="../mod/mpm_common.html#lockfile">LockFile</a></code> directive).</p>
  685.         </dd>
  686.  
  687.         <dt><code>AcceptMutex fcntl</code></dt>
  688.  
  689.         <dd>
  690.           <p>This method uses the <code>fcntl(2)</code> system call to
  691.           lock a lock file (located by the <code class="directive"><a href="../mod/mpm_common.html#lockfile">LockFile</a></code> directive).</p>
  692.         </dd>
  693.  
  694.         <dt><code>AcceptMutex sysvsem</code></dt>
  695.  
  696.         <dd>
  697.           <p>(1.3 or later) This method uses SysV-style semaphores to
  698.           implement the mutex. Unfortunately SysV-style semaphores have
  699.           some bad side-effects. One is that it's possible Apache will
  700.           die without cleaning up the semaphore (see the
  701.           <code>ipcs(8)</code> man page). The other is that the
  702.           semaphore API allows for a denial of service attack by any
  703.           CGIs running under the same uid as the webserver
  704.           (<em>i.e.</em>, all CGIs, unless you use something like
  705.           <code class="program"><a href="../programs/suexec.html">suexec</a></code> or <code>cgiwrapper</code>). For these
  706.           reasons this method is not used on any architecture except
  707.           IRIX (where the previous two are prohibitively expensive
  708.           on most IRIX boxes).</p>
  709.         </dd>
  710.  
  711.         <dt><code>AcceptMutex pthread</code></dt>
  712.  
  713.         <dd>
  714.           <p>(1.3 or later) This method uses POSIX mutexes and should
  715.           work on any architecture implementing the full POSIX threads
  716.           specification, however appears to only work on Solaris (2.5
  717.           or later), and even then only in certain configurations. If
  718.           you experiment with this you should watch out for your server
  719.           hanging and not responding. Static content only servers may
  720.           work just fine.</p>
  721.         </dd>
  722.  
  723.         <dt><code>AcceptMutex posixsem</code></dt>
  724.  
  725.         <dd>
  726.           <p>(2.0 or later)  This method uses POSIX semaphores.  The
  727.           semaphore ownership is not recovered if a thread in the process
  728.           holding the mutex segfaults, resulting in a hang of the web
  729.           server.</p>
  730.         </dd>
  731.  
  732.       </dl>
  733.  
  734.       <p>If your system has another method of serialization which
  735.       isn't in the above list then it may be worthwhile adding code
  736.       for it to APR.</p>
  737.  
  738.       <p>Another solution that has been considered but never
  739.       implemented is to partially serialize the loop -- that is, let
  740.       in a certain number of processes. This would only be of
  741.       interest on multiprocessor boxes where it's possible multiple
  742.       children could run simultaneously, and the serialization
  743.       actually doesn't take advantage of the full bandwidth. This is
  744.       a possible area of future investigation, but priority remains
  745.       low because highly parallel web servers are not the norm.</p>
  746.  
  747.       <p>Ideally you should run servers without multiple
  748.       <code class="directive"><a href="../mod/mpm_common.html#listen">Listen</a></code>
  749.       statements if you want the highest performance.
  750.       But read on.</p>
  751.  
  752.     
  753.  
  754.     <h3>accept Serialization - single socket</h3>
  755.  
  756.       
  757.  
  758.       <p>The above is fine and dandy for multiple socket servers, but
  759.       what about single socket servers? In theory they shouldn't
  760.       experience any of these same problems because all children can
  761.       just block in <code>accept(2)</code> until a connection
  762.       arrives, and no starvation results. In practice this hides
  763.       almost the same "spinning" behaviour discussed above in the
  764.       non-blocking solution. The way that most TCP stacks are
  765.       implemented, the kernel actually wakes up all processes blocked
  766.       in <code>accept</code> when a single connection arrives. One of
  767.       those processes gets the connection and returns to user-space,
  768.       the rest spin in the kernel and go back to sleep when they
  769.       discover there's no connection for them. This spinning is
  770.       hidden from the user-land code, but it's there nonetheless.
  771.       This can result in the same load-spiking wasteful behaviour
  772.       that a non-blocking solution to the multiple sockets case
  773.       can.</p>
  774.  
  775.       <p>For this reason we have found that many architectures behave
  776.       more "nicely" if we serialize even the single socket case. So
  777.       this is actually the default in almost all cases. Crude
  778.       experiments under Linux (2.0.30 on a dual Pentium pro 166
  779.       w/128Mb RAM) have shown that the serialization of the single
  780.       socket case causes less than a 3% decrease in requests per
  781.       second over unserialized single-socket. But unserialized
  782.       single-socket showed an extra 100ms latency on each request.
  783.       This latency is probably a wash on long haul lines, and only an
  784.       issue on LANs. If you want to override the single socket
  785.       serialization you can define
  786.       <code>SINGLE_LISTEN_UNSERIALIZED_ACCEPT</code> and then
  787.       single-socket servers will not serialize at all.</p>
  788.  
  789.     
  790.  
  791.     <h3>Lingering Close</h3>
  792.  
  793.       
  794.  
  795.       <p>As discussed in <a href="http://www.ics.uci.edu/pub/ietf/http/draft-ietf-http-connection-00.txt">
  796.       draft-ietf-http-connection-00.txt</a> section 8, in order for
  797.       an HTTP server to <strong>reliably</strong> implement the
  798.       protocol it needs to shutdown each direction of the
  799.       communication independently (recall that a TCP connection is
  800.       bi-directional, each half is independent of the other). This
  801.       fact is often overlooked by other servers, but is correctly
  802.       implemented in Apache as of 1.2.</p>
  803.  
  804.       <p>When this feature was added to Apache it caused a flurry of
  805.       problems on various versions of Unix because of a
  806.       shortsightedness. The TCP specification does not state that the
  807.       <code>FIN_WAIT_2</code> state has a timeout, but it doesn't prohibit it.
  808.       On systems without the timeout, Apache 1.2 induces many sockets
  809.       stuck forever in the <code>FIN_WAIT_2</code> state. In many cases this
  810.       can be avoided by simply upgrading to the latest TCP/IP patches
  811.       supplied by the vendor. In cases where the vendor has never
  812.       released patches (<em>i.e.</em>, SunOS4 -- although folks with
  813.       a source license can patch it themselves) we have decided to
  814.       disable this feature.</p>
  815.  
  816.       <p>There are two ways of accomplishing this. One is the socket
  817.       option <code>SO_LINGER</code>. But as fate would have it, this
  818.       has never been implemented properly in most TCP/IP stacks. Even
  819.       on those stacks with a proper implementation (<em>i.e.</em>,
  820.       Linux 2.0.31) this method proves to be more expensive (cputime)
  821.       than the next solution.</p>
  822.  
  823.       <p>For the most part, Apache implements this in a function
  824.       called <code>lingering_close</code> (in
  825.       <code>http_main.c</code>). The function looks roughly like
  826.       this:</p>
  827.  
  828.       <div class="example"><p><code>
  829.         void lingering_close (int s)<br />
  830.         {<br />
  831.         <span class="indent">
  832.           char junk_buffer[2048];<br />
  833.           <br />
  834.           /* shutdown the sending side */<br />
  835.           shutdown (s, 1);<br />
  836.           <br />
  837.           signal (SIGALRM, lingering_death);<br />
  838.           alarm (30);<br />
  839.           <br />
  840.           for (;;) {<br />
  841.           <span class="indent">
  842.             select (s for reading, 2 second timeout);<br />
  843.             if (error) break;<br />
  844.             if (s is ready for reading) {<br />
  845.             <span class="indent">
  846.               if (read (s, junk_buffer, sizeof (junk_buffer)) <= 0) {<br />
  847.               <span class="indent">
  848.                 break;<br />
  849.               </span>
  850.               }<br />
  851.               /* just toss away whatever is here */<br />
  852.             </span>
  853.             }<br />
  854.           </span>
  855.           }<br />
  856.           <br />
  857.           close (s);<br />
  858.         </span>
  859.         }
  860.       </code></p></div>
  861.  
  862.       <p>This naturally adds some expense at the end of a connection,
  863.       but it is required for a reliable implementation. As HTTP/1.1
  864.       becomes more prevalent, and all connections are persistent,
  865.       this expense will be amortized over more requests. If you want
  866.       to play with fire and disable this feature you can define
  867.       <code>NO_LINGCLOSE</code>, but this is not recommended at all.
  868.       In particular, as HTTP/1.1 pipelined persistent connections
  869.       come into use <code>lingering_close</code> is an absolute
  870.       necessity (and <a href="http://www.w3.org/Protocols/HTTP/Performance/Pipeline.html">
  871.       pipelined connections are faster</a>, so you want to support
  872.       them).</p>
  873.  
  874.     
  875.  
  876.     <h3>Scoreboard File</h3>
  877.  
  878.       
  879.  
  880.       <p>Apache's parent and children communicate with each other
  881.       through something called the scoreboard. Ideally this should be
  882.       implemented in shared memory. For those operating systems that
  883.       we either have access to, or have been given detailed ports
  884.       for, it typically is implemented using shared memory. The rest
  885.       default to using an on-disk file. The on-disk file is not only
  886.       slow, but it is unreliable (and less featured). Peruse the
  887.       <code>src/main/conf.h</code> file for your architecture and
  888.       look for either <code>USE_MMAP_SCOREBOARD</code> or
  889.       <code>USE_SHMGET_SCOREBOARD</code>. Defining one of those two
  890.       (as well as their companions <code>HAVE_MMAP</code> and
  891.       <code>HAVE_SHMGET</code> respectively) enables the supplied
  892.       shared memory code. If your system has another type of shared
  893.       memory, edit the file <code>src/main/http_main.c</code> and add
  894.       the hooks necessary to use it in Apache. (Send us back a patch
  895.       too please.)</p>
  896.  
  897.       <div class="note">Historical note: The Linux port of Apache didn't start to
  898.       use shared memory until version 1.2 of Apache. This oversight
  899.       resulted in really poor and unreliable behaviour of earlier
  900.       versions of Apache on Linux.</div>
  901.  
  902.     
  903.  
  904.     <h3>DYNAMIC_MODULE_LIMIT</h3>
  905.  
  906.       
  907.  
  908.       <p>If you have no intention of using dynamically loaded modules
  909.       (you probably don't if you're reading this and tuning your
  910.       server for every last ounce of performance) then you should add
  911.       <code>-DDYNAMIC_MODULE_LIMIT=0</code> when building your
  912.       server. This will save RAM that's allocated only for supporting
  913.       dynamically loaded modules.</p>
  914.  
  915.     
  916.  
  917.   </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  918. <div class="section">
  919. <h2><a name="trace" id="trace">Appendix: Detailed Analysis of a Trace</a></h2>
  920.  
  921.     
  922.  
  923.     <p>Here is a system call trace of Apache 2.0.38 with the worker MPM
  924.     on Solaris 8. This trace was collected using:</p>
  925.  
  926.     <div class="example"><p><code>
  927.       truss -l -p <var>httpd_child_pid</var>.
  928.     </code></p></div>
  929.  
  930.     <p>The <code>-l</code> option tells truss to log the ID of the
  931.     LWP (lightweight process--Solaris's form of kernel-level thread)
  932.     that invokes each system call.</p>
  933.  
  934.     <p>Other systems may have different system call tracing utilities
  935.     such as <code>strace</code>, <code>ktrace</code>, or <code>par</code>.
  936.     They all produce similar output.</p>
  937.  
  938.     <p>In this trace, a client has requested a 10KB static file
  939.     from the httpd. Traces of non-static requests or requests
  940.     with content negotiation look wildly different (and quite ugly
  941.     in some cases).</p>
  942.  
  943.     <div class="example"><pre>/67:    accept(3, 0x00200BEC, 0x00200C0C, 1) (sleeping...)
  944. /67:    accept(3, 0x00200BEC, 0x00200C0C, 1)            = 9</pre></div>
  945.  
  946.     <p>In this trace, the listener thread is running within LWP #67.</p>
  947.  
  948.     <div class="note">Note the lack of <code>accept(2)</code> serialization. On this
  949.     particular platform, the worker MPM uses an unserialized accept by
  950.     default unless it is listening on multiple ports.</div>
  951.  
  952.     <div class="example"><pre>/65:    lwp_park(0x00000000, 0)                         = 0
  953. /67:    lwp_unpark(65, 1)                               = 0</pre></div>
  954.  
  955.     <p>Upon accepting the connection, the listener thread wakes up
  956.     a worker thread to do the request processing. In this trace,
  957.     the worker thread that handles the request is mapped to LWP #65.</p>
  958.  
  959.     <div class="example"><pre>/65:    getsockname(9, 0x00200BA4, 0x00200BC4, 1)       = 0</pre></div>
  960.  
  961.     <p>In order to implement virtual hosts, Apache needs to know
  962.     the local socket address used to accept the connection. It
  963.     is possible to eliminate this call in many situations (such
  964.     as when there are no virtual hosts, or when
  965.     <code class="directive"><a href="../mod/mpm_common.html#listen">Listen</a></code> directives
  966.     are used which do not have wildcard addresses). But
  967.     no effort has yet been made to do these optimizations. </p>
  968.  
  969.     <div class="example"><pre>/65:    brk(0x002170E8)                                 = 0
  970. /65:    brk(0x002190E8)                                 = 0</pre></div>
  971.  
  972.     <p>The <code>brk(2)</code> calls allocate memory from the heap.
  973.     It is rare to see these in a system call trace, because the httpd
  974.     uses custom memory allocators (<code>apr_pool</code> and
  975.     <code>apr_bucket_alloc</code>) for most request processing.
  976.     In this trace, the httpd has just been started, so it must
  977.     call <code>malloc(3)</code> to get the blocks of raw memory
  978.     with which to create the custom memory allocators.</p>
  979.  
  980.     <div class="example"><pre>/65:    fcntl(9, F_GETFL, 0x00000000)                   = 2
  981. /65:    fstat64(9, 0xFAF7B818)                          = 0
  982. /65:    getsockopt(9, 65535, 8192, 0xFAF7B918, 0xFAF7B910, 2190656) = 0
  983. /65:    fstat64(9, 0xFAF7B818)                          = 0
  984. /65:    getsockopt(9, 65535, 8192, 0xFAF7B918, 0xFAF7B914, 2190656) = 0
  985. /65:    setsockopt(9, 65535, 8192, 0xFAF7B918, 4, 2190656) = 0
  986. /65:    fcntl(9, F_SETFL, 0x00000082)                   = 0</pre></div>
  987.  
  988.     <p>Next, the worker thread puts the connection to the client (file
  989.     descriptor 9) in non-blocking mode. The <code>setsockopt(2)</code>
  990.     and <code>getsockopt(2)</code> calls are a side-effect of how
  991.     Solaris's libc handles <code>fcntl(2)</code> on sockets.</p>
  992.  
  993.     <div class="example"><pre>/65:    read(9, " G E T   / 1 0 k . h t m".., 8000)     = 97</pre></div>
  994.  
  995.     <p>The worker thread reads the request from the client.</p>
  996.  
  997.     <div class="example"><pre>/65:    stat("/var/httpd/apache/httpd-8999/htdocs/10k.html", 0xFAF7B978) = 0
  998. /65:    open("/var/httpd/apache/httpd-8999/htdocs/10k.html", O_RDONLY) = 10</pre></div>
  999.  
  1000.     <p>This httpd has been configured with <code>Options FollowSymLinks</code>
  1001.     and <code>AllowOverride None</code>.  Thus it doesn't need to
  1002.     <code>lstat(2)</code> each directory in the path leading up to the
  1003.     requested file, nor check for <code>.htaccess</code> files.
  1004.     It simply calls <code>stat(2)</code> to verify that the file:
  1005.     1) exists, and 2) is a regular file, not a directory.</p>
  1006.  
  1007.     <div class="example"><pre>/65:    sendfilev(0, 9, 0x00200F90, 2, 0xFAF7B53C)      = 10269</pre></div>
  1008.  
  1009.     <p>In this example, the httpd is able to send the HTTP response
  1010.     header and the requested file with a single <code>sendfilev(2)</code>
  1011.     system call. Sendfile semantics vary among operating systems. On some other
  1012.     systems, it is necessary to do a <code>write(2)</code> or
  1013.     <code>writev(2)</code> call to send the headers before calling
  1014.     <code>sendfile(2)</code>.</p>
  1015.  
  1016.     <div class="example"><pre>/65:    write(4, " 1 2 7 . 0 . 0 . 1   -  ".., 78)      = 78</pre></div>
  1017.  
  1018.     <p>This <code>write(2)</code> call records the request in the
  1019.     access log. Note that one thing missing from this trace is a
  1020.     <code>time(2)</code> call. Unlike Apache 1.3, Apache 2.x uses
  1021.     <code>gettimeofday(3)</code> to look up the time. On some operating
  1022.     systems, like Linux or Solaris, <code>gettimeofday</code> has an
  1023.     optimized implementation that doesn't require as much overhead
  1024.     as a typical system call.</p>
  1025.  
  1026.     <div class="example"><pre>/65:    shutdown(9, 1, 1)                               = 0
  1027. /65:    poll(0xFAF7B980, 1, 2000)                       = 1
  1028. /65:    read(9, 0xFAF7BC20, 512)                        = 0
  1029. /65:    close(9)                                        = 0</pre></div>
  1030.  
  1031.     <p>The worker thread does a lingering close of the connection.</p>
  1032.  
  1033.     <div class="example"><pre>/65:    close(10)                                       = 0
  1034. /65:    lwp_park(0x00000000, 0)         (sleeping...)</pre></div>
  1035.  
  1036.     <p>Finally the worker thread closes the file that it has just delivered
  1037.     and blocks until the listener assigns it another connection.</p>
  1038.  
  1039.     <div class="example"><pre>/67:    accept(3, 0x001FEB74, 0x001FEB94, 1) (sleeping...)</pre></div>
  1040.  
  1041.     <p>Meanwhile, the listener thread is able to accept another connection
  1042.     as soon as it has dispatched this connection to a worker thread (subject
  1043.     to some flow-control logic in the worker MPM that throttles the listener
  1044.     if all the available workers are busy).  Though it isn't apparent from
  1045.     this trace, the next <code>accept(2)</code> can (and usually does, under
  1046.     high load conditions) occur in parallel with the worker thread's handling
  1047.     of the just-accepted connection.</p>
  1048.  
  1049.   </div></div>
  1050. <div class="bottomlang">
  1051. <p><span>Available Languages: </span><a href="../en/misc/perf-tuning.html" title="English"> en </a> |
  1052. <a href="../ko/misc/perf-tuning.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
  1053. </div><div id="footer">
  1054. <p class="apache">Copyright 2007 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>
  1055. <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>
  1056. </body></html>