PHP生成页面,但不会立即将它们返回给用户

And*_*rew 6 php apache

我正在测试我正在整理的服务器设置的负载能力.apache2服务器上安装了PHP 5.X,它连接到单独机器上的主数据库,然后连接到2个从服务器中的1个来进行读取.

如果我自己调用它,我的测试页面需要0.2秒生成.我在另一台服务器上创建了一个php脚本,它可以同时调用65个测试页面.测试页面在整个页面中使用微量基准测试,让我知道每个部分需要多长时间.正如预期的那样 - 至少对我来说,如果有人对此有任何意见或建议,请随意评论 - 页面的SQL部分需要很短的时间来收到它接收的第一对请求然后降级,因为其余的查询堆积起来,必须等待.我认为它可能是磁盘IO问题,但在固态驱动器上进行测试时会出现相同的行为.

我的问题是创建了大约30个左右的65页,并按照我的预期由我的测试脚本加载.我的基准测试表示该页面是在3秒内创建的,我的测试脚本表示它在3.1秒内完全收到了该页面.差别并不大.问题是,对于其他请求,我的基准测试表示页面在3秒内加载,但测试脚本在6秒内没有完全收到页面.这是由apache服务器生成的页面之间的完整3秒,并发送回我请求它的测试脚本.为了确保它不是测试脚本的问题,我尝试在运行时在本地浏览器中加载页面,并通过Chrome中的时间线窗口确认相同的延迟.

我已经为Apache尝试了各种配置,但似乎无法找到造成这种延迟的原因.我最近的尝试如下.该机器是四核AMD 2.8Ghz,配备2Ghz Ram.任何有关配置的帮助,或其他建议,将不胜感激. - 很抱歉这个问题很长.

我应该提一下,我在脚本运行时监视资源,并且CPU达到最大9%的负载并且总是至少有1 GB的ram free.

我还要提到,当我查询的所有内容都是静态HTML页面时,会发生相同类型的事情.第一对夫妇需要.X秒,然后慢慢升至3秒.

LockFile ${APACHE_LOCK_DIR}/accept.lock
PidFile ${APACHE_PID_FILE}
Timeout 120
MaxClients            150
KeepAlive On
KeepAliveTimeout 4
MaxKeepAliveRequests 150

Header always append x-frame-options sameorigin

    StartServers         50
    MinSpareServers      25
    MaxSpareServers      50
    MaxClients          150
    MaxRequestsPerChild   0


User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
AccessFileName .httpdoverride

    Order allow,deny
DefaultType text/plain
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
Include mods-enabled/*.load
Include mods-enabled/*.conf
Include httpd.conf
Include ports.conf

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
Include conf.d/
Include sites-enabled/
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps



    SecRuleEngine On
    SecRequestBodyAccess On
    SecResponseBodyAccess Off
    SecUploadKeepFiles Off
    SecDebugLog /var/log/apache2/modsec_debug.log
    SecDebugLogLevel 0
    SecAuditEngine RelevantOnly
    SecAuditLogRelevantStatus ^5
    SecAuditLogParts ABIFHZ
    SecAuditLogType Serial
    SecAuditLog /var/log/apache2/modsec_audit.log
    SecRequestBodyLimit 131072000
    SecRequestBodyInMemoryLimit 131072
    SecResponseBodyLimit 524288000
        ServerTokens Full
        SecServerSignature "Microsoft-IIS/5.0"

更新:似乎很多回应都集中在SQL是罪魁祸首的事实上.所以我在这里说明在静态HTML页面上发生相同的行为.基准测试的结果如下所示.

Concurrency Level:      10
Time taken for tests:   5.453 seconds
Complete requests:      1000
Failed requests:        899
   (Connect: 0, Receive: 0, Length: 899, Exceptions: 0)
Write errors:           0
Total transferred:      290877 bytes
HTML transferred:       55877 bytes
Requests per second:    183.38 [#/sec] (mean)
Time per request:       54.531 [ms] (mean)
Time per request:       5.453 [ms] (mean, across all concurrent requests)
Transfer rate:          52.09 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   21 250.7      0    3005
Processing:    16   33  17.8     27     138
Waiting:       16   33  17.8     27     138
Total:         16   54 253.0     27    3078

Percentage of the requests served within a certain time (ms)
  50%     27
  66%     36
  75%     42
  80%     46
  90%     58
  95%     71
  98%     90
  99%    130
 100%   3078 (longest request)

我还要说明我通过使用PHP和microtime()确定在生成页面之前发生滞后.我通过生成页面和接收它的测试脚本之间的时间差来确定这一点.差异是一致的意味着从生成页面到我的测试页面收到它的时间点无论整个请求花了多长时间,都是相同的.

感谢所有回复的人.一切都很好,我只是不能说他们中的任何一个都解决了这个问题.

pro*_*eek 1

投放前加载的确切页面数是多少?您提到您正在从单个外部脚本创建 65 个并发请求。你没有启用像 limitipconn 这样的 mod 来限制来自单个 IP 的 N 个连接或其他东西吗?是否总是恰好有 30 个(或其他)连接然后延迟?