PHP的壓力測試工具ab.exe 和mpm介紹提高並發數

來源:互聯網
上載者:User

標籤:

該工具是apache內建的,可以用它來測試網站的並發量有多大和某個頁面的訪問時間。

基本用法:

1、  進入CMD,轉到apache的bin目錄下。

2、  執行命令ab.exe  -n 訪問的問次數–c 多少人訪問(並發量) 訪問的地址如:ab.exe –n 1000 –c 100 http://localhost/index.php;

如輸入以下命令ab.exe-n 10000 -c 100 http://localhost/test/index.php,

Index.php的內容為

<?phpfor($i=0;$i<100;$i++){         echo$i.‘|‘;}

 

 

該命令的意思為100個人訪問該地址1W次。會出現以下結果。

 

[plain] view plain copy 
  1. Server Software:        Apache/2.4.4                                   #apache版本號碼  
  2. Server Hostname:        localhost  
  3. Server Port:            80  
  4.    
  5. Document Path:          /test/index.php                       
  6. Document Length:        5 bytes  
  7.    
  8. ConcurrencyLevel:      100  
  9. Time taken fortests:   54.111 seconds                                 #訪問的總時間(秒)  
  10. Completerequests:      10000                                          #訪問的總次數  
  11. Failed requests:        0  
  12. Write errors:           0  
  13. Totaltransferred:      2060000 bytes  
  14. HTMLtransferred:       50000 bytes  
  15. Requests persecond:    184.80 [#/sec] (mean)                          #每秒訪問多少次  
  16. Time perrequest:       541.111 [ms] (mean)                            #這麼多人(100)訪問一次的時間  
  17. Time perrequest:       5.411 [ms] (mean, acrossall concurrent requests)         #一個人訪問一次花費的時間  
  18. Transfer rate:          37.18 [Kbytes/sec] received  



 

另外,如果我們把並發數增加到500,即把命令調整成ab.exe -n 10000 -c 500 http://localhost/test/index.php它就會出現以下結果。

 

[plain] view plain copy 
  1. apr_socket_connect():由於目標電腦積極拒絕,無法串連。   (730061)  
  2. Total of 902 requestscompleted  

 

原因是因為apache在windows下預設的最大並發訪問量為150。我們可以設定conf\extra下的httpd-mpm.conf檔案來修改它的最大並發數。在修改之前我們要說明一下,mpm是個什麼東西

 

Mpm為多路處理模組,即apache採用怎麼樣的方式來處理並發,主要有三種方式

1、  perfork 預先處理進程方式(用進程服務)

2、  worker 工作模式(用進程下的線程服務)

3、  winnt這個一般是windos 下採用的。(針對windows)

說完這個我們就可以動手修改設定檔了。步驟如下:

 

1、  開啟httpd.conf設定檔,開啟下面的配置

# Server-poolmanagement (MPM specific)

Include conf/extra/httpd-mpm.conf

2、  確定當前 apache是mpm模式,CMD下進放到apache的bin目錄輸入指令httpd.exe –l

會出現以下結果,就可知道它用的是什麼模式

[plain] view plain copy 
  1. Compiledin modules:  
  2.   core.c  
  3.   mod_win32.c  
  4.   mpm_winnt.c 這是為winnt模式  
  5.   http_core.c  
  6.   mod_so.c  



3、  修改httpd-mpm.conf檔案,因為從上面可以看到,我的apache用的是winnt模式,所以在該檔案下找到對應的winnt_module模組,修改參數,原先為150,我們把它修改成1000

[plain] view plain copy 
  1. <IfModulempm_winnt_module>  
  2.     ThreadsPerChild        1000  
  3.     MaxConnectionsPerChild   0  
  4. </IfModule>  



4、  重啟伺服器

 

修改完之後我們重新運行上面的命令ab.exe-n 10000 -c 500 http://localhost/test/index.php

它就會運行成功了,出現與ab.exe -n10000 -c 100 http://localhost/test/index.php時類似的效果。

同理,如果是其它模式,則在httpd-mpm.conf中修改對應的地方即可。如下

[plain] view plain copy 
    1. <IfModule mpm_prefork_module>  
    2.    StartServers             5                  #開始啟動的進程  
    3.    MinSpareServers          5                 #最小準備進程  
    4.    MaxSpareServers         10                #最大空閑進程  
    5.    MaxRequestWorkers      1000            #最大並發數  
    6.    MaxConnectionsPerChild   0  
    7. </IfModule>  

http://blog.csdn.net/zhangzmb/article/details/51884011

PHP的壓力測試工具ab.exe 和mpm介紹提高並發數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.