12

我一直在寻找几天来看看是否有人做了一个好的、有记录的、PHP 处理速度比较

  • apache-mpm-prefork 2.4 和 mod_php 5.4

  • nginx 1.2.x + PHP-FPM 5.4

为什么我在看:我看到的唯一测试是 abunt 基准测试,提供整页或类似 Hello, World 的测试,但没有关于测试内容的适当文档。我不关心请求/秒数、硬件,但我确实需要查看测试了哪些 PHP 脚本以及使用了哪些确切配置。

为什么这两个: mod_php 被认为是处理 PHP 最快的(没有静态文件,没有请求/响应测量,只处理 PHP 本身)但从那时起发生了很多变化,包括 apache 版本。Nginx 和 PHP-FPM 占用的内存要少得多,因此更改架构是一个很好的理由,但如果在这种情况下它们不够快,那么更改将是无关紧要的。

我知道如果我找不到一个我必须自己做,但我不敢相信到目前为止没有人做过这样的测试:)

4

2 回答 2

13

我已经在 CentOS 6.3 上使用 完成了这个测试nginx 1.2.7apache 2.4.3并且php 5.4.12所有编译都没有更改默认值。

./configure
make && make install

除了我启用 php-fpm 的 php

./configure --enable-fpm

所有服务器都有 100% 的默认配置,除非如下所述。所有测试都在测试服务器上完成,测试之间没有负载和重新启动。该服务器在 RAID 1 中具有 Intel(R) Xeon(R) CPU E3-1230、1GB RAM 和 2 x 60GB SSD。测试使用运行ab -n 50000 -c 500 http://127.0.0.1/test.php

测试PHP脚本:

<?php

$testing = 0;

for ($i = 0; $i < 1000; $i++) {

    $testing++;

}

echo $testing;

我还必须启用 php,nginx.conf因为默认情况下它没有启用。

location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
    include        fastcgi_params;
}

Nginx - PHP-FPM 在 127.0.0.1:9000

Concurrency Level:      500
Time taken for tests:   10.932 seconds
Complete requests:      50000
Failed requests:        336
   (Connect: 0, Receive: 0, Length: 336, Exceptions: 0)
Write errors:           0
Non-2xx responses:      336
Total transferred:      7837824 bytes
HTML transferred:       379088 bytes
Requests per second:    4573.83 [#/sec] (mean)
Time per request:       109.317 [ms] (mean)
Time per request:       0.219 [ms] (mean, across all concurrent requests)
Transfer rate:          700.17 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   34 338.5      0    7000
Processing:     0   34 166.5     23    8120
Waiting:        0   34 166.5     23    8120
Total:         13   68 409.2     23    9846

Percentage of the requests served within a certain time (ms)
  50%     23
  66%     28
  75%     32
  80%     33
  90%     34
  95%     46
  98%     61
  99%   1030
 100%   9846 (longest request)

Nginx - 通过套接字的 PHP-FPM(配置更改为 fastcgi_pass)

fastcgi_pass   unix:/var/lib/php/php.sock;

Concurrency Level:      500
Time taken for tests:   7.054 seconds
Complete requests:      50000
Failed requests:        351
   (Connect: 0, Receive: 0, Length: 351, Exceptions: 0)
Write errors:           0
Non-2xx responses:      351
Total transferred:      7846209 bytes
HTML transferred:       387083 bytes
Requests per second:    7087.70 [#/sec] (mean)
Time per request:       70.545 [ms] (mean)
Time per request:       0.141 [ms] (mean, across all concurrent requests)
Transfer rate:          1086.16 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   26 252.5      0    7001
Processing:     0   24 112.9     17    3683
Waiting:        0   24 112.9     17    3683
Total:          7   50 306.4     17    7001

Percentage of the requests served within a certain time (ms)
  50%     17
  66%     19
  75%     20
  80%     21
  90%     23
  95%     31
  98%     55
  99%   1019
 100%   7001 (longest request)

阿帕奇 - mod_php

Concurrency Level:      500
Time taken for tests:   10.979 seconds
Complete requests:      50000
Failed requests:        0
Write errors:           0
Total transferred:      9800000 bytes
HTML transferred:       200000 bytes
Requests per second:    4554.02 [#/sec] (mean)
Time per request:       109.793 [ms] (mean)
Time per request:       0.220 [ms] (mean, across all concurrent requests)
Transfer rate:          871.67 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   22 230.2      1    7006
Processing:     0   58 426.0     18    9612
Waiting:        0   58 425.9     18    9611
Total:          5   80 523.8     19   10613

Percentage of the requests served within a certain time (ms)
  50%     19
  66%     23
  75%     25
  80%     26
  90%     31
  95%     36
  98%   1012
  99%   1889
 100%  10613 (longest request)

我很乐意进一步调整 apache,但似乎 apache 跟不上。明显的赢家是带有 php-fpm via socket 的 nginx。

于 2013-02-24T11:06:33.940 回答
-4

似乎您正在比较苹果和橙子,或者更准确地说,您正在通过调整两个变量来混淆结果。当然,将 Apache+fastcgi+php-fpm 与 nginx+php-fpm 进行比较会更明智吗?您会期望 php-fpm 部分是相同的,因此您将衡量 Apache_fastcgi 与 nginx 的优势。

于 2013-11-25T23:21:27.800 回答