【问题标题】:connect time from NGINX to PHP via FastCGI通过 FastCGI 从 NGINX 连接到 PHP 的时间
【发布时间】:2011-03-13 20:07:58
【问题描述】:

这是一个具有 32GB 内存的六核。我有 nginx 0.7.X 和 php5-fpm 和 php5.3(来自 dotdeb.org)。重要的配置文件:

nginx.conf

user www-data;
worker_processes 2;
events {
    worker_connections 4096;
}
location ~ \.php$ {
                fastcgi_pass   unix:/tmp/fcgi.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
                include fastcgi_params;
}

php5-fpm.conf

<value name="listen_address">/tmp/fcgi.sock</value>
<value name="max_children">1500</value>
<value name="max_requests">5000</value>

就是这样。使用 apache bench (ab -n 1000 -c 1000 http://url..。) 我可以在 250 毫秒内为 1000 个并发连接请求一个静态文件(大小为 10kB)。

Document Path:          /inc/helper-swf.js
Document Length:        10217 bytes

Concurrency Level:      1000
Time taken for tests:   0.278 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      10448124 bytes
HTML transferred:       10219896 bytes
Requests per second:    3600.30 [#/sec] (mean)
Time per request:       277.755 [ms] (mean)
Time per request:       0.278 [ms] (mean, across all concurrent requests)
Transfer rate:          36734.70 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   27  11.1     30      41
Processing:    16  101  57.1    102     215
Waiting:       15  101  57.1    101     215
Total:         28  128  56.5    136     235

Percentage of the requests served within a certain time (ms)
  50%    136
  66%    167
  75%    178
  80%    184
  90%    198
  95%    205
  98%    220
  99%    228
 100%    235 (longest request)

但是当请求转到一个 php 文件时,这需要 500 毫秒??? php什么都不做,文件的第一行是一个die();

Document Path:          /test.php
Document Length:        0 bytes

Concurrency Level:      1000
Time taken for tests:   0.501 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      158000 bytes
HTML transferred:       0 bytes
Requests per second:    1996.99 [#/sec] (mean)
Time per request:       500.754 [ms] (mean)
Time per request:       0.501 [ms] (mean, across all concurrent requests)
Transfer rate:          308.13 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   28   9.5     29      41
Processing:    15  365 117.4    395     448
Waiting:       15  363 117.1    393     448
Total:         27  393 122.9    425     480

Percentage of the requests served within a certain time (ms)
  50%    425
  66%    434
  75%    471
  80%    472
  90%    473
  95%    474
  98%    479
  99%    479
 100%    480 (longest request)

访问php文件时没有内容要传输,只有一个从nginx到php5-fpm的upstream通过socket(tcp耗时800ms,1000个并发连接)。有什么问题? 日志中没有提示。打开文件限制为 32768。有没有办法从 php-fpm 调整响应时间?

【问题讨论】:

    标签: php performance request nginx fastcgi


    【解决方案1】:

    fastcgi 还加载 PHP 实例。如果您的 PHP 充满了脂肪(您不需要的扩展),那么结果就是:每个请求的次数更高。

    我的建议是:

    • 仅使用您正在使用的扩展重新编译 PHP
    • 安装 APC
    • 增加缓冲区大小

    【讨论】:

    • 可能也值得将 php 编译为静态二进制文件 - ez.no/developer/blog/php_as_dso_or_as_static_php_module
    • 您好,感谢您的回复。 PHP 是从 dotdeb.org 存储库安装的。因为我们喜欢自动安装服务器,所以我不喜欢自己构建它。 APC 已经安装,性能提高了 20%。你的意思是什么类型的缓冲区? FastCGI 缓冲区?
    • 您可以像安装它们一样卸载不需要的 PHP 库apt-get remove php5-gd php5-mysql php5-memcache ...
    猜你喜欢
    • 1970-01-01
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    • 2010-12-02
    相关资源
    最近更新 更多