這次測試加在php動態頁面的效果
apache pre-fork mode:
1, apache compiled
./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --with-mpm=prefork
2 php compiled
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysql=/usr/local/webserver/mysql --with-apxs2=/usr/local/apache2/bin/apxs
3. make
make ZEND_EXTRA_LIBS='-liconv'
4 .make install
5. 編輯測試文件
[root@LB1 bin]# cd /usr/local/apache2/htdocs/
[root@LB1 htdocs]# ls
index.html
[root@LB1 htdocs]# vi index.php
[root@LB1 htdocs]# cat index.php
<?php
phpinfo();
?>
[root@LB1 htdocs]#
6, apache httpd.conf中添加:
設置web server環境
#載入php5的函式庫
LoadModule php5_module modules/libphp5.so
#指定php執行的副檔名
AddType application/x-httpd-php .php .phtml .inc .php3
#原始碼副呈現的副檔名
AddType application/x-httpd-php-source .phps
<IfModule mpm_worker_module>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
7 壓力baseline收集
php 頁面部分
===prefork mode====
[root@LB1 bin]# ./ab -n 10000 -c 10 http://172.16.1.222/index.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 172.16.1.222 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Apache/2.2.15
Server Hostname: 172.16.1.222
Server Port: 80
Document Path: /index.php
Document Length: 40213 bytes
Concurrency Level: 10
Time taken for tests: 5.047 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 403848771 bytes
HTML transferred: 402178437 bytes
Requests per second: 1981.49 [#/sec] (mean)
Time per request: 5.047 [ms] (mean)
Time per request: 0.505 [ms] (mean, across all concurrent requests)
Transfer rate: 78146.56 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.6 0 8
Processing: 1 5 0.8 5 12
Waiting: 0 1 0.9 1 8
Total: 2 5 0.8 5 13
Percentage of the requests served within a certain time (ms)
50% 5
66% 5
75% 5
80% 6
90% 6
95% 6
98% 7
99% 7
100% 13 (longest request)
[root@LB1 bin]#
btw:再進行work方式的時候使用類似上面的辦法報錯了“
[root@LB1 bin]# ./apachectl start
[Mon Mar 29 23:57:53 2010] [crit] Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP.
Pre-configuration failed
”解決,參見 上一篇文章
worker 方式:
1, apache complied
./configure --prefix=/usr/local/httpd2 --enable-so --enable-rewrite --with-mpm=worker
2, php compiled
./configure --prefix=/usr/local/php2 --with-config-file-path=/usr/local/phpw --with-mysql=/usr/local/webserver/mysql --with-apxs2=/usr/local/httpd2/bin/apxs --enable-maintainer-zts
3. make
make ZEND_EXTRA_LIBS='-liconv'
4 .make install
5. 編輯測試文件
[root@LB1 bin]# cd /usr/local/apache2/htdocs/
[root@LB1 htdocs]# ls
index.html
[root@LB1 htdocs]# vi index.php
[root@LB1 htdocs]# cat index.php
<?php
phpinfo();
?>
[root@LB1 htdocs]#
6, apache httpd.conf中添加:
設置web server環境
#載入php5的函式庫
LoadModule php5_module modules/libphp5.so
#指定php執行的副檔名
AddType application/x-httpd-php .php .phtml .inc .php3
#原始碼副呈現的副檔名
AddType application/x-httpd-php-source .phps
<IfModule mpm_worker_module>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
啟動apache
7 收集壓力基準:
[root@LB1 htdocs]# cd ../bin
[root@LB1 bin]# ./ab -n 10000 -c 10 http://172.16.1.222/index.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 172.16.1.222 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Apache/2.2.15
Server Hostname: 172.16.1.222
Server Port: 80
Document Path: /index.php
Document Length: 40284 bytes
Concurrency Level: 10
Time taken for tests: 4.213 seconds
Complete requests: 10000
Failed requests: 3
(Connect: 0, Receive: 0, Length: 3, Exceptions: 0)
Write errors: 0
Total transferred: 404509865 bytes
HTML transferred: 402839865 bytes
Requests per second: 2373.57 [#/sec] (mean)
Time per request: 4.213 [ms] (mean)
Time per request: 0.421 [ms] (mean, across all concurrent requests)
Transfer rate: 93762.80 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 4
Processing: 1 4 1.8 4 45
Waiting: 0 3 1.5 3 30
Total: 1 4 1.8 4 46
Percentage of the requests served within a certain time (ms)
50% 4
66% 4
75% 5
80% 5
90% 6
95% 7
98% 8
99% 9
100% 46 (longest request)
[root@LB1 bin]#
對比發現 ,從動態頁面來看,worker方式的優勢就顯現出來了,處理能力明顯被pre-fork方式強。
記錄一下,備忘