Apache2
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); ?>
阿帕奇版本資訊:
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
處理第一個請求,完成後處理接下來的五個請求,然後處理剩餘的請求,很容易看出批處理之間的延遲是由於程序仍然被 sleep 命令保持打開狀態。
更改配置後,我確實重新啟動了 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
我該如何解決這個問題/我的配置哪裡出錯了?
經過大量的研究和調試,我終於找到了原因。
php-fpm.bin
工人一次被限制為 5 個。pm.max_children
在相應的配置文件中增加一個更高的數字解決了這個問題。