Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4249663
  • 博文数量: 601
  • 博客积分: 15410
  • 博客等级: 上将
  • 技术积分: 6884
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-16 08:11
个人简介

独学而无友,则孤陋而寡闻!

文章分类

全部博文(601)

文章存档

2020年(1)

2018年(4)

2017年(7)

2016年(42)

2015年(25)

2014年(15)

2013年(36)

2012年(46)

2011年(117)

2010年(148)

2009年(82)

2008年(37)

2007年(41)

分类: Python/Ruby

2012-07-31 14:54:55

一、Blitz

1、从0-100循环,总流量已经超过7M,很可能会受网速的限制。
   服务器CPU利用率:85%左右,负载:1或2
   最繁忙的程序是nginx
   CPU利用率恢复到0%时,测试马上结束。

  1. %webbench -t 90 -c 200 http://ict.sdcangyuan.com/test/blitz/test.php
  2. 200 clients, running 90 sec.
  3. Speed=103998 pages/min, 7422003 bytes/sec.
  4. Requests: 155993 susceed, 4 failed.

  5. %webbench -t 90 -c 300 http://ict.sdcangyuan.com/test/blitz/test.php
  6. 300 clients, running 90 sec.
  7. Speed=103214 pages/min, 7354411 bytes/sec.
  8. Requests: 154808 susceed, 14 failed.
2、改为从0-50循环:


  1. %webbench -t 90 -c 300 http://ict.sdcangyuan.com/test/blitz/test.php
  2. 300 clients, running 90 sec.
  3. Speed=114114 pages/min, 3711739 bytes/sec.
  4. Requests: 171164 susceed, 7 failed.

  5. %webbench -t 90 -c 400
  6. 400 clients, running 90 sec.
  7. Speed=113617 pages/min, 3687560 bytes/sec.
    Requests: 170407 susceed, 19 failed.


  8.             input        (Total)           output
       packets  errs idrops      bytes    packets  errs      bytes colls drops
           29k     0     0       6.4M        25k     0       9.7M     0     0
           28k     0     0       6.3M        24k     0       9.6M     0     0
           28k     0     0       6.2M        24k     0       9.4M     0     0
           28k     0     0       6.3M        24k     0       9.5M     0     0
           28k     0     0       6.4M        24k     0       9.6M     0     0
           28k     0     0       6.3M        24k     0       9.6M     0     0
           28k     0     0       6.3M        24k     0       9.5M     0     0
           28k     0     0       6.3M        24k     0       9.6M     0     0
           28k     0     0       6.2M        24k     0       9.5M     0     0
           28k     0     0       6.3M        24k     0       9.5M     0     0


ab -c 300 -t 90


Document Path:          /test/blitz/test.php
Document Length:        1794 bytes

Concurrency Level:      100
Time taken for tests:   18.493 seconds
Complete requests:      50000
Failed requests:        0
Write errors:           0
Total transferred:      97800000 bytes
HTML transferred:       89700000 bytes
Requests per second:    2703.68 [#/sec] (mean)
Time per request:       36.987 [ms] (mean)
Time per request:       0.370 [ms] (mean, across all concurrent requests)
Transfer rate:          5164.46 [Kbytes/sec] received






二、smarty

1、CPU利用率: 100%, 负载:25左右
  最繁忙的程序是php-fpm
  CPU利用率恢复到0%时,仍然要等近两分钟才能结束测试
  300个连接,webbench会等会长时间也得不到结果。

下面的结果可能出错,因为同样的输出内容,在每分钟11W的时候,流量大约是不到4M,看后台,出现了大量的error,说明已经超出php的计算范围,这个时候应该出现了大量的错误页面:
  1. %webbench -t 90 -c 250 http://ict.sdcangyuan.com/test/smarty/demo/index.php
  2. Webbench - Simple Web Benchmark 1.5
  3. Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

  4. Benchmarking: GET http://ict.sdcangyuan.com/test/smarty/demo/index.php
  5. 250 clients, running 90 sec.

  6. Speed=118555 pages/min, 955586 bytes/sec.
  7. Requests: 177833 susceed, 0 failed.
减少并发数,可以看到结果差不多,每分钟1w,每秒在4百k左右:

  1. %webbench -t 90 -c 100
  2. Webbench - Simple Web Benchmark 1.5
  3. Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

  4. Benchmarking: GET
  5. 100 clients, running 90 sec.

  6. Speed=13425 pages/min, 440285 bytes/sec.
  7. Requests: 20138 susceed, 0 failed.
继续加到200个并发,同时附上流量信息:

  1. %webbench -t 90 -c 200
    Webbench - Simple Web Benchmark 1.5
    Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

    Benchmarking: GET
    200 clients, running 90 sec.

    Speed=13413 pages/min, 439825 bytes/sec.
    Requests: 20120 susceed, 0 failed.


  2.             input        (Total)           output
       packets  errs idrops      bytes    packets  errs      bytes colls drops
          3.5k     0     0       764k       3.3k     0       1.1M     0     0
          3.6k     0     0       782k       3.4k     0       1.2M     0     0
          3.4k     0     0       741k       3.2k     0       1.1M     0     0
          3.5k     0     0       760k       3.3k     0       1.1M     0     0
          3.5k     0     0       768k       3.3k     0       1.1M     0     0

继续加到300并发,坚持了不到1分钟,nginx-error爆满:

  1. %webbench -t 90 -c 300
    Webbench - Simple Web Benchmark 1.5
    Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

    Benchmarking: GET
    300 clients, running 90 sec.

    Speed=123128 pages/min, 979094 bytes/sec.
    Requests: 184515 susceed, 178 failed.
    %

  2.    packets  errs idrops      bytes    packets  errs      bytes colls drops
           21k     0     0       1.9M        19k     0       2.6M     0     0
           20k     0     0       1.9M        18k     0       2.5M     0     0
           20k     0     0       1.9M        18k     0       2.5M     0     0
           20k     0     0       1.9M        18k     0       2.5M     0     0
           20k     0     0       1.9M        18k     0       2.5M     0     0
           20k     0     0       1.8M        18k     0       2.5M     0     0
           20k     0     0       1.9M        18k     0       2.5M     0     0
           20k     0     0       1.9M        18k     0       2.6M     0     0

ab -c 100 -t 90

Document Path:          /test/smarty/demo/index.php
Document Length:        1806 bytes

Concurrency Level:      100
Time taken for tests:   90.001 seconds
Complete requests:      20336
Failed requests:        0
Write errors:           0
Total transferred:      40021248 bytes
HTML transferred:       36726816 bytes
Requests per second:    225.95 [#/sec] (mean)
Time per request:       442.568 [ms] (mean)
Time per request:       4.426 [ms] (mean, across all concurrent requests)
Transfer rate:          434.26 [Kbytes/sec] received







三、php代码输出:

CPU利用率:55%左右

  1. %webbench -t 90 -c 300
  2. Webbench - Simple Web Benchmark 1.5
  3. Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

  4. Benchmarking: GET
  5. 300 clients, running 90 sec.

  6. Speed=153972 pages/min, 3984266 bytes/sec.
  7. Requests: 230950 susceed, 8 failed.

               input        (Total)           output
   packets  errs idrops      bytes    packets  errs      bytes colls drops
       28k     0     0       5.5M        24k     0       7.9M     0     0
       28k     0     0       5.5M        24k     0       7.9M     0     0
       28k     0     0       5.5M        24k     0       7.9M     0     0
       27k     0     0       5.3M        23k     0       7.7M     0     0
       28k     0     0       5.4M        24k     0       7.9M     0     0
       28k     0     0       5.5M        24k     0         8M     0     0
       28k     0     0       5.4M        24k     0       7.9M     0     0
       28k     0     0       5.5M        24k     0       7.9M     0     0 


 ab -c 100 -t 90

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

Concurrency Level:      100
Time taken for tests:   15.221 seconds
Complete requests:      50000
Failed requests:        0
Write errors:           0
Total transferred:      77701554 bytes
HTML transferred:       69601392 bytes
Requests per second:    3285.00 [#/sec] (mean)
Time per request:       30.441 [ms] (mean)
Time per request:       0.304 [ms] (mean, across all concurrent requests)
Transfer rate:          4985.35 [Kbytes/sec] received






四、结论:


Blitz的速度大约是smarty的10倍,能达到php的直接echo方式的80%左右,性能相当不错了。

但是Blitz的变量值传递非常别扭,必须多一级数组,在数组循环的时候,竟然夸张地需要三级数组!相比来说,smarty的单级数组显得非常简洁和便于理解。
 

五、三种方式的源代码:

注:以上各个测试结果,均无Xcache加速器,下次测试有Xcache时的对比。

1、Blitz
php文件:
  1. <?php
  2.   $t = new Blitz();
  3.   $t->load('{{ include("./test.tpl") }}');
  4.   $arr = array();
  5.   for ( $i = 0 ; $i < 50 ; $i++ ){
  6.     $arr[]['number'] = $i;
  7.    }
  8.   $t->set(array('arr'=>$arr));

  9.   $abc = "This is a Test template!";
  10.   $t->set(array('abc'=>$abc));

  11.   $title = "The Test Page of lsstarboy!";
  12.   $t->set(array('title'=>$title));

  13.   $t->display();
  14. ?>
tpl文件:

  1. <html>
  2.   <head>
  3.    <title> {{ $title }} </title>
  4.   <body>
  5.    {{ $abc }} <br>
  6.    {{ BEGIN arr }}
  7.      <p>The number is {{ $number }} ! </p>
  8.      {{ END }}
  9.     <p> This is the end!!</p>
  10.   </body>
  11. </html>
2、smarty:
php文件:

  1. <?php

  2. require('../libs/Smarty.class.php');
  3. $smarty = new Smarty;
  4. $smarty->debugging = false;
  5. $smarty->caching = true;
  6. $smarty->cache_lifetime = 120;

  7. $smarty->assign("title","The Test Page Of lsstarboy");
  8. $smarty->assign("abc","This is a Test template!");

  9. $arr = array();

  10. for( $i=0; $i < 50; $i++ ) {
  11.   $arr[] = $i;
  12. }

  13. $smarty->assign("arr",$arr);

  14. $smarty->display('index.tpl');
  15. ?>
tpl文件:

  1. <html>
  2.   <head>
  3.    <title>{$title}</title>
  4.   </head>
  5.   <body>
  6.     {$abc}<br>
  7.      {section name=test loop=$arr}
  8. <p>The number is {$arr[test]} ! </p>
  9.       {/section}
  10.     <p>This is the end!!</p>
  11.    </body>
  12. </html>
3、php原生代码:

  1. <?php
  2. echo "\n";
  3. echo "\n";
  4. $title = "The Test Page of lsstarboy!";
  5. echo "$title\n";
  6. echo "\n";
  7. echo "\n";
  8. echo "This is a Test template!";
  9. for ( $i =1 ; $i<50; $i++ ) {
  10.   echo "

    The number is : " . $i . "!

    "
    ;
  11.  }
  12.  $abc = "This is the end!";
  13. echo $abc;
  14. echo " \n";
  15. echo "";
  16. ?>





----end----







阅读(4734) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~