日期:2014-05-16  浏览次数:21028 次

nginx和apache并发性能测试对比

今天在ubuntu 12.04 service版本上搭建了apache2+php的站点以及nginx+php5-fpm的站点,简单地用apache自带的ab工具测试了一下并发的性能,具体的测试脚本如下:

<?php
    $arr = array();
    for($i=0;$i<1000;++$i)
    {
        $arr['areyouok'.$i] = $i*$i;
    }
    print_r($arr);
?>


具体的nginx和apache2我都启用了七个进程,但是 通过 service apache2 restart启动之后,apache2只有6个进程,而 通过 service nginx restart重启之后,发现nginx是有七个进程的,每一次测试之前都是先stop服务然后再start服务的,

http://localhost对应的是nginx站点

http://localhost6000对应的是apache站点

结果发现测试结果如下:

./ab -n 100 -c 50 http://localhost:6000/perform.php

Requests per second:      725.11,746.45   [#/sec] (mean)

./ab -n 100 -c 50 http://localhost/perform.php

Requests per second:      615.58,622.23   [#/sec] (mean)


然后测试100个并发请求

./ab -n 200 -c 100 http://localhost:6000/perform.php

Requests per second:      657.06,744.74   [#/sec] (mean)

./ab -n 200 -c 100 http://localhost/perform.php

Requests per second:      611.91,632.74   [#/sec] (mean)


然后测试250人并发:

./ab -n 500 -c 250 http://localhost:6000/perform.php

Requests per second:      353.54,150.99,207.15,237.05   [#/sec] (mean)

./ab -n 500 -c 250 http://localhost/perform.php

Requests per second:      407,413,418,409   [#/sec] (mean)


可以明显看出,在网站的并发访问量小于100时,apache的性能会好一些,并发量大于200时,nginx明显占优.

我的电脑硬件配置为:

使用命令:cat proc/cpuinfo   

 Intel(R) Core(TM)2 Duo CPU     T9400  @ 2.53GHz 

4G内存

查找硬盘信息:cat /proc/partitions

查找内存信息:cat /proc/meminfo |more