簡體   English   中英

通過FastCGI將時間從NGINX連接到PHP

[英]connect time from NGINX to PHP via FastCGI

這是一款帶有32GB內存的六核。 我使用php5.3(來自dotdeb.org)獲得nginx 0.7.X和php5-fpm。 重要的配置文件:

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 .. )我可以在250ms內為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的上游通過套接字(tcp占用800ms,1000個並發連接)。 有什么問題? 日志中沒有提示。 打開文件限制是32768.有沒有辦法調整php-fpm的響應時間?

fastcgi也加載了PHP實例。 如果您的PHP充滿了胖(您不需要擴展),那么結果就是:每個請求的時間更長。

我的建議是:

  • 僅使用您正在使用的擴展重新編譯PHP
  • 安裝APC
  • 增加緩沖區大小

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM