1. 程式人生 > >nginx和apache併發效能測試對比

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