为什么 Apache 说有 49 名闲置工人,而实际上应该只有 10 名?

为什么 Apache 说有 49 名闲置工人,而实际上应该只有 10 名?

我已启用 apache mod_status 模块,同时还启用了 ExtendedStatus。由于我将服务器状态配置为仅在本地运行:

// httpd.conf
<Location /server-status>
  SetHandler server-status
  Order deny,allow
  Deny from all
  Allow from 127.0.0.1 ::1
</Location>

我使用 lynx 来连接它:

lynx http://localhost/server-status

这是输出:

   Server Version: Apache/2.2.22 (Ubuntu)
   Server Built: Mar 19 2014 21:10:46
     ________________________________________________________________________________________________________________________

   Current Time: Sunday, 04-May-2014 23:13:58 EDT
   Restart Time: Sunday, 04-May-2014 23:13:35 EDT
   Parent Server Generation: 0
   Server uptime: 23 seconds
   Total accesses: 0 - Total Traffic: 0 kB
   CPU Usage: u0 s0 cu0 cs0
   0 requests/sec - 0 B/second -
   1 requests currently being processed, 49 idle workers

_________________________.......................................
_____W___________________.......................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................

   Scoreboard Key:
   "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
   "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
   "C" Closing connection, "L" Logging, "G" Gracefully finishing,
   "I" Idle cleanup of worker, "." Open slot with no current process

   Srv PID   Acc  M CPU  SS    Req    Conn Child Slot  Client     VHost             Request
   1-0 8658 0/0/0 W 0.00 0  899699703 0.0  0.00  0.00 127.0.0.1 127.0.1.1 GET /server-status HTTP/1.0
     ________________________________________________________________________________________________________________________

    Srv  Child Server number - generation
    PID  OS process ID
    Acc  Number of accesses this connection / this child / this slot
     M   Mode of operation
    CPU  CPU usage, number of seconds
    SS   Seconds since beginning of most recent request
    Req  Milliseconds required to process most recent request

嗯?上面说有 49 个空闲工作进程?但是如果你看一下 apache2.conf 中的 mpm prefork 配置:

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

它说从 5 个生成的子进程开始,留下 5 个挂起。因此,总共应该有 10 个 Apache 进程。这个 49 是从哪里来的?

答案1

如果你已经知道这一点,我很抱歉,但需要明确的是,Min 和 MaxSpareServers 是建议空闲工作进程的数量。Apache 可以并且会高于或低于这些配置值。MaxClients 是一个死限制,在 mpm_prefork 的情况下是分叉工作进程的限制。

至于为什么有 49 个空闲工作进程,Apache 应该只响应客户端负载。如果这是最近重新启动的服务器,那么在启动时一定有什么东西占用了工作进程。如果它最近没有重新启动,那么 Apache 将调整其空闲工作进程的长期目标,目前可能在 50 左右。可能还有其他原因,这取决于您的配置……

相关内容