使用HipHop for PHP进行Apache基准测试

5

最近我用Apache Benchmark (ab)对HipHop for PHP进行了基准测试。

我期望HipHop for PHP的结果比普通的apache2 web服务器更快,但事实证明并非如此。

我使用这个脚本来测试服务器:

<?php
  $i=0;
  while($i < 1000000){
    echo 'Welcome to HipHop for PHP<br />';
    $i++;
  }
?>

我使用ab命令进行基准测试:

ab -n 500 -c 5 [URL]

我使用以下命令进行编译:

hphp/hphp hiphop1.php -k 1 -l 3

Apache2服务器的基准测试结果为:

kiddo@kiddo-VirtualBox:~/dev/hiphop-php/doc$ ab -n 500 -c 5 http://localhost/hiphop1.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests


Server Software:        Apache/2.2.16
Server Hostname:        localhost
Server Port:            80

Document Path:          /hiphop1.php
Document Length:        31000000 bytes

Concurrency Level:      5
Time taken for tests:   71.024 seconds
Complete requests:      500
Failed requests:        0
Write errors:           0
Total transferred:      15500095500 bytes
HTML transferred:       15500000000 bytes
Requests per second:    7.04 [#/sec] (mean)
Time per request:       710.240 [ms] (mean)
Time per request:       142.048 [ms] (mean, across all concurrent requests)
Transfer rate:          213122.37 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.9      0      19
Processing:   505  708  61.1    694     960
Waiting:        0    0   3.3      0      67
Total:        505  708  61.1    695     960

Percentage of the requests served within a certain time (ms)
  50%    695
  66%    714
  75%    729
  80%    736
  90%    781
  95%    857
  98%    898
  99%    938
 100%    960 (longest request)

同时,HipHop for PHP 的基准也在不断提高:

kiddo@kiddo-VirtualBox:~/dev/hiphop-php/doc$ ab -n 500 -c 5 http://localhost:8080/hiphop1.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests


Server Software:        
Server Hostname:        localhost
Server Port:            8080

Document Path:          /hiphop1.php
Document Length:        31000000 bytes

Concurrency Level:      5
Time taken for tests:   294.546 seconds
Complete requests:      500
Failed requests:        0
Write errors:           0
Total transferred:      15500052500 bytes
HTML transferred:       15500000000 bytes
Requests per second:    1.70 [#/sec] (mean)
Time per request:       2945.455 [ms] (mean)
Time per request:       589.091 [ms] (mean, across all concurrent requests)
Transfer rate:          51390.26 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.6      0      20
Processing:  1515 2941 579.7   2919    4734
Waiting:     1452 2626 532.5   2609    4135
Total:       1515 2941 579.7   2919    4734

Percentage of the requests served within a certain time (ms)
  50%   2919
  66%   3147
  75%   3334
  80%   3448
  90%   3704
  95%   3937
  98%   4223
  99%   4394
 100%   4734 (longest request)

问题是,为什么我的基准测试中HipHop运行速度较慢?脚本测试有问题吗?

服务器(特别是输出缓冲区)可能配置不同。如果缓冲区太小,则需要更多的输入/输出操作。 - LazyOne
7
你的测试代码与典型的Web应用程序工作量相差甚远。现代Web应用程序将执行大量对象实例化、数据库I/O、用户输入处理等操作。你的所有代码只是在测试循环和文本输出。在典型的真实世界使用情况下,HipHop可能会更快,但在一两个非常特定的情况下可能会更慢。 - GordonM
1
有关基准测试Web应用程序的任何建议?特别是针对PHP的HipHop?我不知道如何为基准测试Web服务器制作测试用例。 - Kiddo
我通过使用来自PHP官方开发存储库的bench.php获得了想要的结果。我使用ab进行基准测试,但我只得到了执行时间。如何获取CPU和内存使用情况? - Kiddo
你可以使用脚本获取CPU负载。 - Mascarpone
我也不会在被测试应用程序的同一台机器上运行基准测试。 - Stephen Melrose
1个回答

3
有一个普遍的误解,即PHP hip-hop可以加速PHP代码执行。实际上并不一定如此。Facebook开发这个工具是因为他们的整个平台都建立在几个PHP文件上,而这些文件被频繁地执行且非常庞大,使用纯PHP会效率低下。
使用Hip-Hop只是在PHP执行中添加了一个步骤,你不应该将PHP Hip-Hop用于像那样“简单”的代码。
此外,PHP执行一些本来由C++原生执行的函数,但是使用了PHP脚本。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接