apache2 mpm_event 对配置更改没有反应

apache2 mpm_event 对配置更改没有反应

我想增加并行打开的连接数量(阅读:服务器收到了请求,但需要时间处理才能回答,客户端正在等待我编写了一个测试php脚本来测试我是否达到了托管在apache2实例上的目标:

<?php
$time = new DateTime();
echo date_timestamp_get($time);
echo "<br>Hello World";
sleep(20);
echo "<br>bye world<br>";
$time = new DateTime();
echo date_timestamp_get($time);
?>

Apache 版本信息:

apachectl -V
Server version: Apache/2.4.23 (Unix)
Server built:   Oct 17 2016 11:09:09
Server's Module Magic Number: 20120211:61
Server loaded:  APR 1.5.2, APR-UTIL 1.5.4
Compiled using: APR 1.5.2, APR-UTIL 1.5.4
Architecture:   64-bit
Server MPM:     event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/bitnami/lampstack-linux-x64/output/apache2"
 -D SUEXEC_BIN="/bitnami/lampstack-linux-x64/output/apache2/bin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

加载的模块有:

Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 socache_shmcb_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 substitute_module (shared)
 deflate_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 unique_id_module (shared)
 setenvif_module (shared)
 version_module (shared)
 proxy_module (shared)
 proxy_connect_module (shared)
 proxy_ftp_module (shared)
 proxy_http_module (shared)
 proxy_fcgi_module (shared)
 proxy_scgi_module (shared)
 proxy_wstunnel_module (shared)
 proxy_ajp_module (shared)
 proxy_balancer_module (shared)
 proxy_express_module (shared)
 slotmem_shm_module (shared)
 ssl_module (shared)
 lbmethod_byrequests_module (shared)
 lbmethod_bytraffic_module (shared)
 lbmethod_bybusyness_module (shared)
 mpm_event_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 negotiation_module (shared)
 dir_module (shared)
 actions_module (shared)
 alias_module (shared)
 rewrite_module (shared)

与mpm模块相关的配置httpd.conf为:

LoadModule mpm_event_module modules/mod_mpm_event.so
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
[...]
<IfModule mpm_prefork_module>
  StartServers    20
  MinSpareServers 20
  MaxSpareServers 20
  <IfVersion >= 2.3>
    MaxRequestWorkers       20
    MaxConnectionsPerChild  5000
  </IfVersion>
  <IfVersion < 2.3 >
    MaxClients              20
    MaxRequestsPerChild     5000
  </IfVersion>
  KeepAliveTimeout 1
</IfModule>

<IfModule mpm_event_module>
  ServerLimit               15
  StartServers              15
  MinSpareThreads         128
  MaxSpareThreads         192
  ThreadsPerChild          64
  MaxRequestWorkers       256
  MaxConnectionsPerChild 5000
  KeepAliveTimeout          2
</IfModule>

我在浏览器中(手动)运行了 8 个请求来访问测试脚本,并期望输出access.log显示所有请求都在几秒钟内完成。但日志的输出显示了不同的情况:

192.168.56.1 - - [16/Aug/2017:21:00:43 +0000] "GET /test.php HTTP/1.1" 200 58
192.168.56.1 - - [16/Aug/2017:21:01:03 +0000] "GET /test.php HTTP/1.1" 200 58
192.168.56.1 - - [16/Aug/2017:21:01:05 +0000] "GET /test.php HTTP/1.1" 200 58
192.168.56.1 - - [16/Aug/2017:21:01:05 +0000] "GET /test.php HTTP/1.1" 200 58
192.168.56.1 - - [16/Aug/2017:21:01:06 +0000] "GET /test.php HTTP/1.1" 200 58
192.168.56.1 - - [16/Aug/2017:21:01:07 +0000] "GET /test.php HTTP/1.1" 200 58
192.168.56.1 - - [16/Aug/2017:21:01:23 +0000] "GET /test.php HTTP/1.1" 200 59
192.168.56.1 - - [16/Aug/2017:21:01:25 +0000] "GET /test.php HTTP/1.1" 200 59

我的浏览器中的输出与access.log输出相匹配:

1.
1502917243
Hello World
bye world
1502917263

2.
1502917263
Hello World
bye world
1502917283

3.
1502917265
Hello World
bye world
1502917285

4.
1502917265
Hello World
bye world
1502917286

5.
1502917266
Hello World
bye world
1502917286

6.
1502917267
Hello World
bye world
1502917287

7.
1502917283
Hello World
bye world
1502917303

8.
1502917285
Hello World
bye world
1502917305

第一个请求被处理后,接下来的五个请求也被处理,然后剩下的请求也被处理,很容易看出批次之间的延迟是由于进程仍然被睡眠命令保持打开状态。

做过更改配置后重新启动 apache 服务。我做过更改配置后重新启动整个机器。 这两个操作都没有导致不同的结果,所以我的理论是我没有正确进行配置。

使用top列出活动进程并使用过滤COMMAND=httpd.bin显示下图:

 1298 root      20   0  136508   4624   2876 S  0.0  0.5   0:00.15 httpd.bin                                                                                                                                                                                                                                                                                                                                                           
 1347 daemon    20   0  876188   7192   2412 S  0.0  0.7   0:00.61 httpd.bin                                                                                                                                                                                                                                                                                                                                                           
 1348 daemon    20   0  876188   6956   2260 S  0.0  0.7   0:00.61 httpd.bin                                                                                                                                                                                                                                                                                                                                                           
 1349 daemon    20   0 1072796   7364   2416 S  0.0  0.7   0:00.62 httpd.bin  

我该如何修复这个问题/我的配置哪里出错了?

答案1

经过大量的研究和调试,我终于找到了原因。workerphp-fpm.bin一次最多只能有 5 个。pm.max_children在相应的配置文件中增加到更高的数字可以解决问题。

相关内容