zoukankan      html  css  js  c++  java
  • PHP的压力测试工具ab.exe 和mpm介绍提高并发数

    该工具是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的内容为

    <?php
    
    for($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。我们可以设置confextra下的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

  • 相关阅读:
    Sencha Touch id 和 itemId
    解决VS报表.rdl 显示乱码“小方块”问题
    C# 调试程序弹出 没有可用于当前位置的源代码 对话框
    解决DropDownList 有一个无效 SelectedValue,因为它不在项目列表中。这是怎么回事?
    CS0016: 未能写入输出文件“c:windowsMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filesdata34aae0607daa87dApp_Web_addadvice.aspx.cdcab7d2.ekhlcbjd.dll”--“目录名无效。 ”
    利用微软类库 Visual Studio International Pack 汉字转拼音
    【C#】线程之Parallel
    【C#】线程之Task
    【C#】线程协作式取消
    【C#】属性(Attribute)
  • 原文地址:https://www.cnblogs.com/hellowzd/p/5908810.html
Copyright © 2011-2022 走看看