阿帕奇瓶颈

阿帕奇瓶颈

我有 nginx 作为前端代理,并使用 mod_fcgid 的 apache。

这个盒子有 24GB RAM 和 16 个核心。我不应该遇到瓶颈。

似乎存在瓶颈。一旦达到 7000 个请求,它就会挂起,然后才能继续。

编辑 3:有人能解释一下PHP_FCGI_CHILDREN吗?我将其设置为 1,效果似乎更好。设置得越高越好吗?它确实跨越了很多过程,就像它越高一样。

编辑:错误日志明智:

(104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server

编辑 - 问题 2 因为我使用 nginx 作为前端代理。我是否可能用尽了所有端口,因此无法再发送到后端(apache)?我还注意到 PHP 进程死机很快

16409 USER 20   0     0    0    0 Z 27.2  0.0   0:00.82 [php] <defunct>

即使这样,它也会失败:

/usr/local/apache/bin/ab -n 1000000 -c 10 http://IP/index.php
apr_poll: The timeout specified has expired (70007)
Total of 23998 requests completed

我的结果:

/usr/local/apache/bin/ab -n 10000 -c 100 http:///index.php

Document Path:          /index.php
Document Length:        55764 bytes

Concurrency Level:      100
Time taken for tests:   52.076 seconds
Complete requests:      10000
Failed requests:        17
   (Connect: 0, Receive: 0, Length: 17, Exceptions: 0)
Write errors:           0
Non-2xx responses:      17
Total transferred:      558563436 bytes
HTML transferred:       556703249 bytes
Requests per second:    192.03 [#/sec] (mean)
Time per request:       520.764 [ms] (mean)
Time per request:       5.208 [ms] (mean, across all concurrent requests)
Transfer rate:          10474.46 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.4      0       6
Processing:     3  436 3978.0      3   52069
Waiting:        2  436 3978.0      3   52069
Total:          3  436 3978.1      3   52073

Percentage of the requests served within a certain time (ms)
  50%      3
  66%      4
  75%      4
  80%      4
  90%      5
  95%      5
  98%   1018
  99%  29055
 100%  52073 (longest request)

/etc/sysctl.conf

net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.tcp_fin_timeout = 25
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_fack = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.tcp_reordering = 5
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 3
net.ipv4.tcp_max_syn_backlog = 2048
net.core.netdev_max_backlog = 1024
net.core.hot_list_length = 256
net.ipv4.tcp_max_tw_buckets = 360000
net.core.rmem_default = 65535
net.core.rmem_max = 8388608
net.ipv4.tcp_rmem = 4096 87380 8388608
net.core.wmem_default = 65535
net.core.wmem_max = 8388608
net.ipv4.tcp_wmem = 4096 65535 8388608
net.ipv4.tcp_mem = 8388608 8388608 8388608
net.core.optmem_max = 40960
net.ipv4.netfilter.ip_conntrack_max = 32768
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 0
net.ipv4.tcp_orphan_retries = 1
net.ipv4.tcp_fin_timeout = 25
net.ipv4.tcp_max_orphans = 8192
net.ipv4.ip_local_port_range = 2768    61000
fs.file-max = 209708

在 /usr/local/cpanel/cgi-sys/php5

export PHP_FCGI_CHILDREN=0
exec /usr/bin/php

/usr/local/apache/conf/php.conf

LoadModule fcgid_module modules/mod_fcgid.so
MaxRequestsPerProcess 1000
FcgidMaxProcesses 200
FcgidProcessLifeTime 3600
MaxProcessCount 200
FcgidIOTimeout 2000
FcgidIdleTimeout 60
FcgidIdleScanInterval 30
FcgidBusyTimeout 300
FcgidBusyScanInterval 80
ErrorScanInterval 3
ZombieScanInterval 3
FcgidMinProcessesPerClass 5
FcgidMaxProcessesPerClass 150
DefaultMinClassProcessCount 5
DefaultMaxClassProcessCount 150
IPCCommTimeout 40
IPCConnectTimeout 10
MaxRequestLen 1073741824
AddHandler fcgid-script .php5 .php4 .php .php3 .php2 .phtml
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php5
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php4
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php3
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .php2
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .phtml

阿帕奇

Timeout 5
TraceEnable Off
ServerSignature Off
ServerTokens ProductOnly
FileETag None
StartServers 15
<IfModule prefork.c>
MinSpareServers 5
MaxSpareServers 10
</IfModule>
ServerLimit 256
MaxClients 150
MaxRequestsPerChild 1000
KeepAlive Off
KeepAliveTimeout 1
MaxKeepAliveRequests 1

httpd-V

Server version: Apache/2.2.23 (Unix)
Server built:   Jan 29 2013 11:18:48
Cpanel::Easy::Apache v3.16.7 rev9999
Server's Module Magic Number: 20051115:31
Server loaded:  APR 1.4.6, APR-Util 1.4.1
Compiled using: APR 1.4.6, APR-Util 1.4.1
Architecture:   64-bit
Server MPM:     Event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/experimental/event"
 -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 APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/usr/local/apache"
 -D SUEXEC_BIN="/usr/local/apache/bin/suexec"
 -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"

nginx 错误日志

2013/02/06 18:12:50 [notice] 15123#0: signal 17 (SIGCHLD) received
2013/02/06 18:12:50 [notice] 15123#0: worker process 15127 exited with code 0
2013/02/06 18:12:50 [notice] 15123#0: worker process 15128 exited with code 0
2013/02/06 18:12:50 [notice] 15123#0: worker process 15129 exited with code 0
2013/02/06 18:12:50 [notice] 15123#0: worker process 15131 exited with code 0
2013/02/06 18:12:50 [notice] 15123#0: worker process 15137 exited with code 0
2013/02/06 18:12:50 [notice] 15123#0: worker process 15139 exited with code 0
2013/02/06 18:12:50 [notice] 15123#0: signal 29 (SIGIO) received
2013/02/06 18:12:50 [notice] 15123#0: signal 17 (SIGCHLD) received
2013/02/06 18:12:50 [notice] 15123#0: worker process 15124 exited with code 0
2013/02/06 18:12:50 [notice] 15123#0: signal 29 (SIGIO) received
2013/02/06 18:12:50 [notice] 15123#0: signal 17 (SIGCHLD) received
2013/02/06 18:12:50 [notice] 15123#0: worker process 15136 exited with code 0
2013/02/06 18:12:50 [notice] 15123#0: signal 29 (SIGIO) received
2013/02/06 18:12:50 [notice] 15123#0: signal 17 (SIGCHLD) received
2013/02/06 18:12:50 [notice] 15123#0: worker process 15125 exited with code 0
2013/02/06 18:12:50 [notice] 15123#0: signal 29 (SIGIO) received
2013/02/06 18:12:50 [notice] 15123#0: signal 17 (SIGCHLD) received
2013/02/06 18:12:50 [notice] 15123#0: worker process 15130 exited with code 0
2013/02/06 18:12:50 [notice] 15123#0: signal 29 (SIGIO) received

答案1

如果您已经使用 ngix 作为反向代理,并且我假设它也用于提供静态文件,那么mod_fcgi只是一个复杂的事情 - 只需使用 apachemod_php和相当高的maxclientsserverlimit(例如 1024)。

答案2

您是否在服务器上的独立机器上运行基准测试?服务器上的网络链接速度是多少?您可能已将网络带宽用到最大限度。

Transfer rate:          10474.46 [Kbytes/sec] received

这看起来像是 10MB/s

答案3

5 秒内服务的请求百分比为 95%,然后突然跳升至 1018 秒,服务器仅为 98%。还可能发生您的 Apache 超时设置为 5 秒的情况。我认为 Apache 的默认超时值通常默认设置为大于 120 秒。您将其设置为 5 秒有什么原因吗?您是否考虑过增加它?

 95%      5
 98%   1018

相关内容