Aug
21
Posted (xurenlu) in php性能, php技术 on 08月-21-2007

我的师兄,从某种程度上说也是我php方面的师父,和他的同事做了测评,分别是针对php4,php5的性能对比和function,class的性能对比的。
这里是师兄的对比结果
师兄的同事做的测评
但是我不认为用ab来做出的测试是合理的.理由:用ab来测试时,结果好像总似是在跳舞一样.做为证据,我将我的notebook依文本方式重启,用ab来测lighttpd的表现.
具体环境:
Haier H40S Notebook
RAM:1.5G
CPU:CY 1.6GHz
硬盘:60G,(具体型号什么的不清楚,列个60G表示不是SCSI硬盘)
OS:Fedora Core 7.0(Moonshine)
web server:lighttpd 1.4.15
测试工具:ab
X环境:未运行X server
命令:ab -n 10000 -c 50 http://localhost:8181/
第一份结果:

  1. This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
  2. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  3. Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)

Server Software: lighttpd/1.4.15
Server Hostname: localhost
Server Port: 8181

Document Path: /
Document Length: 345 bytes

Concurrency Level: 50
Time taken for tests: 1.786830 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Non-2xx responses: 10000
Total transferred: 4980000 bytes
HTML transferred: 3450000 bytes
Requests per second: 5596.50 [#/sec] (mean)
Time per request: 8.934 [ms] (mean)
Time per request: 0.179 [ms] (mean, across all concurrent requests)
Transfer rate: 2721.58 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 2.6 4 8
Processing: 1 4 0.7 5 6
Waiting: 0 1 1.7 2 5
Total: 5 8 2.2 8 13
WARNING: The median and mean for the processing time are not within a normal deviation
These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
50% 8
66% 10
75% 10
80% 11
90% 11
95% 12
98% 12
99% 12
100% 13 (longest request)

这里的结果是Requests per second: 5596.50 [#/sec] (mean)(插一句,lighttpd的性能真是好,用apache从来没上过3000)
第二份ab -n 10000 -c 50的结果:

  1. This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
  2. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  3. Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)

Server Software: lighttpd/1.4.15
Server Hostname: localhost
Server Port: 8181

Document Path: /
Document Length: 345 bytes

Concurrency Level: 50
Time taken for tests: 1.313719 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Non-2xx responses: 10011
Total transferred: 4985478 bytes
HTML transferred: 3453795 bytes
Requests per second: 7611.98 [#/sec] (mean)
Time per request: 6.569 [ms] (mean)
Time per request: 0.131 [ms] (mean, across all concurrent requests)
Transfer rate: 3705.51 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.0 1 5
Processing: 1 5 2.0 5 32
Waiting: 0 3 1.8 3 30
Total: 1 6 2.1 6 35

Percentage of the requests served within a certain time (ms)
50% 6
66% 6
75% 6
80% 6
90% 7
95% 8
98% 10
99% 11
100% 35 (longest request)

结果表明RPS是Requests per second: 7611.98 [#/sec] (mean).
第三份结果:

  1. This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
  2. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  3. Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)

Server Software: lighttpd/1.4.15
Server Hostname: localhost
Server Port: 8181

Document Path: /
Document Length: 345 bytes

Concurrency Level: 50
Time taken for tests: 1.300247 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Non-2xx responses: 10009
Total transferred: 4984482 bytes
HTML transferred: 3453105 bytes
Requests per second: 7690.85 [#/sec] (mean)
Time per request: 6.501 [ms] (mean)
Time per request: 0.130 [ms] (mean, across all concurrent requests)
Transfer rate: 3743.14 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.0 1 5
Processing: 1 4 1.4 5 11
Waiting: 0 2 1.1 3 8
Total: 1 6 1.2 6 14

Percentage of the requests served within a certain time (ms)
50% 6
66% 6
75% 6
80% 6
90% 7
95% 9
98% 10
99% 11
100% 14 (longest request)

RPS结果是Requests per second: 7690.85 [#/sec] (mean).
第四份结果是:

  1. This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
  2. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  3. Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)

Server Software: lighttpd/1.4.15
Server Hostname: localhost
Server Port: 8181

Document Path: /
Document Length: 345 bytes

Concurrency Level: 50
Time taken for tests: 1.315784 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Non-2xx responses: 10033
Total transferred: 4996434 bytes
HTML transferred: 3461385 bytes
Requests per second: 7600.03 [#/sec] (mean)
Time per request: 6.579 [ms] (mean)
Time per request: 0.132 [ms] (mean, across all concurrent requests)
Transfer rate: 3708.06 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.2 1 8
Processing: 1 4 1.4 5 11
Waiting: 0 2 1.1 3 8
Total: 1 6 1.4 6 15

Percentage of the requests served within a certain time (ms)
50% 6
66% 6
75% 6
80% 6
90% 7
95% 9
98% 11
99% 12
100% 15 (longest request)

结果是Requests per second: 7600.03 [#/sec] (mean).
第五份结果是:

  1. This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
  2. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  3. Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)

Server Software: lighttpd/1.4.15
Server Hostname: localhost
Server Port: 8181

Document Path: /
Document Length: 345 bytes

Concurrency Level: 50
Time taken for tests: 1.812989 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Non-2xx responses: 10000
Total transferred: 4980000 bytes
HTML transferred: 3450000 bytes
Requests per second: 5515.75 [#/sec] (mean)
Time per request: 9.065 [ms] (mean)
Time per request: 0.181 [ms] (mean, across all concurrent requests)
Transfer rate: 2682.31 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 2.7 4 9
Processing: 1 4 0.8 5 6
Waiting: 0 1 1.7 2 5
Total: 5 8 2.3 9 13
WARNING: The median and mean for the processing time are not within a normal deviation
These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
50% 9
66% 10
75% 10
80% 11
90% 12
95% 12
98% 12
99% 12
100% 13 (longest request)

RPS结果是Requests per second: 5515.75 [#/sec] (mean);

可以看到,同是ab -n 10000 -c 50 http://localhost:8181/,结果大不一样,不仅分为7600RPS和5500RPS两档,而各档中具体数据也不一样.这个结果可以理解,OS中总是会有各种各样的消息要处理,影响具体数据结果也很正常.
因此,谢华亮(sir?mm?)的测试用ab的结果来进行php4,php5的性能比较是不太对的.至少目前看来,我没有从他的文章中看到他进行了多次ab测评后取结果的平均值.但是他列出来这样一个结果:

  1. 版本 函数测试 不实例化类 实例化类 类的继承
  2. PHP 4.4.2 1047.23/rps 1034.98/rps 1006.14/rps 992.95/rps
  3. PHP 5.2.1 1176.06/rps 1197.17/rps 1187.93/rps 1128.54/rps

这大致可以说明,php5.2确实是比php4.4.2要快.但是从1197.17>1176.06得出php5的类跑得比functiong还快,我不这么认为.只是21个request的差别,太小了,ab测试的随便一个风吹草吹就行了(而且说class比function要快,严重地伤害了我的感情,哈哈)…
嗯,先整这么多.有空好好研究一下,如何对web程序进行性能测评.
另外,有空见到这两位兄台,好好争论一番.


Tag:
相关文章


     
    Aug
    21
    Posted (xurenlu) in 未分类 on 08月-21-2007

    我又写了一个文件.再测之:

    1. <?php
    2.  
    3. function signin()
    4. {
    5. return "null";
    6. }
    7. class User
    8. {
    9.     public function signin()
    10.     {
    11. return "null";
    12.     }
    13.  
    14. }
    15. function time1()
    16. {
    17. $arr=split(" ",microtime());
    18. return $arr[1]+$arr[0];
    19. }
    20. $t1= time1();
    21. for($i=0;$i<100000;$i++)
    22. signin();
    23. $t2=time1();
    24.  
    25. for($i=0;$i<100000;$i++)
    26. User::signin();
    27. $t3=time1();
    28.  
    29. echo "
    30. function:".($t2-$t1)."ms
    31. class:".($t3-$t2)."ms";

    这是结果:

    1. function:0.071924924850464ms
    2. class:0.23149108886719ms

    为了避免程序运行顺序的影响,我们再运行一次,这次先测静态类的,再测function的:

    1. <?php
    2.  
    3. function signin()
    4. {
    5. return "null";
    6. }
    7. class User
    8. {
    9.     public function signin()
    10.     {
    11. return "null";
    12.     }
    13.  
    14. }
    15. function time1()
    16. {
    17. $arr=split(" ",microtime());
    18. return $arr[1]+$arr[0];
    19. }
    20. $t1= time1();
    21.  
    22. for($i=0;$i<100000;$i++)
    23. User::signin();
    24. $t2=time1();
    25.  
    26. for($i=0;$i<100000;$i++)
    27. signin();
    28. $t3=time1();
    29.  
    30. echo "
    31. function:".($t3-$t2)."ms
    32. class:".($t2-$t1)."ms";

    这次测的时间如下:

    1. function:0.072422027587891ms
    2. class:0.26213884353638ms

    从这个结果来看,php的function还是相当快的,比class,哪怕是静态方法要快。
    看来我越来越喜欢用function的路子是对的。

    后来我加上另一个,把整个结果贴出来:

    1. $obj=& new User();
    2.  
    3. $t1= time1();
    4.  
    5. for($i=0;$i<100000;$i++)
    6. User::signin();
    7. $t2=time1();
    8.  
    9. for($i=0;$i<100000;$i++)
    10. signin();
    11. $t3=time1();
    12.  
    13. for($i=0;$i<100000;$i++)
    14. $obj->signin();
    15. $t4=time1();
    16.  
    17. for($i=0;$i<100000;$i++)
    18. {
    19. $obj1=& new User();
    20. $obj1->signin();
    21. }
    22. $t5=time1();
    23. echo "
    24. function:".($t3-$t2)."ms
    25. class:".($t2-$t1)."ms
    26. object:".($t4-$t3)."ms
    27. new object:".($t5-$t4)."ms";

    结果是:

    1. function:0.071459054946899ms
    2. class:0.23710894584656ms
    3. object:0.08794093132019ms
    4. new object:0.17567801475525ms

    也就是说,直接调用function是最快的,其次是重复调用已存在对象的方法,仅比纯function慢一点点。
    接着是先新建class的实例再调用方法,最慢的是直接调用静态方法。
    这个结果有一点点出乎我的意料,我没料到静态方法是最慢的一个。


    Tag:
    相关文章


       
      Aug
      21
      Posted (xurenlu) in php性能 on 08月-21-2007

      老覃同学做了一个测试,来比较PHP5下利用function,class来编程时的效率差异。
      我一向喜欢钻牛角尖:
      有两个疑问:
      1.ab本身的文档说了,ab自身是需要CPU资源的,有时候要注意你可能不是在测apache的性能,而是在测ab这个软件的性能。老覃同志如何去除ab的影响?
      2.php编译时也是花费CPU时间的。我做了另一组测试:

      1. //t1.php

      function signin()

      {

      echo “signin”;

      }

      signin();

      ?>

      ab -n 10000 -c 50 的结果是:
      1534.15 [#/sec]
      Time per request: 32.591 [ms] (mean)

      ,再另外一个:

      function signin()

      {

      echo “signin”;

      }

      //signin();

      ?>

      ab -n 10000 -c 50的结果是:
      1748.48 [#/sec], Time per request: 28.596 。
      就是说,算上ab的花费,apache的花费,php编译的花费,这几个的时间消费可能已经比php代码运行的时间花费要大了。加上运行的代码后,只相关几个ms。
      如果要进行精确的比较,老覃的做法可能很不可靠。
      PHP4与PHP5.20的效率目前还只有看官方的数据。
      另外有个疑问,我的php比老覃同志的似乎快了不少,相差好几倍。可能是我的是Fedora 下运行的结果。

      附注:

      我后来做了一个实验,ab -n 10000 -c 50 http://localhost/test/23442.php ,返回的结果是:

      1. Requests per second:    2192.03 [#/sec] (mean)
      2. Time per request:       22.810 [ms] (mean)

      这是在请求的文件不存在下,apache简单返回一个静态面的情况下的。由此看来,ab和apache的开销就已经占了大约20ms.

      再注,在这里
      是老覃的同事做的测试.我google得到了这个结果.


      Tag:
      相关文章